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 torchcrepeVerified import paths — ran on the pinned version, not inferred.
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.
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.
Utilize `torchcrepe.threshold.Silence` to manually set periodicity (confidence) to zero in silent regions, or apply custom silence detection and masking.
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.
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`).
Convert your audio tensor to `torch.float32` before passing it to torchcrepe: `audio_tensor = audio_tensor.to(torch.float32)`.
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()`.
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).