Skip to main content

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.2.x reads the same as realtime-bpm-analyzer 6.2 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 float array.array or 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 samples pcm / 32768.
  • sample_rate: their rate in Hz. The tempogram needs at least 100 Hz, and peaks at least 2 Hz.
  • 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, so max must be at least twice min.
  • lowpass: the peaks engine's filter, Lowpass(frequency=200, q=1) by default, with Q in dB. Only peaks takes one.

It returns None when it finds no tempo: silence, noise, or under 1.5 seconds of audio for the tempogram. 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
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.2.1

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

Source distribution (sdist)

Source distribution for realtime-bpm-analyzer 6.2.1
File Size Uploaded Provenance Actions
realtime_bpm_analyzer-6.2.1.tar.gz 20.7 kB With provenance Details for realtime_bpm_analyzer-6.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for realtime-bpm-analyzer 6.2.1
File Interpreter ABI Platform Actions
realtime_bpm_analyzer-6.2.1-py3-none-any.whl Python 3 none any Details for realtime_bpm_analyzer-6.2.1-py3-none-any.whl

Total release size: 45.1 kB

Release files / realtime_bpm_analyzer-6.2.1.tar.gz

Download URL realtime_bpm_analyzer-6.2.1.tar.gz
Size 20.7 kB
Tags Source
SHA-256 checksum
How to use checksums
32cae26f78f885bf30de7fe7102199122edb8b007abb7d722c2ef487296de516
BLAKE2b-256 checksum
How to use checksums
a5648d1fcba2eec0aa2acb007a6248b813a35431f07c2e6cffa4e14b6994a62d
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 log

Release files / realtime_bpm_analyzer-6.2.1-py3-none-any.whl

Download URL realtime_bpm_analyzer-6.2.1-py3-none-any.whl
Size 24.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4364f03648a2115004cbb4cbe0169edc0bc40419f9dcaedb7156057a57fe7323
BLAKE2b-256 checksum
How to use checksums
845b630d830222be61fb06d59513ecca8006db4703d87345eba9236068faf579
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 log

Security for realtime-bpm-analyzer 6.2.1

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.

Select from 2 files

Attestation for realtime_bpm_analyzer-6.2.1.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 log

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.

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