realtime-bpm-analyzer for Python
The offline BPM analysis of realtime-bpm-analyzer, ported to Python. You pass the decoded samples of one channel and get a reading back: the tempo, its confidence, and the other candidate tempos.
It gives the same readings as the JS library's analyzeChannelData. The repository's
conformance vectors hold the JS library's
readings of 140 cases, plus 8 that must fail, and the port's tests compare every one of them.
Install
pip install realtime-bpm-analyzer
It needs Python 3.11 or later and NumPy 1.26 or later, and has no native code of its own.
Versions
The version is the JS library's major and minor whose conformance vectors the port passes, plus its own patch:
6.3.x reads the same as realtime-bpm-analyzer 6.3 on npm. A patch of the port can ship without a JS release.
Example
Decoding a file is your job. This example uses soundfile, but any decoder that gives you samples from -1 to 1 works.
import soundfile
from realtime_bpm_analyzer import analyze_channel_data
samples, sample_rate = soundfile.read("song.wav", dtype="float32", always_2d=True)
reading = analyze_channel_data(samples[:, 0], sample_rate)
if reading is None:
print("No tempo found")
else:
print(f"{reading.bpm} BPM, confidence {reading.confidence}")
print("Candidates:", [candidate.bpm for candidate in reading.candidates])
API
def analyze_channel_data(
samples: Samples,
sample_rate: float,
*,
engine: Literal["tempogram", "peaks"] = "tempogram",
tempo_range: TempoRange | None = None,
lowpass: Lowpass | None = None,
) -> Reading | None
samples: one channel of numbers from -1 to 1, as a list, a floatarray.arrayor a 1-D float NumPy array. They are analysed as 32-bit floats, as the JS library holds them, so a float64 array reads like its float32 copy. Integers are refused, whatever holds them: scale integer PCM first, for 16-bit samplespcm / 32768.sample_rate: their rate in Hz. The tempogram needs at least 122.97509238026915 Hz, the first rate at which its FFT has a bin above DC, andpeaksat least 2 Hz. Releases before this floor refused only under 100 Hz, and returnedNonefrom there up to it.engine:"tempogram", the default, reads the full band."peaks"counts the intervals between bass peaks.tempo_range:TempoRange(min=90, max=180)by default. A reading is folded into this range by octaves, somaxmust be at least twicemin.lowpass: the peaks engine's filter,Lowpass(frequency=200, q=1)by default, with Q in dB. Onlypeakstakes one.
It returns None when it finds no tempo, as for silence or under 1.5 seconds of audio for the tempogram. Input with
no beat, such as noise, may still return a reading. Otherwise it returns a frozen Reading:
| Field | Type | |
|---|---|---|
bpm |
int |
The tempo, rounded |
bpm_exact |
float |
The tempo before rounding |
confidence |
float | None |
From 0 to 1, calibrated on the default 90 to 180 BPM range. None with any other range, for a tempo outside it, or for a peaks reading found only relative to a quiet or bass-light input's own level, which input may hold no beat at all |
candidates |
tuple[Candidate, ...] |
Up to 5 tempos, best first. Each has a bpm and a relation to the top one: "top", "half", "double" or "other" |
audio |
AudioSpan |
The span read, in seconds: start and end |
engine |
str |
The engine that read it |
The options and defaults are the JS library's, in snake case. Two names differ from the JS reading: the JS
audio.from and audio.to are audio.start and audio.end here, since from is a Python keyword, and the JS
audio.contextTime is left out, since it is always null in an offline reading.
Errors
| Exception | When |
|---|---|
InvalidSamplesError (a ValueError) |
The samples are empty, not one channel, or hold a NaN or infinite sample (a float64 past float32's range included, which becomes infinite) |
OutOfRangeError (a ValueError) |
A value is out of range: the sample rate, the engine, the tempo range (its max must be at least twice its min and at most 2^31 - 1, and max / min must be finite), or the lowpass settings |
TypeError |
An argument has the wrong type, or the samples are integers |
Limits
- Offline only: it reads samples you already have. There is no live or microphone input, which the JS library does in the browser.
- It reads one channel. To read a stereo file, pass one channel, or your own mix of both.
- It doesn't decode audio files.
License
Apache-2.0, like the JS library.
Metadata
Release files for realtime-bpm-analyzer 6.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| realtime_bpm_analyzer-6.3.0.tar.gz | 22.0 kB | With provenance | Details for realtime_bpm_analyzer-6.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| realtime_bpm_analyzer-6.3.0-py3-none-any.whl | Python 3 | none | any | Details for realtime_bpm_analyzer-6.3.0-py3-none-any.whl |
Total release size: 47.9 kB
Release files / realtime_bpm_analyzer-6.3.0.tar.gz
| Download URL | realtime_bpm_analyzer-6.3.0.tar.gz |
|---|---|
| Size | 22.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab1c488ab07005bab0dd91ed765b978b35d3309700f11a198902603f5aa51884
|
|
BLAKE2b-256 checksum How to use checksums |
75810aac9285dc388163092340efb6a565bbac03f2b5b05f99bc09bbafc230c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logRelease files / realtime_bpm_analyzer-6.3.0-py3-none-any.whl
| Download URL | realtime_bpm_analyzer-6.3.0-py3-none-any.whl |
|---|---|
| Size | 25.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0753349d9a8b546bf0f11f221b9894da59c5cb5f639f5bb7fdd9e8854a19bc26
|
|
BLAKE2b-256 checksum How to use checksums |
86261688144eab7efda09cf0a8f8ab4cb7ee174c203673e4b9f291afed76d3b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logSecurity for realtime-bpm-analyzer 6.3.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for realtime_bpm_analyzer-6.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logA 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.