# 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:
    times np.ndarray

      times to place clicks, in seconds

    fs int

      desired sampling rate of the output signal

    click np.ndarray

      click signal, defaults to a 1 kHz blip

    length int

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

  Returns:
    click_signal np.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:
    gram np.ndarray

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

      Non-positive magnitudes are interpreted as silence.

    frequencies np.ndarray

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

    times np.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.

    fs int

      desired sampling rate of the output signal

    function function

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

    length int

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

    n_dec int

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

    threshold float

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

  Returns:
    output np.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:
    times np.ndarray

      time indices for each frequency measurement, in seconds

    frequencies np.ndarray

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

    fs int

      desired sampling rate of the output signal

    amplitudes np.ndarray

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

    function function

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

    length int

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

    kind str

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

  Returns:
    output np.ndarray

      synthesized version of the pitch contour

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

  Reverse synthesis of a chromagram (semitone matrix)

  Parameters:
    chromagram np.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]`

    times np.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.

    fs int

      Sampling rate to synthesize audio data at

    **kwargs

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

  Returns:
    output np.ndarray

      Synthesized chromagram

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

  Synthesizes chord labels

  Parameters:
    chord_labels list of str

      List of chord label strings.

    intervals np.ndarray, shape=(len(chord_labels), 2)

      Start and end times of each chord label

    fs int

      Sampling rate to synthesize at

    **kwargs

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

  Returns:
    output np.ndarray

      Synthesized chord labels