librosa.effects.time_stretch#
- librosa.effects.time_stretch(y, *, rate, n_fft=2048, hop_length=None, win_length=None, window='hann', center=True, pad_mode='constant')[source]#
Time-stretch an audio series by a fixed rate.
- Parameters:
- ynp.ndarray [shape=(…, n)]
audio time series. Multi-channel is supported.
- ratefloat > 0 [scalar]
Stretch factor. If
rate > 1, then the signal is sped up. Ifrate < 1, then the signal is slowed down.- n_fftint > 0 [scalar]
Length of the windowed signal after padding with zeros. The number of rows in the STFT matrix is
(1 + n_fft/2).- hop_lengthint or None
Number of audio samples between adjacent STFT columns. If unspecified, defaults to
win_length // 4.- win_lengthint or None
Each frame of audio is windowed by
windowof lengthwin_lengthand then padded with zeros to matchn_fft. If unspecified, defaults towin_length = n_fft.- windowstr, tuple, number, function, or np.ndarray [shape=(n_fft,)]
Window specification. See
scipy.signal.get_windowfor supported values.- centerbool
If
True, the signal is padded so that frametis centered aty[t * hop_length].- pad_modestr
Padding mode used when
center=True. Seenumpy.padfor available modes.
- Returns:
- y_stretchnp.ndarray [shape=(…, round(n/rate))]
audio time series stretched by the specified rate
See also
pitch_shiftPitch shifting
librosa.phase_vocoderSpectrogram phase vocoder
pyrubberband.pyrb.time_stretchHigh-quality time stretching using RubberBand
Examples
Compress to be twice as fast
>>> y, sr = librosa.loadx('choice') >>> y_fast = librosa.effects.time_stretch(y, rate=2.0)
Or half the original speed
>>> y_slow = librosa.effects.time_stretch(y, rate=0.5)