libsonare
Turn audio into data and back, from Python. Analyze songs (BPM, key, chords, loudness), master and mix to broadcast loudness, and render MIDI through built-in instruments — a fast C++ core with NumPy as its only dependency.
Mastering ships 88 named DSP processors implemented against published references (ITU-R BS.1770-4 true-peak limiting, Linkwitz-Riley crossovers, Vicanek matched-Z biquads, ADAA-antialiased saturation); analysis defaults match librosa where the two overlap (validated against generated librosa reference values in CI). Apache-2.0, no model weights.
📖 Full API reference, guides, and CLI docs: libsonare.libraz.net
Installation
pip install libsonare
Supported platforms: Linux (x86_64, aarch64), macOS (Apple Silicon).
Quick Start
Audio is the recommended entry point: it decodes files and caches samples. The
top-level libsonare.detect_* / libsonare.analyze functions are thin wrappers
for one-shot calls on a numpy array.
import libsonare
audio = libsonare.Audio.from_file("song.mp3") # or "song.wav"
result = audio.analyze() # BPM + key + time signature + beats
print(f"BPM: {result.bpm:.1f} Key: {result.key.root.name} {result.key.mode.name}")
# Master toward a target loudness with a named preset
mastered = libsonare.master_audio(
audio.data, sample_rate=audio.sample_rate, preset_name="streaming",
)
print(mastered.output_lufs, mastered.applied_gain_db)
Analyze a numpy array directly (mono float32; downmix stereo first):
import numpy as np
samples = np.asarray(my_mono_float32_signal, dtype=np.float32)
bpm = libsonare.detect_bpm(samples, sample_rate=22050)
key = libsonare.detect_key(samples, sample_rate=22050) # Key(root, mode, confidence)
Render a MIDI arrangement through a built-in instrument with the headless
Project (a context manager):
with libsonare.Project() as project:
project.set_sample_rate(48000)
_, clip_id = project.add_midi_clip(0.0, 4.0)
project.set_midi_events(clip_id, [
libsonare.Project.midi_note_on(0.0, 0, 0, 60, 100), # ppq, group, channel, note, velocity
libsonare.Project.midi_note_off(2.0, 0, 0, 60),
])
audio = project.bounce_with_synth_instrument("saw-lead", num_channels=2)
Capabilities
Every area below has runnable examples and the full API in the
documentation. The functional and
Audio-method forms return identical results; Audio caches decoded samples and
is preferred when doing more than one computation on the same signal.
- Analysis — BPM, key (+ candidates), chords, downbeats, sections, melody, tuning; pitch (YIN / pYIN), timbre, and the full spectral feature set (STFT, mel, MFCC, chroma, CQT/VQT, spectral contrast); metering (
metering_*,waveform_peaks). → Python API - Mastering — 88 named DSP processors, the configurable
mastering_chain, 25 named presets viamaster_audio, dynamics / repair specialist functions, and reference-matching. → Mastering processors - Mixing — offline
mix_stereoand the block-basedMixerwith scene presets. → Mixing - Editing DSP — time-stretch, pitch-shift, HPSS (+ residual), phase vocoder, normalize, trim, remix. → Editing DSP
- Room acoustics — blind RT60 / EDT, impulse-response clarity metrics,
estimate_room,synthesize_rir,room_morph. → Room acoustics - Realtime & streaming —
RealtimeEngine(transport / MIDI / render / capture),StreamAnalyzer,StreamingMasteringChain,RealtimeVoiceChanger. → Realtime & streaming - Instruments & synthesis — built-in oscillator synth, patch-driven NativeSynth (15 synthesis engines, incl. physically-modeled piano / strings / winds — being tuned over time), and a GS-compatible SoundFont (SF2) player. → Python API
- Headless DAW —
Projectarrangement model: audio / MIDI tracks and clips, undo/redo, SMF / MIDI 2.0 Clip File I/O, deterministic JSON, offlinebounce. → Python API - Conversions — Hz / mel / MIDI / note, frames / time, resample.
Native return-code failures raise libsonare.SonareError (a RuntimeError
subclass carrying a numeric .code); input-validation failures (empty / NaN / Inf
buffers, bad shapes) raise ValueError.
CLI
The sonare command exposes the analysis, mastering, mixing, effects, and
project surfaces. A few representative commands:
sonare analyze song.mp3 # BPM + key summary
sonare bpm song.mp3 --json # {"bpm": 161.0}
sonare master song.wav -o mastered.wav --preset pop # preset mastering
sonare voice-change vocal.wav -o out.wav --preset bright-idol
sonare project bounce --in project.json -o out.wav --synth saw-lead
Run sonare --help (or sonare <command> --help), or see the
CLI reference for the full command list.
Realtime voice changer preset schemas
The wheel includes JSON Schema documents for third-party voice changer presets.
Use importlib.resources to obtain them instead of copying a schema into an
application:
from importlib.resources import files
preset_schema = files("libsonare").joinpath(
"schemas/realtime-voice-changer-preset.schema.json"
)
Validate data against this schema before saving it, then call
validate_realtime_voice_changer_preset_json() before applying it. The runtime
check is authoritative and also rejects malformed JSON such as duplicate keys.
Supported audio formats
| Format | Default build | With FFmpeg support |
|---|---|---|
| WAV (PCM 16/24/32, float32) | yes | yes |
| MP3 | yes | yes |
| M4A / AAC / FLAC / OGG / Opus / WMA / ... | no | yes |
The PyPI wheels are pinned to SONARE_WITH_FFMPEG=OFF so the distributed
wheel never silently links against the build host's FFmpeg. To enable
FFmpeg-backed decoding, build from source with SONARE_FFMPEG=1 (see the
installation guide); this links
against the system FFmpeg shared libraries (LGPL by default), so install them
first (brew install ffmpeg, or apt install libavformat-dev libavcodec-dev libavutil-dev libswresample-dev).
Input format expectations
| API | dtype | shape | range |
|---|---|---|---|
Audio.from_buffer(samples, sample_rate=...) |
float32 (float64 also accepted) | 1D mono | nominally [-1.0, 1.0] |
Audio.from_memory(data) |
bytes of an encoded WAV / MP3 / (FFmpeg) file |
— | — |
Audio.from_file(path) |
path to an encoded audio file | — | — |
libsonare.detect_bpm(samples, sample_rate=...) etc. |
float32 (float64 also accepted) | 1D mono | nominally [-1.0, 1.0] |
Stereo input passed as samples is not downmixed automatically — downmix
yourself (e.g. samples.mean(axis=1, dtype=np.float32)). File loaders downmix to
mono internally.
librosa-compatible defaults
| Parameter | Default |
|---|---|
| Sample rate | 22050 Hz |
n_fft |
2048 |
hop_length |
512 |
n_mels |
128 |
fmin / fmax |
0.0 / sr/2 |
Documentation
Full API reference and guides live at libsonare.libraz.net (getting started · Python API · CLI).
Also available
npm install @libraz/libsonare # JavaScript / TypeScript (WASM)
License
Apache-2.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file libsonare-1.6.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: libsonare-1.6.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 3.5 MB
- Tags: Python 3, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8280c765bd7c75023d2a9392f5d6aa2b206c2e20a94572bc1b7905484e2a7dfc
|
|
| MD5 |
0c71b2df870d441bfd18e2338db08764
|
|
| BLAKE2b-256 |
e29cb9b65c3c2a5f04c4fed628437a617d230c400e2607b2d1495de21171e324
|
Provenance
The following attestation bundles were made for libsonare-1.6.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
publish.yml on libraz/libsonare
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libsonare-1.6.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
8280c765bd7c75023d2a9392f5d6aa2b206c2e20a94572bc1b7905484e2a7dfc - Sigstore transparency entry: 2329371152
- Sigstore integration time:
-
Permalink:
libraz/libsonare@9e23b374299107bfcc04d1716d4ece5de2aaab19 -
Branch / Tag:
refs/tags/v1.6.0 - Owner: https://github.com/libraz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9e23b374299107bfcc04d1716d4ece5de2aaab19 -
Trigger Event:
push
-
Statement type:
File details
Details for the file libsonare-1.6.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: libsonare-1.6.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 3.2 MB
- Tags: Python 3, manylinux: glibc 2.27+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f691a874c73c4e7e3fea712c42331b5f0d3165ff9e90354c03a33235306f5f5b
|
|
| MD5 |
cd5b409aa6e048fe1a4bda5094c09392
|
|
| BLAKE2b-256 |
49732fc17a24953e1c63d1b08a21977f33fe4d48db494c7bbab7d489d806fc93
|
Provenance
The following attestation bundles were made for libsonare-1.6.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl:
Publisher:
publish.yml on libraz/libsonare
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libsonare-1.6.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl -
Subject digest:
f691a874c73c4e7e3fea712c42331b5f0d3165ff9e90354c03a33235306f5f5b - Sigstore transparency entry: 2329370918
- Sigstore integration time:
-
Permalink:
libraz/libsonare@9e23b374299107bfcc04d1716d4ece5de2aaab19 -
Branch / Tag:
refs/tags/v1.6.0 - Owner: https://github.com/libraz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9e23b374299107bfcc04d1716d4ece5de2aaab19 -
Trigger Event:
push
-
Statement type:
File details
Details for the file libsonare-1.6.0-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: libsonare-1.6.0-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.6 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c471121a683a4e5ce129386f3991df89fdc5a45f2d7f6b4d6beece1d25f3960a
|
|
| MD5 |
d53ca803c1e6134bb184a653ae44cf9e
|
|
| BLAKE2b-256 |
d7add0fcfc075857f482a31e7874f2a54f048cf2264277c2cbd3ea875638d475
|
Provenance
The following attestation bundles were made for libsonare-1.6.0-py3-none-macosx_11_0_arm64.whl:
Publisher:
publish.yml on libraz/libsonare
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libsonare-1.6.0-py3-none-macosx_11_0_arm64.whl -
Subject digest:
c471121a683a4e5ce129386f3991df89fdc5a45f2d7f6b4d6beece1d25f3960a - Sigstore transparency entry: 2329370669
- Sigstore integration time:
-
Permalink:
libraz/libsonare@9e23b374299107bfcc04d1716d4ece5de2aaab19 -
Branch / Tag:
refs/tags/v1.6.0 - Owner: https://github.com/libraz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9e23b374299107bfcc04d1716d4ece5de2aaab19 -
Trigger Event:
push
-
Statement type: