Caution
You're reading the documentation for a development version. For the latest released version, please have a look at 0.11.0.
librosa.phase_vocoder
- librosa.phase_vocoder(D, *, rate=None, t_out=None, kind='linear', hop_length=<DEPRECATED parameter>, n_fft=<DEPRECATED parameter>)[source]
Phase vocoder. Given an STFT matrix D, speed up by a factor of
rateBased 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=(…, n_bins, n_frames), dtype=complex]
STFT matrix
- ratefloat > 0 [scalar]
Speed-up factor:
rate > 1is faster,rate < 1is slower. Use this for constant-rate time-stretching.- t_outnp.ndarray [shape=(n_output,)], optional
Optional array of fractional input frame indices specifying the input time corresponding to each output frame. Values must lie in [0, n_frames). This can be used for variable-rate time-stretching. If given, rate must be None.
- kindstr
Interpolation kind for magnitude interpolation, e.g., ‘linear’ or ‘nearest’. See
scipy.interpolate.interp1dfor a full list of supported options.- hop_lengthint > 0 [scalar] or None
The number of samples between successive columns of
D.If None, defaults to
n_fft//4 = (D.shape[-2]-1)//2Warning
This parameter is deprecated as of 1.0 and will be removed in 1.1. It is unused in the current implementation.
- 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.
Warning
This parameter is deprecated as of 1.0 and will be removed in 1.1. It is unused in the current implementation.
- Returns:
- D_stretchednp.ndarray [shape=(…, n_bins, t / rate), dtype=complex]
time-stretched STFT. For variable-rate stretching, the output will have len(t_out) frames.
See also
Examples
>>> # Play at double speed >>> y, sr = librosa.loadx('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.loadx('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)