Skip to main content

Harmonica

An independent reproduction of Harmonica: Accurate and Lightweight Instrument-Agnostic Music Transcription (Ou, Martel, Hennessy-Priest, Cho; arXiv:2609.04640). Audio of one pitched instrument goes in and its notes come out as MIDI, with no instrument label anywhere.

This is not the authors' code. Everything here was rebuilt from the paper. Where the paper leaves a detail unspecified, we filled it in with our own assumptions, so this implementation is not guaranteed to match the authors' exactly.

Transcribe a recording

uvx harmonica-amt song.wav                   # writes song.mid
uvx harmonica-amt song.flac -o out.mid       # choose where the MIDI goes
uvx harmonica-amt song.wav --model x-large   # the most accurate size; medium by default

Input can be WAV, FLAC, MP3, or OGG. Inference runs on a GPU if there is one, otherwise on the CPU.

Models

--model takes one of the sizes below or the path of a checkpoint. Each size ships with the decoding thresholds its development-set sweep chose. Scores are the mean OnP / OnPOff / Frm over the paper's eight test sets:

Variant Params Ours Paper
nano 25K .791 / .524 / .763 .808 / .547 / .773
small 131K .835 / .603 / .804 .854 / .638 / .815
medium (default) 654K .862 / .660 / .827 .879 / .687 / .838
large 3.1M .877 / .688 / .843 .891 / .713 / .848
x-large 14.7M .882 / .694 / .843 .895 / .721 / .852

docs/results.md breaks the scores down by test set.

Python

from harmonica import Harmonica

model = Harmonica()  # the bundled medium, on the GPU if there is one
notes = model.transcribe("song.wav")
notes.save_midi("song.mid")

for onset, offset, pitch in zip(notes.onsets, notes.offsets, notes.pitches):
    print(f"{onset:.2f}-{offset:.2f}s  MIDI {pitch}")

The model loads once, so reuse a Harmonica for many recordings. It also takes a NumPy array with its sample rate, model.transcribe(audio, 44100), and Harmonica(model, device=..., onset_threshold=..., frame_threshold=...) picks another model, device, or thresholds.

Reproduce the paper

uv sync                                      # Python 3.12+, a CUDA GPU
source .venv/bin/activate                    # puts harmonica on PATH
harmonica prepare --workers 16               # index the eight corpora
harmonica train --size medium                # one row of the table above
harmonica eval --size medium \
    --checkpoint outputs/harmonica-medium/checkpoints/checkpoint_latest.ckpt

Citation

This repository reproduces the following paper; please cite it:

@article{ou2026harmonica,
  title   = {Harmonica: Accurate and Lightweight Instrument-Agnostic Music Transcription},
  author  = {Longshen Ou and H{\'e}ctor Martel and Joe Hennessy-Priest and Taemin Cho},
  journal = {arXiv preprint arXiv:2609.04640},
  year    = {2026}
}

Metadata

Release files for harmonica-amt 0.2.1

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

Source distribution (sdist)

Source distribution for harmonica-amt 0.2.1
File Size Uploaded Provenance
harmonica_amt-0.2.1.tar.gz 69.5 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for harmonica-amt 0.2.1
File Interpreter ABI Platform
harmonica_amt-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 139.0 MB

Release files / harmonica_amt-0.2.1.tar.gz

Download URL harmonica_amt-0.2.1.tar.gz
Size 69.5 MB
Tags Source
SHA-256 checksum
How to use checksums
76206b8fc5a2e993d530e770e3ce0f3f5d7e8228614ddf7069e0217fc975d089
BLAKE2b-256 checksum
How to use checksums
279956911fab22390af51c5f300545e74dbd5a32a3e048a3d3ee18f046ac09ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / harmonica_amt-0.2.1-py3-none-any.whl

Download URL harmonica_amt-0.2.1-py3-none-any.whl
Size 69.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
107ebf71394e8499bfa450d55f244978e5d1b36e41036d7cd1661b094b4b99df
BLAKE2b-256 checksum
How to use checksums
b92049ae77cf77c1e4c0346dc6789f14ba66b2f3ac852c200a21a06710c1feac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for harmonica-amt 0.2.1

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.

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