Skip to main content

libretta

An AI-oriented music analysis pipeline built on librosa, Demucs, and Basic Pitch.

Stem separation, MIDI transcription, spectral analysis, chord detection, ghost frequency diagnostics, and spectrogram visualization, all from one command. Outputs structured JSON that language models can reason over.

What it does

  1. Stem separation (Demucs) splits a mix into vocals, drums, bass, and other
  2. MIDI transcription (Basic Pitch) detects notes and exports MIDI files with pitch bends
  3. Feature extraction (librosa) pulls tempo, key, chroma, spectral features, dynamics, MFCCs, beat timing, harmonic/percussive ratio
  4. Chord detection estimates chords at each beat using chroma template matching
  5. Ghost frequency detection finds inaudible subsonic/ultrasonic energy eating your headroom
  6. Spectrogram rendering generates mel spectrograms, chromagrams, piano rolls, waveforms, and frequency spectrum plots

Each step runs on both the full mix and each individual stem for maximum accuracy.

Note: Demucs and Basic Pitch download model weights on first run. Demucs pulls ~80MB from Meta's CDN, Basic Pitch pulls its ONNX model automatically. After that, they're cached locally.

Install

pip install libretta

For full features (stem separation + better MIDI transcription):

pip install libretta[all]

On Windows, if basic-pitch gives you trouble:

pip install onnxruntime
pip install "basic-pitch==0.3.3" --no-build-isolation

For GPU acceleration (recommended), install PyTorch with CUDA:

pip install torch torchaudio --index-url https://download.pytorch.org/whl/cu121

Quick test

# verify the install works
python -m libretta.cli --help

Usage

Command line

# full analysis
libretta song.mp3

# skip stem separation (faster, just analyze the mix)
libretta song.wav --no-stems

# skip spectrogram images
libretta song.flac --no-images

# use the fine-tuned demucs model (better quality, slower)
libretta song.mp3 --model htdemucs_ft

# force CPU
libretta song.mp3 --cpu

# custom output directory
libretta song.mp3 -o ./my_analysis

Python API

from libretta import analyze, separate_stems, render_spectrograms

# analyze a single file
result = analyze("song.mp3", tag="mix")
print(result["key"])       # "F major"
print(result["bpm"])       # 120.5
print(result["chords"])    # [{"time": 0.0, "chord": "Fmaj", "conf": 0.89}, ...]
print(result["notes"])     # [{"start": 0.5, "end": 1.2, "pitch": 69, "name": "A4", "vel": 0.7}, ...]

# separate stems
stems = separate_stems("song.mp3", "./stems")
# returns {"drums": "./stems/drums.wav", "bass": "./stems/bass.wav", ...}

# render spectrograms
render_spectrograms("song.mp3", "mix", "./images", notes=result["notes"])

Output

Running libretta song.mp3 creates:

analysis_song/
  analysis.json          # all data, structured, feedable to an LLM
  report.txt             # human readable summary
  stems/
    drums.wav
    bass.wav
    other.wav
    vocals.wav
    other.mid            # MIDI transcription per stem
    bass.mid
    vocals.mid
  images/
    mix_overview.png     # mel spectrogram + chromagram + piano roll + waveform
    mix_spectrum.png     # frequency spectrum with ghost frequency zones
    drums_overview.png
    drums_spectrum.png
    ...

Ghost frequencies

libretta detects inaudible subsonic (below 20Hz) and ultrasonic (above 18kHz) energy that eats headroom and confuses limiters. It filters these out before analysis so the readings are accurate, but flags them in the report so you know your mix has a problem to fix.

Silent stems (like when Demucs splits a solo piano into "drums" and gets basically nothing) are automatically detected via RMS threshold and marked as unreliable.

Requirements

  • Python 3.10+
  • librosa, numpy, scipy, soundfile, matplotlib, torch, torchaudio (core)
  • demucs (optional, for stem separation)
  • basic-pitch + onnxruntime (optional, for MIDI transcription, falls back to pyin)
  • CUDA GPU recommended but not required

License

MIT

Metadata

Release files for libretta 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for libretta 0.1.2
File Size Uploaded Provenance Actions
libretta-0.1.2.tar.gz 14.4 kB Without provenance Details for libretta-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for libretta 0.1.2
File Interpreter ABI Platform Actions
libretta-0.1.2-py3-none-any.whl Python 3 none any Details for libretta-0.1.2-py3-none-any.whl

Total release size: 27.9 kB

Release files / libretta-0.1.2.tar.gz

Download URL libretta-0.1.2.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7f78d43e708ceb33c2880380286105f385bfa3549d46de9f986afa613b2962b8
BLAKE2b-256 checksum
How to use checksums
712c6c7071aafdb76ab2d6dc29fa91155da41648fce5fe3650c4a8983775499f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / libretta-0.1.2-py3-none-any.whl

Download URL libretta-0.1.2-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a128ebd92ba2c66e99b69397d36cfd5b857b3741eb536167f536f75135eb7987
BLAKE2b-256 checksum
How to use checksums
19bc3ee19a5d97b8e72532eed8810bd3e5de9f42e58c246e29165bd752924635
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for libretta 0.1.2

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.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page