librosa.effects.time_stretch

librosa.effects.time_stretch(y, rate)[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.

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

audio time series stretched by the specified rate

See also

pitch_shift
pitch shifting
librosa.core.phase_vocoder
spectrogram phase vocoder

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)