msaf/utils.py
def sonify_clicks(audio, clicks, out_file, fs, offset=0):
    """Sonifies the estimated times into the output file.

    Parameters
    ----------
    audio: np.array
        Audio samples of the input track.
    clicks: np.array
        Click positions in seconds.
    out_file: str
        Path to the output file.
    fs: int
        Sample rate.
    offset: float
        Offset of the clicks with respect to the audio.
    """
    # Generate clicks (this should be done by mir_eval, but its
    # latest release is not compatible with latest numpy)
    times = clicks + offset
    # 1 kHz tone, 100ms
    click = np.sin(2 * np.pi * np.arange(fs * .1) * 1000 / (1. * fs))
    # Exponential decay
    click *= np.exp(-np.arange(fs * .1) / (fs * .01))
    length = int(times.max() * fs + click.shape[0] + 1)
    audio_clicks = mir_eval.sonify.clicks(times, fs, length=length)

    # Create array to store the audio plus the clicks
    out_audio = np.zeros(max(len(audio), len(audio_clicks)))

    # Assign the audio and the clicks
    out_audio[:len(audio)] = audio
    out_audio[:len(audio_clicks)] += audio_clicks

    # Write to file
    scipy.io.wavfile.write(out_file, fs, out_audio)
def sonify_clicks(audio, clicks, out_file, fs, offset=0):
    """Sonifies the estimated times into the output file.

    Parameters
    ----------
    audio: np.array
        Audio samples of the input track.
    clicks: np.array
        Click positions in seconds.
    out_file: str
        Path to the output file.
    fs: int
        Sample rate.
    offset: float
        Offset of the clicks with respect to the audio.
    """
    # Generate clicks (this should be done by mir_eval, but its
    # latest release is not compatible with latest numpy)
    times = clicks + offset
    # 1 kHz tone, 100ms
    click = np.sin(2 * np.pi * np.arange(fs * .1) * 1000 / (1. * fs))
    # Exponential decay
    click *= np.exp(-np.arange(fs * .1) / (fs * .01))
    length = int(times.max() * fs + click.shape[0] + 1)
    audio_clicks = mir_eval.sonify.clicks(times, fs, length=length)

    # Create array to store the audio plus the clicks
    out_audio = np.zeros(max(len(audio), len(audio_clicks)))

    # Assign the audio and the clicks
    out_audio[:len(audio)] = audio
    out_audio[:len(audio_clicks)] += audio_clicks

    # Write to file
    scipy.io.wavfile.write(out_file, fs, out_audio)
Sonifies the estimated times into the output file.

    Parameters
    ----------
    audio: np.array
        Audio samples of the input track.
    clicks: np.array
        Click positions in seconds.
    out_file: str
        Path to the output file.
    fs: int
        Sample rate.
    offset: float
        Offset of the clicks with respect to the audio.