mir_eval.sonify

Methods which sonify annotations for “evaluation by ear”. All functions return a raw signal at the specified sampling rate.

mir_eval.sonify.clicks(times, fs, click=None, length=None)

Return a signal with the signal ‘click’ placed at each specified time

Parameters:
timesnp.ndarray

times to place clicks, in seconds

fsint

desired sampling rate of the output signal

clicknp.ndarray

click signal, defaults to a 1 kHz blip

lengthint

desired number of samples in the output signal, defaults to times.max()*fs + click.shape[0] + 1

Returns:
click_signalnp.ndarray

Synthesized click signal

mir_eval.sonify.time_frequency(gram, frequencies, times, fs, function=<ufunc 'sin'>, length=None, n_dec=1, threshold=0.01)

Reverse synthesis of a time-frequency representation of a signal

Parameters:
gramnp.ndarray

gram[n, m] is the magnitude of frequencies[n] from times[m] to times[m + 1]

Non-positive magnitudes are interpreted as silence.

frequenciesnp.ndarray

array of size gram.shape[0] denoting the frequency (in Hz) of each row of gram

timesnp.ndarray, shape= (gram.shape[1],) or (gram.shape[1], 2)

Either the start time (in seconds) of each column in the gram, or the time interval (in seconds) corresponding to each column.

fsint

desired sampling rate of the output signal

functionfunction

function to use to synthesize notes, should be 2\pi-periodic

lengthint

desired number of samples in the output signal, defaults to times[-1]*fs

n_decint

the number of decimals used to approximate each sonfied frequency. Defaults to 1 decimal place. Higher precision will be slower.

thresholdfloat

optimizes synthesis to only occur for frequencies that have a linear magnitude of at least one element in gram above the given threshold.

Returns:
outputnp.ndarray

synthesized version of the piano roll

mir_eval.sonify.pitch_contour(times, frequencies, fs, amplitudes=None, function=<ufunc 'sin'>, length=None, kind='linear')

Sonify a pitch contour.

Parameters:
timesnp.ndarray

time indices for each frequency measurement, in seconds

frequenciesnp.ndarray

frequency measurements, in Hz. Non-positive measurements or NaNs will be interpreted as un-voiced samples.

fsint

desired sampling rate of the output signal

amplitudesnp.ndarray

amplitude measurements, nonnegative defaults to np.ones((length,))

functionfunction

function to use to synthesize notes, should be 2\pi-periodic

lengthint

desired number of samples in the output signal, defaults to max(times)*fs

kindstr

Interpolation mode for the frequency and amplitude values. See: scipy.interpolate.interp1d for valid settings.

Returns:
outputnp.ndarray

synthesized version of the pitch contour

mir_eval.sonify.chroma(chromagram, times, fs, **kwargs)

Reverse synthesis of a chromagram (semitone matrix)

Parameters:
chromagramnp.ndarray, shape=(12, times.shape[0])

Chromagram matrix, where each row represents a semitone [C->Bb] i.e., chromagram[3, j] is the magnitude of D# from times[j] to times[j + 1]

timesnp.ndarray, shape=(len(chord_labels),) or (len(chord_labels), 2)

Either the start time of each column in the chromagram, or the time interval corresponding to each column.

fsint

Sampling rate to synthesize audio data at

**kwargs

Additional keyword arguments to pass to mir_eval.sonify.time_frequency()

Returns:
outputnp.ndarray

Synthesized chromagram

mir_eval.sonify.chords(chord_labels, intervals, fs, **kwargs)

Synthesizes chord labels

Parameters:
chord_labelslist of str

List of chord label strings.

intervalsnp.ndarray, shape=(len(chord_labels), 2)

Start and end times of each chord label

fsint

Sampling rate to synthesize at

**kwargs

Additional keyword arguments to pass to mir_eval.sonify.time_frequency()

Returns:
outputnp.ndarray

Synthesized chord labels