librosa.output.annotation(path, intervals, annotations=None, delimiter=', ', fmt='%0.3f')[source]

Save annotations in a 3-column format:

intervals[0, 0],intervals[0, 1],annotations[0]\n
intervals[1, 0],intervals[1, 1],annotations[1]\n
intervals[2, 0],intervals[2, 1],annotations[2]\n

This can be used for segment or chord annotations.


path : str

path to save the output CSV file

intervals : np.ndarray [shape=(n, 2)]

array of interval start and end-times.

intervals[i, 0] marks the start time of interval i

intervals[i, 1] marks the end time of interval i

annotations : None or list-like [shape=(n,)]

optional list of annotation strings. annotations[i] applies to the time range intervals[i, 0] to intervals[i, 1]

delimiter : str

character to separate fields

fmt : str

format-string for rendering time data



if annotations is not None and length does not match intervals


>>> y, sr = librosa.load(librosa.util.example_audio_file())
>>> data = librosa.feature.mfcc(y=y, sr=sr, hop_length=512)

Detect segment boundaries

>>> boundaries = librosa.segment.agglomerative(data, k=10)

Convert to time

>>> boundary_times = librosa.frames_to_time(boundaries, sr=sr,
...                                         hop_length=512)

Convert events boundaries to intervals

>>> intervals = np.hstack([boundary_times[:-1, np.newaxis],
...                        boundary_times[1:, np.newaxis]])

Make some fake annotations

>>> labels = ['Seg #{:03d}'.format(i) for i in range(len(intervals))]

Save the output

>>> librosa.output.annotation('segments.csv', intervals,
...                           annotations=labels)