uppercut-beat-grid
Detects tempo, beats and downbeats in audio and writes them as a JSON beat grid with a frame index for every beat. It also checks or snaps cut times to a grid, and renders a synthesized music bed at an exact tempo together with the grid it was built on, so cuts can land on beats with no detection error. The grid data model, alignment and bed synthesis use only NumPy. WAV files load with the standard library; other formats need the audio extra, and the optional librosa extra adds librosa's beat tracker as a second detection backend.
Install
pip install uppercut-beat-grid
pip install "uppercut-beat-grid[audio]" # FLAC, OGG and float WAV input
pip install "uppercut-beat-grid[librosa]" # librosa backend
Example
from uppercut_beat_grid import detect, align, make_grid, generate_bed, write_bed
result = detect("track.wav") # tempo, beats, downbeats, energy, onsets
print(result["tempo"], result["downbeats"][:4])
grid = make_grid(bpm=128, duration=15, fps=60) # planned grid with frame indices
report = align([0.47, 0.94, 1.6], grid, tolerance_ms=17)
print(report.misses, [r.delta_ms for r in report.results])
bed = generate_bed(124, "intro:2,build:4,drop:4,outro:2", style="pulse", seed=3)
write_bed(bed, "sound/bed") # bed.wav, bed.stems/*.wav, bed.grid.json
Command line:
uppercut-beat-grid detect track.wav --json track.grid.json
uppercut-beat-grid grid --bpm 128 --duration 15 --fps 60 --json plan.json
uppercut-beat-grid align --cuts cuts.json --beats plan.json --tolerance-ms 17
uppercut-beat-grid bed --bpm 124 --sections intro:2,build:4,drop:4,outro:2 --out sound/bed
align exits with 1 when any cut misses. A cuts file is a JSON list of times in seconds or {"cuts": [...]}.
Functions
| Function | What it does |
|---|---|
detect(audio, sr=None, backend="fit", bpm_hint=None, beats_per_bar=4) |
Tempo, beat times, downbeat phase and times, per-beat energy and onset times. audio is a path or a mono array (with sr). Backend "fit" uses NumPy; "librosa" needs the extra. Detected tempo can be off by a factor of two; bpm_hint pins it. |
fit_tempo(envelope, hop_seconds, bpm_hint=None) |
Constant-tempo and phase fit on an onset envelope: grid search over the half, same and double of the estimate, an octave prior around 120 BPM, and a least-squares refinement. |
onset_envelope(y, sr) |
Spectral-flux onset strength and its seconds per frame. |
pick_downbeat_phase(envelope, hop_seconds, beats, beats_per_bar) |
Which beat starts a bar, by onset strength. |
grid_from_detection(result, fps=60) |
A grid dict from a detect result. |
make_grid(bpm, duration, offset=0, fps=60, beats_per_bar=4) |
A planned grid: beats with i, t, bar, beat, frame, plus half-beats. |
save_grid(grid, path), load_grid(path), beat_times(grid), frame_index(t, fps) |
JSON round trip and helpers. |
snap_to_grid(t, beats, reach=None) |
Nearest beat time, or None beyond reach seconds. |
align(cuts, beats, tolerance_ms=17, half=False, auto_offset=False) |
An AlignReport with each cut's distance to the nearest beat. half adds half-beats as targets. auto_offset removes the median delta first, for judging a delivered file whose detected beats lag by a constant. 17 ms is one frame at 60 fps. |
snap_cuts(cuts, beats, half=False, reach=None) |
Cut times moved to their nearest beats. |
generate_bed(bpm, sections, style="pulse", key="A", scale="minor", seed=3, fps=60, end_hit=False, gaps=(), rate=48000) |
A Bed(stems, mix, grid, rate). Sections: intro, build, groove, drop, break, outro, hold. Styles: pulse, lofi, drive. Scales: minor, major, dorian. Each beat in gaps is preceded by half a beat of silence. |
write_bed(bed, out) |
Writes out.wav (24-bit stereo, peak -6 dBFS), out.stems/*.wav and out.grid.json. |
read_audio(path), write_wav24(path, samples, rate) |
Audio file helpers. |
The same bed arguments always produce the same samples.
Errors
| Error | Raised when |
|---|---|
ValueError |
A tempo, fps or tolerance is out of range, a section string is malformed, a gap is outside the bed, a style, key or scale is unknown, there are no beats to align to, or the audio is too short to analyse. |
ImportError |
The librosa backend or a non-WAV format is used without its extra installed. |
License
MIT
Metadata
Release files for uppercut-beat-grid 0.1.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 |
|---|---|---|---|---|
| uppercut_beat_grid-0.1.0.tar.gz | 19.7 kB | Without provenance | Details for uppercut_beat_grid-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| uppercut_beat_grid-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for uppercut_beat_grid-0.1.0-py3-none-any.whl |
Total release size: 39.3 kB
Release files / uppercut_beat_grid-0.1.0.tar.gz
| Download URL | uppercut_beat_grid-0.1.0.tar.gz |
|---|---|
| Size | 19.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bbb29685645343951eec0f8cb5e016c2db87e6bbb557e98bf730486fe15af5c3
|
|
BLAKE2b-256 checksum How to use checksums |
8231fdc17c047928595b06abbd110ff46bd14478d65a59ef4744d8eabd7af7b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / uppercut_beat_grid-0.1.0-py3-none-any.whl
| Download URL | uppercut_beat_grid-0.1.0-py3-none-any.whl |
|---|---|
| Size | 19.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
68fd4fc13f584c03509258ad49aecdcd8091739a3f606dd3e7da97781c3fcbf1
|
|
BLAKE2b-256 checksum How to use checksums |
32816ec2440a190899f2dce077eda1dbba1d9ba2d41900cfc9ae27ecaefb043c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for uppercut-beat-grid 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.