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 whose only Python dependency is NumPy 2.0.2 or later. Mastering includes named DSP processors implemented against published references; analysis defaults match librosa where the two overlap. Apache-2.0, no model weights.
Guides, API reference and CLI docs: libsonare.libraz.net
Installation
pip install libsonare
Supported platforms: Linux (x86_64, aarch64), macOS (Apple Silicon).
Quick Start
import libsonare
audio = libsonare.Audio.from_file("song.mp3") # or "song.wav"
result = audio.analyze() # BPM + key + time signature + beats
tempo = f"{result.bpm:.1f}" if result.bpm is not None else "unavailable"
print(f"BPM: {tempo} Key: {result.key.name}")
# Master toward a target loudness with a named preset
mastered = libsonare.master_audio(
audio.data, sample_rate=audio.sample_rate, preset="streaming",
)
print(mastered.output_lufs, mastered.applied_gain_db)
Render a MIDI arrangement through a built-in instrument with the headless Project (a context manager):
import libsonare
with libsonare.Project() as project:
project.set_sample_rate(48000)
clip_id = project.add_midi_clip(0.0, 4.0).clip_id
project.set_midi_events(clip_id, [
libsonare.midi_note_on(0.0, 0, 0, 60, 100), # ppq, group, channel, note, velocity
libsonare.midi_note_off(2.0, 0, 0, 60),
])
synth = libsonare.ProjectInstrumentBinding(instrument=libsonare.SynthPatch(preset="sawLead"))
rendered = project.bounce(num_channels=2, synth_instruments=[synth])
audio = rendered.channels # (channels, frames)
For music analysis, pass mono float32 samples and their sample rate. stft defaults to sr=22050, n_fft=2048 and hop_length=512. See librosa compatibility.
Capabilities
- Analysis — BPM, key, chords, downbeats, sections grouped by repeated material, melody, tuning, pitch, timbre, spectral features and metering. → Analysis
- Stem decomposition and transcription —
decompose_stemssplits a mix into stems, andtranscribeturns audio into MIDI events, with asingingmodel (monophonic_model="singing") for vocals. → Analysis, Audio to notes, CLI examples - Mastering — Named DSP processors, a configurable chain and named presets through
master_audio, and reference-matching. → Mastering processors - Restoration — five repair-only presets,
vinyl,tapeHiss,fieldRecording,voiceMemoandshellac78, plus repair of any channel count in one call (mastering_repair_analyze/mastering_repair_apply). → Mastering processors - Mixing — offline
mix_stereo, the block-basedMixerwith scene presets, andmixing_assistant_suggest, which suggests a mixer scene with a written explanation without applying it. → Mixing, Mixing assistant - Editing DSP — time-stretch, pitch-shift,
auto_tune, HPSS, phase vocoder, normalize, trim, remix. → Editing DSP - Note editing and takes — edit the notes of monophonic takes (
extract_notes) and polyphonic material (PolyphonicAnalysis), align a take to a reference withalign_take_to_reference, and build tuning targets from a MIDI melody withnote_targets_from_smf, and edit vocal takes offline with undo/redo throughVocalEditSession. → Project editing, Recording and takes - Room acoustics — blind RT60, impulse-response metrics,
estimate_room,synthesize_rir,room_morph,room_morph_stereo. → Room acoustics - Realtime and streaming —
RealtimeEnginewith MIDI 1.0 / 2.0 input, bus-to-bus routing with sends, sidechain keys (set_bus_sidechain),StreamAnalyzer,StreamingMasteringChainandRealtimeVoiceChanger(also an insert,voice.changer; pitch correction, harmony, vocoder and character stages, driven bynote_on/note_off/all_notes_offand the optionalcarrierargument toprocess_monoorprocess_planar, with the presetshardTune,robotMonotone,choirHarmony,vocoderStrings,megaphoneandradioVoice). → Realtime engine - Instruments and synthesis — built-in synth, the patch-driven NativeSynth (including a singing-voice engine, preset
singingVoice), and a GS-compatible SoundFont (SF2) player that receives GS SysEx and offers two GS insertion-effect realisations (gs_efx_realization), with a selectable rig per part (set_part_rig). The acoustic piano is calibrated; the other physical-model voices are still being tuned and will change in 2.0.x patch releases. → GM and GS, Native synth - Headless DAW —
Projectwith audio and MIDI tracks, undo/redo, SMF and MIDI 2.0 Clip File I/O, and offlinebounce;transcribe_to_clipwrites a transcription into a clip, andcompile(with_timeline=True)turns a project into a timeline a stoppedRealtimeEngineplays. → Project editing - Playback —
PlaybackRendererrenders PCM up to 7.1 to speakers or HRTF binaural headphones. → Playback - Parameter descriptors —
capability_catalog,mastering_insert_param_info,synth_engine_param_infoandsynth_patch_param_infoprovide defaults and applicable ranges, units, display scales and conditions. Patch enum descriptors list accepted tokens and their default. → Build controls from descriptors
The whole surface is listed in the Python API reference.
CLI
The sonare command exposes the analysis, mastering, mixing, effects and project surfaces.
sonare analyze song.mp3 # BPM, key and meter summary
sonare mastering song.wav -o mastered.wav --preset pop # preset mastering
sonare project import-smf song.mid -o project.json # MIDI file to project JSON
sonare project bounce project.json -o out.wav --synth sawLead
Run sonare --help, or see the CLI reference.
Audio decoding and encoding
WAV and MP3 decode out of the box. M4A / AAC / FLAC / OGG / Opus need FFmpeg, which the PyPI wheels are built without; build from source with SONARE_FFMPEG=1 to enable it (see the installation guide).
encode_audio always supports WAV output. Check capabilities().encode.ffmpeg for the additional formats the loaded build can encode.
Documentation
Getting started · Python API · CLI · Examples · Binding parity. The wheel bundles the JSON Schemas for realtime voice changer presets; see Realtime voice changer.
Also available
npm install @libraz/libsonare # JavaScript / TypeScript (WASM)
License
Apache-2.0
Metadata
Release files for libsonare 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| libsonare-2.0.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | Python 3 | none | Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 | Details for libsonare-2.0.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
| libsonare-2.0.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl | Python 3 | none | Linux glibc 2.28+ ARM64, Linux glibc 2.27+ ARM64 | Details for libsonare-2.0.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl |
| libsonare-2.0.0-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for libsonare-2.0.0-py3-none-macosx_11_0_arm64.whl |
Total release size: 22.0 MB
Release files / libsonare-2.0.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | libsonare-2.0.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 8.4 MB |
| Tags | Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
ea1b896f61e060288f56c4926c90a4eed292184d9aa33fea88f8e79f9aaa8fa0
|
|
BLAKE2b-256 checksum How to use checksums |
d1ad59399a033a4e399f38b2d7c815ac5e57a35958779c07b7d1dbc57fe0f2f6
|
| 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 26, 2026.
Transparency logRelease files / libsonare-2.0.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
| Download URL | libsonare-2.0.0-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 7.6 MB |
| Tags | Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
c8d266c3ceac4bc455a36366bfb9eb4746d5eda172f4808c04c641bfcdac20a4
|
|
BLAKE2b-256 checksum How to use checksums |
c232c08b8e06080066f31be2a550b9f4a944b5740b0eaed5a7b11d5d69058ab9
|
| 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 26, 2026.
Transparency logRelease files / libsonare-2.0.0-py3-none-macosx_11_0_arm64.whl
| Download URL | libsonare-2.0.0-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 6.0 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
6d0937e9b96f74932d07ae02a89ae10c6569bc93999fc237540e8023f42f9ded
|
|
BLAKE2b-256 checksum How to use checksums |
ad6ecbaec44fe028c59fe1e1da1f0271d7cc6550f58964adee066948a1c135ff
|
| 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 26, 2026.
Transparency logSecurity for libsonare 2.0.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
All 3 files in this release have been uploaded with provenance metadata.
Attestation for libsonare-2.0.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
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 26, 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.