Registry / ai-ml / torchcrepe

torchcrepe

JSON →
library0.0.24pypypi✓ verified 89d ago

Torchcrepe is a PyTorch implementation of the CREPE pitch tracker, a state-of-the-art monophonic pitch estimation tool based on a deep convolutional neural network. It allows users to compute pitch and periodicity from audio signals, offering functionalities for direct file processing, filtering, thresholding, and various decoding options. The library is actively maintained, with regular updates to its PyPI package.

pip install torchcrepe
INSTALL
IMPORT
SIG · TORCHCREPE
T
torchcrepe
ai-mlpythonv0.0.24
Install
81.5s avg
Import
7944ms
Disk
5350MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.0.24 · 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
✕ timeout
✓ 91.45s
py 3.11
✕ build_error
✓ 84.73s
py 3.12
✕ build_error
✓ 77.2s
py 3.13
✕ build_error
✓ 72.58s
py 3.9
✕ timeout
✕ timeout
5350MB installed
● package 5350MB
Code
Verified usage

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

torchcrepe
✓ import torchcrepe
predict
✓ from torchcrepe import predict
Main function for pitch prediction
load.audio
✓ from torchcrepe.load import audio
Utility to load audio files for processing

This quickstart demonstrates how to load an audio signal (using a mocked function for a self-contained example), set common parameters like hop length, frequency range, model capacity, and device, and then use `torchcrepe.predict` to estimate the pitch. It highlights the basic workflow for integrating torchcrepe into a PyTorch-based audio processing pipeline.

import torch import torchcrepe import numpy as np # Mock torchcrepe.load.audio for a runnable example without external files class MockLoadAudio: def audio(self, *args, **kwargs): # Generate a dummy 16kHz sine wave audio (1 second) sr = 16000 duration = 1.0 frequency = 440.0 # Hz t = np.linspace(0., duration, int(sr * duration), endpoint=False) audio_np = 0.5 * np.sin(2 * np.pi * frequency * t).astype(np.float32) return torch.from_numpy(audio_np).unsqueeze(0), sr # unsqueeze for batch dimension torchcrepe.load = MockLoadAudio() # Load dummy audio audio, sr = torchcrepe.load.audio('dummy.wav', sr=16000) # Here we'll use a 5 millisecond hop length hop_length = int(sr / 200.) # Provide a sensible frequency range for your domain (upper limit is 2006 Hz) # This would be a reasonable range for speech fmin = 50 fmax = 550 # Select a model capacity--one of "tiny" or "full" model = 'tiny' # Choose a device to use for inference device = 'cuda:0' if torch.cuda.is_available() else 'cpu' # Pick a batch size that doesn't cause memory errors on your gpu batch_size = 2048 # Note: Batching here refers to internal frame processing, not input audio files # Compute pitch pitch = torchcrepe.predict( audio, sr, hop_length, fmin, fmax, model, batch_size=batch_size, device=device, return_periodicity=False # Set to True to get a confidence score ) print(f"Predicted pitch shape: {pitch.shape}") if pitch.shape[-1] > 0: print(f"First few pitch values: {pitch[0, :5].tolist()}")
Debug
Known issues
gotchaTorchcrepe's default Viterbi decoding differs from the original CREPE (TensorFlow) implementation. It uses Viterbi decoding on the softmax output instead of a weighted average, which helps prevent double/half frequency errors but changes the default pitch estimation approach.
fix
Be aware of this default behavior. For specific use cases, explore options in `torchcrepe.decode` if you need to replicate the original CREPE's decoding or implement custom post-processing.
affects: All versions
gotchaCREPE models were not trained on silent audio. This can lead to the model assigning high confidence to pitch bins even in silent regions. You may observe spurious pitch predictions in quiet sections.
fix
Utilize `torchcrepe.threshold.Silence` to manually set periodicity (confidence) to zero in silent regions, or apply custom silence detection and masking.
affects: All versions
gotchaThe `batch_size` argument in `torchcrepe.predict` refers to internal batching over audio frames, not directly to processing multiple distinct audio files in a single call. Feeding multiple audio files of varying lengths in a batch for `predict` is not straightforward and might not offer the expected speed benefits due to padding overhead and other design choices.
fix
Process individual audio files separately or manage custom padding and batching strategies if you need to run multiple audio signals through the model concurrently. The library's `predict_from_files_to_files` functions are designed for convenience with multiple files, handling them sequentially.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'torchaudio'
The 'torchaudio' library, a required dependency for many torchcrepe functionalities (especially for audio file loading and processing), is not installed in your environment.
fix
Install torchaudio using pip: `pip install torchaudio`. For CUDA support, ensure you install the correct `torchaudio` version matching your PyTorch and CUDA setup (e.g., `pip install torchaudio -f https://download.pytorch.org/whl/cu118`).
RuntimeError: expected scalar type Float but found Double
torchcrepe functions expect audio input tensors to be of type `torch.float32` (Float), but a `torch.float64` (Double) tensor was provided.
fix
Convert your audio tensor to `torch.float32` before passing it to torchcrepe: `audio_tensor = audio_tensor.to(torch.float32)`.
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
This error occurs when the audio input tensor and the torchcrepe model (or the device specified for prediction) are located on different compute devices (e.g., one on GPU/CUDA and the other on CPU).
fix
Ensure both the audio tensor and the `torchcrepe` model (or the `device` argument for `torchcrepe.predict`) are on the same device. For example: `device = 'cuda' if torch.cuda.is_available() else 'cpu'`, then `audio_tensor = audio_tensor.to(device)` and pass `device=device` to `torchcrepe.predict()`.
torchaudio.backend.NoBackendError: No audio backend is available. Please install 'soundfile' or 'sox' to use torchaudio's I/O functions.
torchcrepe's `process_file` function relies on `torchaudio` to load audio files, but `torchaudio` cannot find an available audio backend (like 'soundfile' or 'sox') in your environment.
fix
Install the 'soundfile' library: `pip install soundfile`. On some systems, you might also need to install the underlying `libsndfile` via your system's package manager (e.g., `sudo apt-get install libsndfile1` on Debian/Ubuntu).
Upgrade
Version history
0.0.24latest on PyPI · released May 16, 2025
Audit
Dependencies
torchrequiredCore deep learning framework dependency.
librosaoptionalCommonly used for audio loading and processing in examples and real-world usage.
torchaudiooptionalAlternative or complementary library for audio I/O and transformations.
Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
torchcrepe — pip install torchcrepe · libregistry