Module key_detect

Module key_detect 

Source
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.