librosa.note_to_midi#
- librosa.note_to_midi(note, *, round_midi=True)[source]#
Convert one or more spelled notes to MIDI number(s).
Notes may be spelled out with optional accidentals or octave numbers.
The leading note name is case-insensitive.
The empty string
""maps to np.nan.Sharps are indicated with
#, flats may be indicated with!orb.- Parameters:
- notestr or iterable of str
One or more note names.
- round_midibool
If
True, midi numbers are rounded to the nearest integer.If
False, allow fractional midi numbers.
- Returns:
- midifloat or np.array
Midi note numbers corresponding to inputs.
- Raises:
- ParameterValueError
If the input is not in valid note format
See also
Examples
>>> librosa.note_to_midi("C") 12 >>> librosa.note_to_midi("C#3") 49 >>> librosa.note_to_midi("C♯3") # Using Unicode sharp 49 >>> librosa.note_to_midi("C♭3") # Using Unicode flat 47 >>> librosa.note_to_midi("f4") 65 >>> librosa.note_to_midi("Bb-1") 10 >>> librosa.note_to_midi("A!8") 116 >>> librosa.note_to_midi("G𝄪6") # Double-sharp 93 >>> librosa.note_to_midi("B𝄫6") # Double-flat 93 >>> librosa.note_to_midi("C♭𝄫5") # Triple-flats also work 69 >>> # Lists of notes also work >>> librosa.note_to_midi(["C", "E", "G"]) array([12, 16, 19])