crepe-predictor
A dependency-light reimplementation of CREPE pitch estimation, exported to ONNX for inference without PyTorch.
crepe_predictor.py— the runtime package: framing, Viterbi-decoded pitch prediction from an ONNX session, and Kaldi-compatible (NCCF, pitch) postprocessing, wrapped in aCrepePredictorclass.export_torchcrepe_to_onnx.py— script to (re-)generate the ONNX checkpoints.
Installation
pip install crepe-predictor
Inference only depends on numpy, onnxruntime, and scipy.
Exporting checkpoints additionally requires torch and onnxscript, listed as script dependencies at the top of export_torchcrepe_to_onnx.py.
API
Inference goes through crepe_predictor.CrepePredictor; crepe_predictor.postprocess_pitch is exposed separately for pitch that was produced elsewhere.
CrepePredictor(capacity="full", *, checkpoint=None, onnx_providers=None)
Resolves a checkpoint and opens an ONNX Runtime session for it.
capacity:"tiny","small","medium","large", or"full"— model size, trading accuracy for speed.checkpoint: path to a local.onnxfile. If omitted, the checkpoint matchingcapacityis downloaded and cached under$CREPE_CACHE_DIR,$XDG_CACHE_HOME, or~/.cache/crepe_predictor/checkpoints.onnx_providers: ONNX Runtime execution providers, e.g.["CUDAExecutionProvider", "CPUExecutionProvider"]. Defaults to["CPUExecutionProvider"].
predict(audio, *, viterbi=True, center=True, frame_shift=0.01, frame_length=0.025) -> np.ndarray
Estimates pitch from 16 kHz mono audio, returning an (n_frames, 2) array of (POV, pitch): probability of voicing in [0, 1], and pitch in Hz.
viterbi: decode pitch bins along a Viterbi path enforcing pitch continuity, instead of a per-frame argmax.center: padaudioso each frame is centered on its timestamp.frame_shift,frame_length: frame spacing and length in seconds, used to resample the output to the frame count they imply.
predict_kaldi(audio, *, viterbi=True, center=True, frame_shift=0.01, frame_length=0.025) -> np.ndarray
Same arguments as predict, but returns (n_frames, 2) of (NCCF, pitch), compatible with Kaldi's process-pitch: unvoiced frames are detected with a voicing HMM, pitch is interpolated over them, and POV is converted to an NCCF value. Raises ValueError if no frame is voiced.
postprocess_pitch(pitch) -> np.ndarray
The (POV, pitch) → (NCCF, pitch) conversion predict_kaldi applies, exposed on its own so it can be run over an (n_frames, 2) array obtained from predict earlier or from another pitch extractor.
Usage
Estimate pitch from a synthetic tone:
import numpy as np
from crepe_predictor import CrepePredictor
predictor = CrepePredictor("full") # "tiny", "small", "medium", "large", or "full"
t = np.arange(16000) / 16000 # 1 second at 16 kHz
audio = np.sin(2 * np.pi * 220 * t).astype(np.float32) # a 220 Hz tone
pov, pitch = predictor.predict(audio).T
print(pitch[pov > 0.5]) # pitch in Hz for confidently voiced frames
Process a recording and produce Kaldi-compatible pitch features, running on GPU when available:
from scipy.io import wavfile
from crepe_predictor import CrepePredictor
predictor = CrepePredictor(
"full",
onnx_providers=["CUDAExecutionProvider", "CPUExecutionProvider"],
)
sample_rate, audio = wavfile.read("speech.wav")
assert sample_rate == 16000
audio = audio.astype("float32") / 32768.0 # int16 PCM -> float32 in [-1, 1]
nccf, pitch = predictor.predict_kaldi(audio).T
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crepe_predictor-0.1.1.tar.gz.
File metadata
- Download URL: crepe_predictor-0.1.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7c600c5ea3185e80c8235c5e951e71abd8c3795385ef80c5cbc11a20664b9e5
|
|
| MD5 |
f158f52591cb3193ad9edb76317a0905
|
|
| BLAKE2b-256 |
10cb44263463c0b3b27df7058f18d8b860362cff490ed7df3626a3b61725ae7c
|
File details
Details for the file crepe_predictor-0.1.1-py3-none-any.whl.
File metadata
- Download URL: crepe_predictor-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd1ea1b59432efb2e4e6b88b6e079bf04270cfd2b0379e98cca9229f7435c81c
|
|
| MD5 |
35e6b0cbdd27d40a9cf009b7533cd762
|
|
| BLAKE2b-256 |
7a882e2361cb472f9b0400adf17b317ea5447fe0a144f174ec261ff0a0978788
|