Skip to main content

Audio analysis pipeline: stem separation, MIDI transcription, spectral analysis, chord detection, ghost frequency diagnostics, and spectrogram visualization.

Project description

libretta

Audio analysis pipeline that makes AI understand music. Stem separation, MIDI transcription, spectral analysis, chord detection, ghost frequency diagnostics, and spectrogram visualization, all from one command.

libretta takes an audio file, tears it apart, measures everything, and gives you structured data that a language model can reason over. Think of it as librosa's successor that actually tells you what's happening in a song instead of just handing you raw numbers.

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.

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libretta-0.1.1.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

libretta-0.1.1-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file libretta-0.1.1.tar.gz.

File metadata

  • Download URL: libretta-0.1.1.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for libretta-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bc4eb81d8e5c27da258969112bb6e8e80608b9153d9d37a260f1f752a8bb1e0f
MD5 f4503b9506d97ef4d0c36dc55faf5f68
BLAKE2b-256 4e4a1da7eade1b15bc9dc5c7053faf6cff8f2edb9191bf1c37905f503b9538b6

See more details on using hashes here.

File details

Details for the file libretta-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: libretta-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for libretta-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d5323098f2c29dcddc2292d15d5bb6590f7c9e39c36b387ccac8c9cb27bfa492
MD5 a460006e7e10798eebd40d24bc9227c4
BLAKE2b-256 583c95885938fc08119dc7d10bd0f128120b59081425d20b284e97b95257318d

See more details on using hashes here.

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