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.output.annotation¶
- 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.
Warning
This function is deprecated in librosa 0.7.0. It will be removed in 0.8.
- Parameters
- pathstr
path to save the output CSV file
- intervalsnp.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
- annotationsNone or list-like [shape=(n,)]
optional list of annotation strings. annotations[i] applies to the time range intervals[i, 0] to intervals[i, 1]
- delimiterstr
character to separate fields
- fmtstr
format-string for rendering time data
- Raises
- ParameterError
if annotations is not None and length does not match intervals
Examples
>>> 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)