{"id":6918,"library":"torchcrepe","title":"Torchcrepe","description":"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.","status":"active","version":"0.0.24","language":"python","source_language":"en","source_url":"https://github.com/maxrmorrison/torchcrepe","tags":["audio","pitch tracking","deep learning","pytorch","music information retrieval"],"install":[{"cmd":"pip install torchcrepe","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core deep learning framework dependency.","package":"torch","optional":false},{"reason":"Commonly used for audio loading and processing in examples and real-world usage.","package":"librosa","optional":true},{"reason":"Alternative or complementary library for audio I/O and transformations.","package":"torchaudio","optional":true}],"imports":[{"symbol":"torchcrepe","correct":"import torchcrepe"},{"note":"Main function for pitch prediction","symbol":"predict","correct":"from torchcrepe import predict"},{"note":"Utility to load audio files for processing","symbol":"load.audio","correct":"from torchcrepe.load import audio"}],"quickstart":{"code":"import torch\nimport torchcrepe\nimport numpy as np\n\n# Mock torchcrepe.load.audio for a runnable example without external files\nclass MockLoadAudio:\n    def audio(self, *args, **kwargs):\n        # Generate a dummy 16kHz sine wave audio (1 second)\n        sr = 16000\n        duration = 1.0\n        frequency = 440.0 # Hz\n        t = np.linspace(0., duration, int(sr * duration), endpoint=False)\n        audio_np = 0.5 * np.sin(2 * np.pi * frequency * t).astype(np.float32)\n        return torch.from_numpy(audio_np).unsqueeze(0), sr # unsqueeze for batch dimension\n\ntorchcrepe.load = MockLoadAudio()\n\n# Load dummy audio\naudio, sr = torchcrepe.load.audio('dummy.wav', sr=16000)\n\n# Here we'll use a 5 millisecond hop length\nhop_length = int(sr / 200.)\n\n# Provide a sensible frequency range for your domain (upper limit is 2006 Hz)\n# This would be a reasonable range for speech\nfmin = 50\nfmax = 550\n\n# Select a model capacity--one of \"tiny\" or \"full\"\nmodel = 'tiny'\n\n# Choose a device to use for inference\ndevice = 'cuda:0' if torch.cuda.is_available() else 'cpu'\n\n# Pick a batch size that doesn't cause memory errors on your gpu\nbatch_size = 2048 # Note: Batching here refers to internal frame processing, not input audio files\n\n# Compute pitch\npitch = torchcrepe.predict(\n    audio,\n    sr,\n    hop_length,\n    fmin,\n    fmax,\n    model,\n    batch_size=batch_size,\n    device=device,\n    return_periodicity=False # Set to True to get a confidence score\n)\n\nprint(f\"Predicted pitch shape: {pitch.shape}\")\nif pitch.shape[-1] > 0:\n    print(f\"First few pitch values: {pitch[0, :5].tolist()}\")","lang":"python","description":"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."},"warnings":[{"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.","message":"Torchcrepe'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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Utilize `torchcrepe.threshold.Silence` to manually set periodicity (confidence) to zero in silent regions, or apply custom silence detection and masking.","message":"CREPE 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'activ':55 'allow':30 'art':17 'audio':38,64 'base':22 'comput':33 'convolut':26 'crepe':9 'decod':50 'deep':25,67 'direct':43 'estim':20 'file':44 'filter':46 'function':41 'implement':6 'inform':71 'learn':68 'librari':53 'maintain':56 'monophon':18 'music':70 'network':28 'neural':27 'offer':40 'option':51 'packag':63 'period':36 'pitch':10,19,34,65 'process':45 'pypi':62 'pytorch':5,69 'regular':58 'retriev':72 'signal':39 'state':14 'state-of-the-art':13 'threshold':47 'tool':21 'torchcrep':1,2 'track':66 'tracker':11 'updat':59 'user':31 'various':49","created_at":"2026-04-15T18:48:37.960009+00:00","updated_at":"2026-04-16T23:05:37.817417+00:00","problems":[{"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`).","cause":"The 'torchaudio' library, a required dependency for many torchcrepe functionalities (especially for audio file loading and processing), is not installed in your environment.","error":"ModuleNotFoundError: No module named 'torchaudio'"},{"fix":"Convert your audio tensor to `torch.float32` before passing it to torchcrepe: `audio_tensor = audio_tensor.to(torch.float32)`.","cause":"torchcrepe functions expect audio input tensors to be of type `torch.float32` (Float), but a `torch.float64` (Double) tensor was provided.","error":"RuntimeError: expected scalar type Float but found Double"},{"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()`.","cause":"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).","error":"RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!"},{"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).","cause":"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.","error":"torchaudio.backend.NoBackendError: No audio backend is available. Please install 'soundfile' or 'sox' to use torchaudio's I/O functions."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.0.24","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/maxrmorrison/torchcrepe","docs":null,"changelog":null,"pypi":"https://pypi.org/project/torchcrepe/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}