Key Detection
Infer the tonic key from a chord sequence.
Functions
detectKey
detectKey(chords: Chord[], declaredKey?: string | null, config?: DetectKeyConfig): string | null
Infer the tonic key from a chord sequence. Returns a key string (e.g. `'Am'`, `'G mixolydian'`) or `null` if no key scores above the minimum confidence threshold. If `declaredKey` is provided and scores above zero, it is returned unchanged unless it has zero diatonic overlap with the chords.
Types
DetectKeyConfig
interface
Options for `detectKey`.
forceKey?: string- Skip scoring entirely and return this key string.
fSharpOrGFlat?: "f-sharp" | "g-flat"- Resolve the ambiguous F♯/G♭ enharmonic key to one spelling. Defaults to `'f-sharp'`.