Skip to main content

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 a CrepePredictor class.
  • 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

Everything is exposed through crepe_predictor.CrepePredictor.

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 .onnx file. If omitted, the checkpoint matching capacity is 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: pad audio so 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.

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

crepe_predictor-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crepe_predictor-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file crepe_predictor-0.1.0.tar.gz.

File metadata

  • Download URL: crepe_predictor-0.1.0.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

Hashes for crepe_predictor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 888396a1c8ed8720c45016950fcb79e8cf23d848db3364d78a69bfa5789f615f
MD5 b8223aae831504b58b30bd2242ec5102
BLAKE2b-256 6383aba66cbef7a430f02de6e89433bf99238e08ed300e7d593a73d00d1a840d

See more details on using hashes here.

File details

Details for the file crepe_predictor-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: crepe_predictor-0.1.0-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

Hashes for crepe_predictor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5af87827a0300e8508c565b82741d938c1e8575319588c64c5bac12bcbb6b003
MD5 74844aee581ac8aeefbea53f2976c1fd
BLAKE2b-256 53754c301b4b17abb96987baffb21f279b9505d8b190780eda4df24c2fb4f207

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page