librosa.core.phase_vocoder

librosa.core.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].

[1]Ellis, D. P. W. “A phase vocoder in Matlab.” Columbia University, 2002. http://www.ee.columbia.edu/~dpwe/resources/matlab/pvoc/
Parameters:
D : np.ndarray [shape=(d, t), dtype=complex]

STFT matrix

rate : float > 0 [scalar]

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

hop_length : int > 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_stretched : np.ndarray [shape=(d, t / rate), dtype=complex]

time-stretched STFT

Examples

>>> # Play at double speed
>>> y, sr   = librosa.load(librosa.util.example_audio_file())
>>> 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.util.example_audio_file())
>>> 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)