librosa.effects.time_stretch

librosa.effects.time_stretch(y, rate, **kwargs)[source]

Time-stretch an audio series by a fixed rate.

Parameters:
y : np.ndarray [shape=(n,)]

audio time series

rate : float > 0 [scalar]

Stretch factor. If rate > 1, then the signal is sped up. If rate < 1, then the signal is slowed down.

kwargs : additional keyword arguments.

See librosa.decompose.stft for details.

Returns:
y_stretch : np.ndarray [shape=(round(n/rate),)]

audio time series stretched by the specified rate

See also

pitch_shift
pitch shifting
librosa.core.phase_vocoder
spectrogram phase vocoder
pyrubberband.pyrb.time_stretch
high-quality time stretching using RubberBand

Examples

Compress to be twice as fast

>>> y, sr = librosa.load(librosa.util.example_audio_file())
>>> y_fast = librosa.effects.time_stretch(y, 2.0)

Or half the original speed

>>> y_slow = librosa.effects.time_stretch(y, 0.5)