librosa.core.note_to_midi

librosa.core.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:
note : str or iterable of str

One or more note names.

round_midi : bool
  • If True, allow for fractional midi notes
  • Otherwise, round cent deviations to the nearest note
Returns:
midi : float 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('f4')
65
>>> librosa.note_to_midi('Bb-1')
10
>>> librosa.note_to_midi('A!8')
116
>>> # Lists of notes also work
>>> librosa.note_to_midi(['C', 'E', 'G'])
array([12, 16, 19])