Skip to main content

audio-file-pitch-detector

Audio File Pitch Detector as a portable Python library.

Detect monophonic pitch over time from audio files or PCM buffers. For each voiced frame the library reports the nearest 12-tone equal-temperament note name (A4 = 440 Hz), exact frequency in Hz, and cents deviation. It also returns a pitch contour plus summary stats: most common note, average frequency, detected range, and unique note count.

This package diagnoses pitch. It does not correct, retune, or rewrite audio. There is no web UI, microphone capture, or network I/O.

Install

pip install audio-file-pitch-detector

From a local checkout:

pip install -e ".[dev]"

Formats: WAV is decoded with the Python standard library. MP3, M4A, and AAC require ffmpeg on your PATH. There is no hard file-size limit (unlike typical browser uploads).

Quick start

from audio_file_pitch_detector import analyze_file

result = analyze_file("take.wav")

print(result.most_common_note)      # e.g. "A4"
print(result.average_frequency)     # Hz
print(result.frequency_range)       # (min_hz, max_hz)
print(result.unique_note_count)

for frame in result.contour:
    if frame.voiced:
        print(f"{frame.time:.3f}s  {frame.note}  {frame.frequency:.2f} Hz  {frame.cents:+.1f} c")

Analyze a NumPy buffer directly:

import numpy as np
from audio_file_pitch_detector import analyze

sr = 22050
t = np.arange(sr) / sr
tone = 0.4 * np.sin(2 * np.pi * 440.0 * t)
result = analyze(tone, sample_rate=sr)
assert result.most_common_note == "A4"

CLI

audio-file-pitch-detector take.wav
audio-file-pitch-detector take.mp3 --json --contour
audio-file-pitch-detector long.wav --no-max-duration
audio-file-pitch-detector take.wav --frame-size 2048 --hop-size 512

Analysis window and long files

By default the library analyzes the first 120 seconds of a file (the same practical cap used by the browser tool for responsiveness). Override it:

API Behavior
max_duration=120 (default) Cap at two minutes
max_duration=None No duration cap
CLI --no-max-duration or --max-duration 0 No duration cap

The analysis frame size and hop size are also configurable (frame_size, hop_size).

Tips for better results

  • Prefer monophonic, relatively dry recordings (one voice or one instrument). Full mixes confuse time-domain detectors.
  • WAV / higher bitrates usually read cleaner than heavily compressed audio.
  • Quiet rooms and less reverb yield more voiced frames.
  • This is pitch detection, not pitch correction.

Public API

Symbol Role
analyze_file(path, **opts) -> PitchResult Analyze a file on disk
analyze_buffer(samples, sample_rate, **opts) -> PitchResult Analyze a PCM array
analyze(source, **opts) -> PitchResult File path, bytes, stream, or NumPy array
PitchResult Contour + summary stats
PitchFrame time, frequency, note, cents

Algorithm: YIN (time-domain), after De Cheveigné & Kawahara (2002).

Development

pip install -e ".[dev]"
pytest

License

MIT © Sherotree

Metadata

Release files for audio-file-pitch-detector 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for audio-file-pitch-detector 0.1.0
File Size Uploaded Provenance Actions
audio_file_pitch_detector-0.1.0.tar.gz 14.2 kB Without provenance Details for audio_file_pitch_detector-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for audio-file-pitch-detector 0.1.0
File Interpreter ABI Platform Actions
audio_file_pitch_detector-0.1.0-py3-none-any.whl Python 3 none any Details for audio_file_pitch_detector-0.1.0-py3-none-any.whl

Total release size: 30.3 kB

Release files / audio_file_pitch_detector-0.1.0.tar.gz

Download URL audio_file_pitch_detector-0.1.0.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7e9a3161fe02da76e8d3bc22944d202f0d5d721da24469bbbd5bfa34793c418a
BLAKE2b-256 checksum
How to use checksums
a9d3aa0239f415daa915bbe506fe0c8f1ea59302a3c57d9120d1a380be9e1550
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / audio_file_pitch_detector-0.1.0-py3-none-any.whl

Download URL audio_file_pitch_detector-0.1.0-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e2fe5e3e45846ff8f0a07624ca43ecffd92ddc0ffe19f8bcb6660a53be88694
BLAKE2b-256 checksum
How to use checksums
e7091e4bbe81c8ca226c45a7be75c6c5f8297f5f1f10dcf3faa1d2e1729f2549
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for audio-file-pitch-detector 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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