#2107·librosa

time_stretch/pitch_shift crash on documented STFT kwargs (pad_mode, dtype)

Author: godking123Created Sep 26, 2026Updated Sep 28, 2026
LabelsbugAPI change

Summary

time_stretch/pitch_shift accept **kwargs that their docstrings say are STFT parameters, but those kwargs get forwarded verbatim to both stft and istft. Since stft and istft don't accept the same set of parameters, valid calls to this function result in errors and crashes.

Reproduction

python
import numpy as np, librosa
y = np.random.default_rng(0).standard_normal(22050).astype(np.float32)
librosa.effects.time_stretch(y, rate=1.5, pad_mode='constant')
/.../librosa/effects.py:448: FutureWarning: The hop_length parameter is deprecated as of 1.0 and will be removed in 1.1. It is unused in the current implementation.
  stft_stretch = core.phase_vocoder(
/.../librosa/effects.py:448: FutureWarning: The n_fft parameter is deprecated as of 1.0 and will be removed in 1.1. It is unused in the current implementation.
  stft_stretch = core.phase_vocoder(
Traceback (most recent call last):
  File "...", line 4, in <module>
    librosa.effects.time_stretch(y, rate=1.5, pad_mode='constant')
  File ".../librosa/effects.py", line 459, in time_stretch
    y_stretch = core.istft(stft_stretch, dtype=y.dtype, length=len_stretch, **kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: istft() got an unexpected keyword argument 'pad_mode'

Two bugs here:

pad_mode works fine on stft but istft has no such parameter, so forwarding the whole kwargs dict to both breaks on that line. Same thing with dtype.

The warnings are the other bug. Even a plain time_stretch(y, rate=1.5) prints both deprecation warnings, because kwargs.get("hop_length")/kwargs.get("n_fft") return None when unset, and phase_vocoder can't tell that None apart from a real user-supplied value.

Solution

Swap **kwargs for explicit params (n_fft, hop_length, win_length, window, center, pad_mode) and route each to whichever of stft/istft actually takes it. For the second bug I can either only forward hop_length/n_fft to phase_vocoder when the caller actually set them, or completely ignore them in the function call phase_vocoder. The latter would be more future proof as those parameters will soon be deprecated.

Happy to open a PR if this if the solution looks right!