Caution

You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.10.2.

librosa.phase_vocoder

librosa.phase_vocoder(D, rate, hop_length=None)[source]

Phase vocoder. Given an STFT matrix D, speed up by a factor of rate

Based on the implementation provided by [1].

This is a simplified implementation, intended primarily for reference and pedagogical purposes. It makes no attempt to handle transients, and is likely to produce many audible artifacts. For a higher quality implementation, we recommend the RubberBand library [2] and its Python wrapper pyrubberband.

Parameters:
Dnp.ndarray [shape=(d, t), dtype=complex]

STFT matrix

ratefloat > 0 [scalar]

Speed-up factor: rate > 1 is faster, rate < 1 is slower.

hop_lengthint > 0 [scalar] or None

The number of samples between successive columns of D.

If None, defaults to n_fft//4 = (D.shape[0]-1)//2

Returns:
D_stretchednp.ndarray [shape=(d, t / rate), dtype=complex]

time-stretched STFT

See also

pyrubberband

Examples

>>> # Play at double speed
>>> y, sr   = librosa.load(librosa.ex('trumpet'))
>>> D       = librosa.stft(y, n_fft=2048, hop_length=512)
>>> D_fast  = librosa.phase_vocoder(D, 2.0, hop_length=512)
>>> y_fast  = librosa.istft(D_fast, hop_length=512)
>>> # Or play at 1/3 speed
>>> y, sr   = librosa.load(librosa.ex('trumpet'))
>>> D       = librosa.stft(y, n_fft=2048, hop_length=512)
>>> D_slow  = librosa.phase_vocoder(D, 1./3, hop_length=512)
>>> y_slow  = librosa.istft(D_slow, hop_length=512)