Skip to main content

The official Pytorch implementation of Fast Context-based Pitch Estimation (FCPE)

Project description

TorchFCPE

Useage

from torchfcpe import spawn_bundled_infer_model
import torch
import librosa

# configure device and target hop_size
device = 'cpu'
sr = 16000
hop_size = 160

# load audio
audio, sr = librosa.load('test.wav', sr=sr)
audio = librosa.to_mono(audio)
audio_length = len(audio)
f0_target_length=(audio_length // hop_size) + 1
audio = torch.from_numpy(audio).float().unsqueeze(0).unsqueeze(-1).to(device)

# load model
model = spawn_bundled_infer_model(device=device)

# infer
'''
audio: wav, torch.Tensor
sr: sample rate
decoder_mode: [Optional] 'local_argmax' is recommended
threshold: [Optional] threshold for V/UV decision, 0.006 is recommended
f0_min: [Optional] minimum f0
f0_max: [Optional] maximum f0
interp_uv: [Optional] whether to interpolate unvoiced frames
output_interp_target_length: [Optional] If not None, the output f0 will be
    interpolated to the target length
'''
f0 = model.infer(
    audio,
    sr=sr,
    decoder_mode='local_argmax',
    threshold=0.006,
    f0_min=80,
    f0_max=880,
    interp_uv=False,
    output_interp_target_length=f0_target_length,
)

print(f0)

# the model is son class of torch.nn.Module, so you can use it as a normal pytorch model
# example: change device
model = model.to(device)
# example: compile model
model = torch.compile(model)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

torchfcpe-0.0.4-py3-none-any.whl (40.2 MB view details)

Uploaded Python 3

File details

Details for the file torchfcpe-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: torchfcpe-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 40.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.7

File hashes

Hashes for torchfcpe-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f042c463d850d76c6f4899a0b84f0b694bb560adf05f4de951097a756d17472d
MD5 4db27f64a096b8ee959742bde09c9523
BLAKE2b-256 159866da447498a2835b01cb3ae851e1333035a9fbf228e5c6f3e3c4351c06b6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page