Registry / ai-ml / torchfcpe

torchfcpe

JSON →
library0.0.4pypypiunverified

The official Pytorch implementation of Fast Context-based Pitch Estimation (FCPE), `torchfcpe` provides a robust and efficient solution for extracting fundamental frequency (F0) from audio signals. It is currently at version `0.0.4` and sees occasional updates, primarily focusing on model improvements and compatibility.

pip install torchfcpe
INSTALL
IMPORT
SIG · TORCHFCPE
T
torchfcpe
ai-mlpythonv0.0.4
Install
68.5s avg
Import
Disk
4890MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 77.6s
py 3.11
✕ build_error
✓ 70.3s
py 3.12
✕ build_error
✓ 66.35s
py 3.13
✕ build_error
✓ 59.6s
py 3.9
✕ build_error
✕ timeout
4890MB installed
● package 4890MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FCPE
from torchfcpe import FCPE

This quickstart demonstrates how to initialize the `FCPE` model, prepare dummy audio data, and perform pitch estimation. It includes essential preprocessing steps like ensuring the correct device and input tensor shape. For real-world usage, replace the dummy audio with `torchaudio.load`.

import torch import torchaudio from torchfcpe import FCPE import os # --- Configuration --- sampling_rate = 44100 # Default sample rate for FCPE hop_length = 512 # Default hop length device = os.environ.get('FCPE_DEVICE', 'cuda' if torch.cuda.is_available() else 'cpu') print(f"Using device: {device}") # --- 1. Initialize the FCPE model --- model = FCPE( sampling_rate=sampling_rate, hop_length=hop_length, device=device ) # --- 2. Create dummy audio data (or load real audio) --- # For a real scenario, replace with torchaudio.load('your_audio.wav') # This creates a 5-second mono sine wave at 440 Hz num_samples = sampling_rate * 5 # 5 seconds of audio t = torch.linspace(0, 5, num_samples, device=device) frequency = 440.0 # Hz # Generate a simple sine wave. FCPE expects mono audio. # Shape: (batch_size, num_samples) audio = torch.sin(2 * torch.pi * frequency * t).unsqueeze(0) # --- 3. Preprocess audio for the model --- # Ensure audio is on the correct device (already done for dummy data) # Ensure audio is 2D (batch_size, num_samples) if audio.dim() == 1: audio = audio.unsqueeze(0) # If audio were stereo (e.g., shape (2, N)), convert to mono: if audio.shape[0] > 1: # Assuming batch_size is 1, check channel dim audio = torch.mean(audio, dim=0, keepdim=True) print(f"Input audio shape: {audio.shape}") # --- 4. Perform pitch estimation --- with torch.no_grad(): f0, uv = model(audio) # f0: fundamental frequency (Hz), uv: unvoiced/voiced decision (boolean-like) print(f"Estimated F0 shape: {f0.shape}") print(f"Estimated UV shape: {uv.shape}") print(f"First 10 F0 values: {f0[0, :10].cpu().numpy()}") print(f"First 10 UV values: {uv[0, :10].cpu().numpy()}")
Debug
Known issues
breakingStarting from `v0.0.4`, all FCPE models now correctly inherit directly from `torch.nn.Module`. While direct instantiation of `FCPE(...)` is generally stable, any custom subclasses or code directly manipulating internal model structure that relied on a previous inheritance hierarchy might require review.
fix
Review custom `torchfcpe` subclasses or direct attribute access to ensure compatibility with standard `torch.nn.Module` methods and properties.
affects: >=0.0.4
gotchaImproved device detection and specific support for Apple Silicon's MPS device were added in `v0.0.2`. Users upgrading from `v0.0.1` or experiencing device-related issues (especially with MPS) may find more reliable behavior in newer versions.
fix
Ensure you are running `torchfcpe>=0.0.2` for the best device compatibility. If issues persist, explicitly set the `device` parameter during model initialization (e.g., `device='cpu'` or `device='mps'`).
affects: <0.0.2
gotchaThe `sampling_rate` parameter passed to the `FCPE` model during initialization must match the sample rate of your input audio. A mismatch will lead to incorrect pitch estimation or errors due to internal feature extraction assumptions.
fix
Always resample your input audio to `model.sampling_rate` using `torchaudio.transforms.Resample` before passing it to the model, or initialize the model with the sample rate of your audio.
affects: All versions
Upgrade
Version history
0.0.4latest on PyPI · released Mar 6, 2024
Audit
Dependencies
torchrequiredCore PyTorch dependency for tensor operations and deep learning models (>=1.12.0)
torchaudiorequiredRequired for audio loading, processing, and resampling (>=0.12.0)
numpyrequiredFundamental package for numerical operations
librosarequiredUtilities for audio analysis
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
torchfcpe — pip install torchfcpe · libregistry