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.effects.time_stretch

librosa.effects.time_stretch(y, *, rate, **kwargs)[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. If rate < 1, then the signal is slowed down.

**kwargsadditional keyword arguments.

See librosa.decompose.stft for details.

Returns
y_stretchnp.ndarray [shape=(…, round(n/rate))]

audio time series stretched by the specified rate

See also

pitch_shift

pitch shifting

librosa.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.ex('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)