librosa.effects.pitch_shift#
- librosa.effects.pitch_shift(y, *, sr, n_steps, bins_per_octave=12, res_type='soxr_hq', scale=False, n_fft=2048, hop_length=None, win_length=None, window='hann', center=True, pad_mode='constant')[source]#
Shift the pitch of a waveform by
n_stepssteps.A step is equal to a semitone if
bins_per_octaveis set to 12.- Parameters:
- ynp.ndarray [shape=(…, n)]
audio time series. Multi-channel is supported.
- srnumber > 0 [scalar]
audio sampling rate of
y- n_stepsfloat [scalar]
how many (fractional) steps to shift
y- bins_per_octaveint > 0 [scalar]
how many steps per octave
- res_typestr
Resample type. By default, ‘soxr_hq’ is used.
See
librosa.resamplefor more information.- scalebool
Scale the resampled signal so that
yandy_hathave approximately equal total energy.- n_fftint > 0 [scalar]
Length of the windowed signal after padding with zeros. The number of rows in the STFT matrix is
(1 + n_fft/2).- hop_lengthint or None
Number of audio samples between adjacent STFT columns. If unspecified, defaults to
win_length // 4.- win_lengthint or None
Each frame of audio is windowed by
windowof lengthwin_lengthand then padded with zeros to matchn_fft. If unspecified, defaults towin_length = n_fft.- windowstr, tuple, number, function, or np.ndarray [shape=(n_fft,)]
Window specification. See
scipy.signal.get_windowfor supported values.- centerbool
If
True, the signal is padded so that frametis centered aty[t * hop_length].- pad_modestr
Padding mode used when
center=True. Seenumpy.padfor available modes.
- Returns:
- y_shiftnp.ndarray [shape=(…, n)]
The pitch-shifted audio time-series
See also
time_stretchTime stretching
librosa.phase_vocoderSpectrogram phase vocoder
pyrubberband.pyrb.pitch_shiftHigh-quality pitch shifting using RubberBand
Examples
Shift up by a major third (four steps if
bins_per_octaveis 12)>>> y, sr = librosa.loadx('choice') >>> y_third = librosa.effects.pitch_shift(y, sr=sr, n_steps=4)
Shift down by a tritone (six steps if
bins_per_octaveis 12)>>> y_tritone = librosa.effects.pitch_shift(y, sr=sr, n_steps=-6)
Shift up by 3 quarter-tones
>>> y_three_qt = librosa.effects.pitch_shift(y, sr=sr, n_steps=3, ... bins_per_octave=24)