Expand description
Musical key detection via chromagram analysis.
Computes a 12-bin chroma vector (C, C#, D, β¦, B) from audio PCM data using frequency-domain energy estimation, then correlates against Krumhansl-Kessler key profiles for all 24 major/minor keys.
ConstantsΒ§
- MAJOR_
PROFILE π - Krumhansl-Kessler major key profile (starting from C).
- MINOR_
PROFILE π - Krumhansl-Kessler minor key profile (starting from C minor).
- NOTE_
NAMES π - Note names for display.
FunctionsΒ§
- compute_
chromagram π - Compute a 12-bin chromagram from PCM audio.
- detect_
key - Detect the musical key of an audio file. Returns a string like βC Majorβ, βF# Minorβ, or None if detection fails.
- goertzel π
- Goertzel algorithm: compute energy at a specific frequency. Much more efficient than FFT when you need only a few frequency bins.
- match_
key_ πprofile - Match a chroma vector against all 24 key profiles (12 major + 12 minor). Returns the best-matching key name.
- profile_
correlation π - Pearson correlation between chroma and a rotated key profile.