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.4-py3-none-manylinux_2_17_x86_64.whl (3.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

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

Uploaded Python 3manylinux: glibc 2.17+ ARM64

libsonare-1.5.4-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.4-py3-none-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for libsonare-1.5.4-py3-none-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 8af3a3d04bc6e8d7d50fb05357b907336efb920ad3a33e66c7b435ac49c42995
MD5 7cd000ce0695a892f2adb45761556b56
BLAKE2b-256 3f6080908915c30159446a9006d0433bab8939a16ddbba6a47424486186c65c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for libsonare-1.5.4-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.4-py3-none-manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for libsonare-1.5.4-py3-none-manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 0199b510120dbc37aa3308e91b7002fcd14730fc26bb95fbb77703be9161e88a
MD5 e385bedbad592eff494c1b54d4b0aa34
BLAKE2b-256 c6a275f0547170ca7b9971905e9dd97e7184b47c6aabeb497d1b4f08c55ad7d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for libsonare-1.5.4-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.4-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for libsonare-1.5.4-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 335a495dc4e2a87428c29961fe37d08ab32cce32be79034f680313bc0d1e78a8
MD5 d1712d7c9d4b8cd6601e21eb42d52e1e
BLAKE2b-256 21c48cbe98f120dafc9dd349eed3a2d7a69640ad7d59d2c5e28581453c13c4ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for libsonare-1.5.4-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