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

Not on PyPI before 6.2.0. The first release, 6.2.0, reaches PyPI with the JS library's 6.2.0. If pip can't find it yet, build it from a clone of the repository with pip install ./packages/python.

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.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 realtime-bpm-analyzer 6.2.0
File Size Uploaded Provenance Actions
realtime_bpm_analyzer-6.2.0.tar.gz 20.8 kB With provenance Details for realtime_bpm_analyzer-6.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 45.3 kB

Release files / realtime_bpm_analyzer-6.2.0.tar.gz

Download URL realtime_bpm_analyzer-6.2.0.tar.gz
Size 20.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3b7feba12fede523b9cf7374b531365cd8693f8245ae1599f9bbef5ab0d7e9b6
BLAKE2b-256 checksum
How to use checksums
098d3167149c55544ba424b05340a2583a8c458edbb0717335a567160dce7cb6
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 16, 2026.

Transparency log

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

Download URL realtime_bpm_analyzer-6.2.0-py3-none-any.whl
Size 24.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da0b1c4ab81b8426df46c468b66b8933b194bb10ba614458a0b37b7ef24f420d
BLAKE2b-256 checksum
How to use checksums
cdcb2a3429a4d631b97763dc34a31e62da641ebd6eb99a0a27f7466217971a8a
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 16, 2026.

Transparency log

Security for realtime-bpm-analyzer 6.2.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.

Select from 2 files

Attestation for realtime_bpm_analyzer-6.2.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 16, 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