Skip to main content

Keysh

Keysh estimates the musical key of an audio file. It's a small neural network (128,000 weights, a 0.5 MB file) that analyses a song in about 0.1-0.15 s on one CPU thread, plus the time to decode the audio. Along with the key it reports how confident it is, the next most likely key, the keys of the first and last 30 seconds, and how far the recording is from A440 tuning.

The name is said like "quiche", and derived from "key-ish". It started as a key detector for a music radio project and grew into its own package.

$ keysh "Rebel Yell/07 - Crank Call.flac"
Rebel Yell/07 - Crank Call.flac   E   12B   0.40 (parallel Em 0.37)   open E   close Em   +5 cents

That line reads: E major (Camelot 12B) with probability 0.40, E minor close behind at 0.37, the song opens in E and ends in E minor, and the recording is 5 cents sharp. A low top probability, or a runner-up this close, is a hint to check the song by ear.

Install

pip install keysh
pip install "keysh[openvino]"    # optional OpenVINO runtime, same results

Python 3.9 or newer. No GPU needed. Keysh reads whatever libsndfile reads: FLAC, WAV, AIFF, OGG, Opus and MP3.

Usage

keysh song.flac
keysh ~/Music/Album                 # folders are searched recursively
keysh --json song.mp3               # one JSON object per song
keysh --json --probabilities x.wav  # include all 24 key probabilities
keysh --no-tuning ~/Music            # skip the tuning offset, about 10% faster
keysh --jobs 4 ~/Music               # files analysed at once (default: one per CPU core, at most 8)

By default Keysh analyses one file per CPU core at a time, up to 8, and prints results in the same order either way. Each extra job needs about 360 MB of memory. On four cores, 60 songs took 8 seconds with --jobs 4 --no-tuning against 35 seconds one at a time (decoding included). Most of the time per song goes into decoding the audio, so a big library mostly benefits from more cores.

From Python:

import keysh

k = keysh.Keysh()                  # loading takes a few seconds, so reuse it
r = k.analyze("song.flac")
r.key, r.camelot, r.confidence     # ('A minor', '8A', 0.71)
r.relative, r.parallel             # relative and parallel keys with their probabilities
r.major_probability                # 0.18
r.opening.key, r.closing.key       # keys of the first and last 30 seconds
r.tuning_cents                     # -3.2 (None with k.analyze(path, tuning=False))
r.as_dict(probabilities=True)

If you already have decoded audio, k.from_excerpts([mono_array, ...], sample_rate) returns the raw probabilities.

A few notes on the outputs:

  • The relative key uses the same notes (C major and A minor). The parallel key has the same tonic in the other mode (A minor and A major). Along with a fifth away, these are the most common mix-ups, so Keysh reports both.
  • major_probability near 0.5 means the song sits between major and minor. Blues-based and modal songs often do.
  • In songs under about 2 minutes the opening and closing excerpts overlap and get merged, so they cover more of the song.
  • Old records and transfers made at the wrong speed are often 20-40 cents off. If you mix by key, correct the pitch before trusting it.

Accuracy

Scores use the MIREX weighting: 1 for the right key, 0.5 for a fifth away, 0.3 for the relative key, 0.2 for the parallel key. Where a table credits a fifth in both directions rather than only above, it says so.

Compared with current DJ software

In November 2026 Kuartz published a test of its own key engine against Mixed In Key 11 and Traktor Pro 4.1 (Kuartz key detection benchmark). It uses the GiantSteps previews, two-minute Beatport clips of house, techno, drum and bass and so on, scored against the expert-corrected GiantSteps+ labels and against the original 2015 labels. They published every program's answer for every track, so I ran the released Keysh package on the same previews and scored it the same way, against their labels. Their scoring credits a fifth in either direction. Keysh never saw these tracks in training.

Software GiantSteps+, exactly right GiantSteps+, score Original labels, exactly right Original labels, score
Kuartz (November 2026) 79.7% 84.2 72.6% 77.8
Keysh 78.1% 83.2 71.2% 77.1
Mixed In Key 11 77.2% 82.8 72.4% 78.0
Traktor Pro 4.1 69.1% 76.6 65.3% 73.2

GiantSteps+ has 566 tracks with a single clear key; 565 of them have an original label. Between Keysh, Kuartz and Mixed In Key the gaps are at most 1.6 points exactly right and 1 point on the score, and a bootstrap over the tracks puts every one of them inside the noise (Keysh minus Mixed In Key on GiantSteps+: +0.5, 95% range -1.5 to +2.4). Traktor is clearly behind. The Kuartz results come from the company itself, and all of this is club music in two-minute clips; nobody has compared these programs on other genres. The per-track results and the scoring script are in research/benchmarks/.

Older results

Knees et al. scored the 2015 versions of the popular tools on the original GiantSteps labels (ISMIR 2015, Table 5), crediting a fifth only above. Keysh, scored the same way on the 599 previews still available:

Software Exactly right MIREX score
Rekordbox 3.2.2 71.9% 79.6
Keysh 70.0% 74.5
Mixed In Key 7 67.2% 74.6
KeyFinder 45.4% 59.3
Queen Mary key detector (used by Mixxx) 39.4% 52.9
Essentia 30.5% 44.9

Rekordbox's current version hasn't been tested on these tracks as far as I know.

Other kinds of music

These are cross-validated in five folds. An album, artist, classical piece or run of neighbouring clips never appears on both the training and the test side.

Music (songs tested) MIREX score
Classical: piano, orchestra, string quartets, art song (860) 83.4
Techno and house, GiantSteps+ (566, never trained on) 81.7
Rock, pop, soul and country from the 1950s on, from one large collection (569) 75.8
Electronic, Free Music Archive (634) 70.5
The rest of the Free Music Archive: folk, jazz, experimental, world and more (4,849) 67.4
Hip-hop, from the Free Music Archive and the collection (162) 66.9

The Free Music Archive and hip-hop scores are lower partly because a lot of those songs have no single clear key, and their labels come from volunteers rather than trained annotators. I haven't measured jazz separately, because the usual jazz test set was part of the training data.

How it works

  1. Keysh reads up to four 30-second excerpts: the first and last 30 seconds of music (silence at either end is skipped) and two from the middle. Overlapping excerpts are merged. Songs under about 105 seconds, and anything a minute or shorter, are read whole.
  2. Each excerpt becomes a log-compressed constant-Q spectrogram (librosa): 144 bins at 24 per octave from 41.2 Hz to 2.6 kHz, about 5 frames a second. Drums are left in.
  3. Six convolution layers look at 2-3 seconds at a time. Their output is averaged over the excerpt and mapped to the 24 keys. The song's key uses all the excerpts; the opening and closing keys use only the first and last.
  4. Tuning is measured separately from spectral peaks between 100 Hz and 2 kHz, averaging their offsets from A440 on a circle.

On one CPU thread a song takes about 50 ms for the spectrogram, 30-40 ms for the network and 30 ms for tuning, plus decoding.

Training data and the details of each licence are in MODEL_CARD.md.

Limits

  • One key per song, plus the opening and closing keys. Key changes in the middle aren't tracked.
  • The network can't tell you why it chose a key.
  • Some songs don't have one right answer. That's what the confidence, runner-up and major probability are for.

License

The code is MIT (LICENSE).

The model weights (keysh/keysh-128k.onnx) are CC BY-NC-SA 4.0 (LICENSES/CC-BY-NC-SA-4.0.txt), because some of the training data is non-commercial share-alike. Whether a dataset's licence carries over to weights trained on it isn't legally settled, so the weights carry those terms to be safe. If you need weights without them, the model card explains how to retrain on data you're allowed to use, and weights you train are yours.

Credits

Written by dmckean44 with Claude Opus 5.5 (Anthropic), which did most of the research, training and code. Training and test data: the Free Music Archive and its key labels, the Beatport EDM Key Dataset, GTZAN with its key annotations, MAESTRO, Sheet Sage and the Hooktheory community, Isophonics, the McGill Billboard Project, the Rock Corpus, Musopen, the Schubert Winterreise Dataset, and GiantSteps for testing. Full credits are in the model card.

Metadata

Release files for keysh 1.1.0

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

Source distribution (sdist)

Source distribution for keysh 1.1.0
File Size Uploaded Provenance Actions
keysh-1.1.0.tar.gz 514.2 kB Without provenance Details for keysh-1.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 1.0 MB

Release files / keysh-1.1.0.tar.gz

Download URL keysh-1.1.0.tar.gz
Size 514.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ca8507e630f65102e94f361c364395a69f75551bf15a4ca3528debcf9f804e48
BLAKE2b-256 checksum
How to use checksums
9cd08e5473c9e38f3f1112b7e386d815122e8ac917bf9bd6342d007c6e24d57a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / keysh-1.1.0-py3-none-any.whl

Download URL keysh-1.1.0-py3-none-any.whl
Size 501.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6714e5ec950afd029400ec0cc496c6839d57a08708ede81a9f98f1bd9dc1ee0d
BLAKE2b-256 checksum
How to use checksums
60c22d6337f831f610c1b33199fc5f59042e2f66c0f5755e642a7d4844086bb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for keysh 1.1.0

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

1.1.0 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