librosa.effects.remix

librosa.effects.remix(y, intervals, align_zeros=True)[source]

Remix an audio signal by re-ordering time intervals.

Parameters:
y : np.ndarray [shape=(t,) or (2, t)]

Audio time series

intervals : iterable of tuples (start, end)

An iterable (list-like or generator) where the i`th item `intervals[i] indicates the start and end (in samples) of a slice of y.

align_zeros : boolean

If True, interval boundaries are mapped to the closest zero-crossing in y. If y is stereo, zero-crossings are computed after converting to mono.

Returns:
y_remix : np.ndarray [shape=(d,) or (2, d)]

y remixed in the order specified by intervals

Examples

Load in the example track and reverse the beats

>>> y, sr = librosa.load(librosa.util.example_audio_file())

Compute beats

>>> _, beat_frames = librosa.beat.beat_track(y=y, sr=sr,
...                                          hop_length=512)

Convert from frames to sample indices

>>> beat_samples = librosa.frames_to_samples(beat_frames)

Generate intervals from consecutive events

>>> intervals = librosa.util.frame(beat_samples, frame_length=2,
...                                hop_length=1).T

Reverse the beat intervals

>>> y_out = librosa.effects.remix(y, intervals[::-1])