Caution

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

librosa.midi_to_note

librosa.midi_to_note(midi, *, octave=True, cents=False, key='C:maj', unicode=True)[source]

Convert one or more MIDI numbers to note strings.

MIDI numbers will be rounded to the nearest integer.

Notes will be of the format ‘C0’, ‘C♯0’, ‘D0’, …

Parameters
midiint or iterable of int

Midi numbers to convert.

octavebool

If True, include the octave number

centsbool

If true, cent markers will be appended for fractional notes. Eg, midi_to_note(69.3, cents=True) == 'A4+03'

keystr

A key signature to use when resolving enharmonic equivalences.

unicodebool

If True (default), accidentals will use Unicode notation: ♭ or ♯

If False, accidentals will use ASCII-compatible notation: b or #

Returns
notesstr or iterable of str

Strings describing each midi note.

Raises
ParameterError

if cents is True and octave is False

Examples

>>> librosa.midi_to_note(0)
'C-1'
>>> librosa.midi_to_note(37)
'C♯2'
>>> librosa.midi_to_note(37, unicode=False)
'C#2'
>>> librosa.midi_to_note(-2)
'A♯-2'
>>> librosa.midi_to_note(104.7)
'A7'
>>> librosa.midi_to_note(104.7, cents=True)
'A7-30'
>>> librosa.midi_to_note(list(range(12, 24)))
['C0', 'C♯0', 'D0', 'D♯0', 'E0', 'F0', 'F♯0', 'G0', 'G♯0', 'A0', 'A♯0', 'B0']

Use a key signature to resolve enharmonic equivalences

>>> librosa.midi_to_note(range(12, 24), key='F:min')
['C0', 'D♭0', 'D0', 'E♭0', 'E0', 'F0', 'G♭0', 'G0', 'A♭0', 'A0', 'B♭0', 'B0']