Skip to main content

libsonare

PyPI npm License Docs

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 76 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 — 76 named DSP processors, the configurable mastering_chain, 25 named presets via master_audio, dynamics / repair specialist functions, and reference-matching. → Mastering processors
  • Mixing — offline mix_stereo and the block-based Mixer with 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 & streamingRealtimeEngine (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 DAWProject arrangement model: audio / MIDI tracks and clips, undo/redo, SMF / MIDI 2.0 Clip File I/O, deterministic JSON, offline bounce. → 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.

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

libsonare-1.5.5-py3-none-manylinux_2_17_x86_64.whl (3.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

libsonare-1.5.5-py3-none-manylinux_2_17_aarch64.whl (3.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

libsonare-1.5.5-py3-none-macosx_11_0_arm64.whl (2.5 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file libsonare-1.5.5-py3-none-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for libsonare-1.5.5-py3-none-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 667ef4e123e6e041dabc15f6a2b106127355f235d1396f9b3374a322e02efdff
MD5 40fdf55b7586906c47590878d7e556a4
BLAKE2b-256 9730bdd30c4afadb61c15d1cd3ac988d267434cfb6ac9426a973ce858e6314f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for libsonare-1.5.5-py3-none-manylinux_2_17_x86_64.whl:

Publisher: publish.yml on libraz/libsonare

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libsonare-1.5.5-py3-none-manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for libsonare-1.5.5-py3-none-manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 09eb2688bc027324aa39b66ce85b493bfc581e4161de3969f9c1d934e5a1344e
MD5 a61f5c22365466b0c07ea5af2b1c0e8b
BLAKE2b-256 2bdd54bd5e8fce38f136886fea1d95e55c22e7ec651bf3c71fe3eac89c96086e

See more details on using hashes here.

Provenance

The following attestation bundles were made for libsonare-1.5.5-py3-none-manylinux_2_17_aarch64.whl:

Publisher: publish.yml on libraz/libsonare

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libsonare-1.5.5-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for libsonare-1.5.5-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b181af5fe504d4cd557ddd9b03e21c34ee8f67b2e37b4ecd69b8ce43ea2845ce
MD5 d9aed6480c6f14f797cd2ebd51fe84ee
BLAKE2b-256 fac9700364c9d3b73b9dfa2cb95f5d16b917cdd316fffd74ae4df6dfa0c9426d

See more details on using hashes here.

Provenance

The following attestation bundles were made for libsonare-1.5.5-py3-none-macosx_11_0_arm64.whl:

Publisher: publish.yml on libraz/libsonare

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page