Audio-to-MIDI Transcription
Convert audio files to MIDI and MusicXML with full music analysis (tempo, key, chords, dynamics, instruments).
Tool
Script: scripts/transcribe.py -- wraps Basic Pitch, Demucs, librosa, and music21. Auto-installs dependencies.
Workflow
- Identify the input audio file (MP3, WAV, FLAC, OGG, M4A)
- Determine options:
- Stems? Add
--stems to separate vocals/drums/bass/other with Demucs first
- Output dir? Use
-o path or default to input file's directory
- Skip analysis? Add
--no-analysis if only MIDI/MusicXML needed
- Skip MusicXML? Add
--no-musicxml if only MIDI needed
- Run the transcription script
- Report output files and analysis summary to user
Engines
| Engine |
Flag |
Best for |
Accuracy |
| Basic Pitch |
--engine basic-pitch (default) |
Mixed/polyphonic music |
Good |
| Piano Model |
--engine piano |
Piano/keyboard music |
96.7% F1 |
For piano or keyboard music, always use --engine piano — it captures sustain/pedal, has far fewer ghost notes, and produces much more accurate MIDI.
Usage
# Piano music (recommended for piano/keyboard)
py -3.12 scripts/transcribe.py "piano.mp3" --engine piano
# General music (default engine: Basic Pitch)
py -3.12 scripts/transcribe.py "song.mp3"
# With stem separation (Demucs): each stem gets its own MIDI + MusicXML
py -3.12 scripts/transcribe.py "song.wav" --stems
# Custom output directory
py -3.12 scripts/transcribe.py "song.mp3" -o ./output --engine piano
# Tuning Basic Pitch sensitivity
py -3.12 scripts/transcribe.py "song.mp3" --onset-threshold 0.6 --frame-threshold 0.4
# MIDI only (skip MusicXML)
py -3.12 scripts/transcribe.py "song.mp3" --no-musicxml
# MIDI + MusicXML without analysis
py -3.12 scripts/transcribe.py "song.mp3" --no-analysis
Output Files
For input song.mp3:
song.mid -- MIDI file (for DAWs, notation software)
song.musicxml -- MusicXML (for MuseScore, Finale, Sibelius, Dorico)
song_analysis.json -- Full analysis (tempo, key, chords, dynamics, spectral)
With --stems, each stem produces its own MIDI + MusicXML:
vocals.mid, vocals.musicxml
drums.mid, drums.musicxml
bass.mid, bass.musicxml
other.mid, other.musicxml
Analysis Output
The _analysis.json contains:
- tempo_bpm: Detected BPM
- key: Detected key and mode (e.g. "A minor")
- key_confidence: 0-1 confidence score
- chords: Time-stamped chord progression
- unique_chords: Deduplicated chord list
- dynamics: Mean/max/min dB, dynamic range
- spectral: Centroid, bandwidth, rolloff, ZCR
- instrument_hints: Detected instrument categories
Tuning Parameters
| Flag |
Default |
Effect |
--onset-threshold |
0.5 |
Higher = fewer ghost notes, may miss quiet notes |
--frame-threshold |
0.3 |
Higher = stricter note detection |
--min-note-length |
58 |
Minimum note duration in ms |
For clean recordings (piano, guitar): defaults work well.
For complex mixes: use --stems for best results.
For percussive music: lower onset threshold to 0.3-0.4.
Dependencies
Auto-installed on first run: basic-pitch, librosa, music21, pretty_midi, numpy, onnxruntime.
With --stems: also installs demucs (includes PyTorch).
Requires: Python 3.12 (py -3.12), ffmpeg (for MP3 decoding).
Important: Use py -3.12 (not python) to run the script. Python 3.14 has compatibility issues with ML packages. The script auto-selects the ONNX backend for Basic Pitch (most compatible).
Supported Input Formats
MP3, WAV, FLAC, OGG, M4A, AAC, WMA
1---2name: audio-to-midi3description: Convert MP3/WAV/FLAC audio files to MIDI (.mid) and MusicXML (.musicxml) with full music analysis. Two engines: Basic Pitch (general-purpose polyphonic) and Piano Model (high-accuracy piano, 96.7% F1). Optional Demucs stem separation. Use --engine piano for piano/keyboard music for best results. Trigger when the user wants to: transcribe audio to MIDI, convert music to sheet music/notes, extract notes from audio, get MusicXML from a recording, analyze tempo/key/chords of a song, separate stems (vocals/drums/bass) and transcribe each, or any audio-to-notation task. Also triggers for requests like "convert this MP3 to MIDI", "get the notes from this song", "what key is this song in", "transcribe this audio", "separate and transcribe stems".4---56# Audio-to-MIDI Transcription78Convert audio files to MIDI and MusicXML with full music analysis (tempo, key, chords, dynamics, instruments).910## Tool1112**Script:** `scripts/transcribe.py` -- wraps Basic Pitch, Demucs, librosa, and music21. Auto-installs dependencies.1314## Workflow15161. Identify the input audio file (MP3, WAV, FLAC, OGG, M4A)172. Determine options:18 - **Stems?** Add `--stems` to separate vocals/drums/bass/other with Demucs first19 - **Output dir?** Use `-o path` or default to input file's directory20 - **Skip analysis?** Add `--no-analysis` if only MIDI/MusicXML needed21 - **Skip MusicXML?** Add `--no-musicxml` if only MIDI needed223. Run the transcription script234. Report output files and analysis summary to user2425## Engines2627| Engine | Flag | Best for | Accuracy |28|--------|------|----------|----------|29| Basic Pitch | `--engine basic-pitch` (default) | Mixed/polyphonic music | Good |30| **Piano Model** | `--engine piano` | Piano/keyboard music | **96.7% F1** |3132For piano or keyboard music, always use `--engine piano` — it captures sustain/pedal, has far fewer ghost notes, and produces much more accurate MIDI.3334## Usage3536```bash37# Piano music (recommended for piano/keyboard)38py -3.12 scripts/transcribe.py "piano.mp3" --engine piano3940# General music (default engine: Basic Pitch)41py -3.12 scripts/transcribe.py "song.mp3"4243# With stem separation (Demucs): each stem gets its own MIDI + MusicXML44py -3.12 scripts/transcribe.py "song.wav" --stems4546# Custom output directory47py -3.12 scripts/transcribe.py "song.mp3" -o ./output --engine piano4849# Tuning Basic Pitch sensitivity50py -3.12 scripts/transcribe.py "song.mp3" --onset-threshold 0.6 --frame-threshold 0.45152# MIDI only (skip MusicXML)53py -3.12 scripts/transcribe.py "song.mp3" --no-musicxml5455# MIDI + MusicXML without analysis56py -3.12 scripts/transcribe.py "song.mp3" --no-analysis57```5859## Output Files6061For input `song.mp3`:62- `song.mid` -- MIDI file (for DAWs, notation software)63- `song.musicxml` -- MusicXML (for MuseScore, Finale, Sibelius, Dorico)64- `song_analysis.json` -- Full analysis (tempo, key, chords, dynamics, spectral)6566With `--stems`, each stem produces its own MIDI + MusicXML:67- `vocals.mid`, `vocals.musicxml`68- `drums.mid`, `drums.musicxml`69- `bass.mid`, `bass.musicxml`70- `other.mid`, `other.musicxml`7172## Analysis Output7374The `_analysis.json` contains:75- **tempo_bpm**: Detected BPM76- **key**: Detected key and mode (e.g. "A minor")77- **key_confidence**: 0-1 confidence score78- **chords**: Time-stamped chord progression79- **unique_chords**: Deduplicated chord list80- **dynamics**: Mean/max/min dB, dynamic range81- **spectral**: Centroid, bandwidth, rolloff, ZCR82- **instrument_hints**: Detected instrument categories8384## Tuning Parameters8586| Flag | Default | Effect |87|------|---------|--------|88| `--onset-threshold` | 0.5 | Higher = fewer ghost notes, may miss quiet notes |89| `--frame-threshold` | 0.3 | Higher = stricter note detection |90| `--min-note-length` | 58 | Minimum note duration in ms |9192For clean recordings (piano, guitar): defaults work well.93For complex mixes: use `--stems` for best results.94For percussive music: lower onset threshold to 0.3-0.4.9596## Dependencies9798Auto-installed on first run: `basic-pitch`, `librosa`, `music21`, `pretty_midi`, `numpy`, `onnxruntime`.99With `--stems`: also installs `demucs` (includes PyTorch).100Requires: Python 3.12 (`py -3.12`), ffmpeg (for MP3 decoding).101102**Important:** Use `py -3.12` (not `python`) to run the script. Python 3.14 has compatibility issues with ML packages. The script auto-selects the ONNX backend for Basic Pitch (most compatible).103104## Supported Input Formats105106MP3, WAV, FLAC, OGG, M4A, AAC, WMA