Caution

You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.10.2.

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.

Sharps are indicated with #, flats may be indicated with ! or b.

Parameters:
notestr or iterable of str

One or more note names.

round_midibool
  • If True, allow for fractional midi notes

  • Otherwise, round cent deviations to the nearest note

Returns:
midifloat or np.array

Midi note numbers corresponding to inputs.

Raises:
ParameterError

If the input is not in valid note format

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])