librosa.phase_vocoder

librosa.phase_vocoder(D, *, rate, hop_length=None, n_fft=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

n_fftint > 0 or None

The number of samples per frame in D. By default (None), this will be inferred from the shape of D. However, if D was constructed using an odd-length window, the correct frame length can be specified here.

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, rate=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, rate=1./3, hop_length=512)
>>> y_slow  = librosa.istft(D_slow, hop_length=512)