librosa.effects.pitch_shift

librosa.effects.pitch_shift(y, sr, n_steps, bins_per_octave=12)[source]

Pitch-shift the waveform by n_steps half-steps.

Parameters:
y : np.ndarray [shape=(n,)]

audio time-series

sr : number > 0 [scalar]

audio sampling rate of y

n_steps : float [scalar]

how many (fractional) half-steps to shift y

bins_per_octave : float > 0 [scalar]

how many steps per octave

Returns:
y_shift : np.ndarray [shape=(n,)]

The pitch-shifted audio time-series

See also

time_stretch
time stretching
librosa.core.phase_vocoder
spectrogram phase vocoder

Examples

Shift up by a major third (four half-steps)

>>> y, sr = librosa.load(librosa.util.example_audio_file())
>>> y_third = librosa.effects.pitch_shift(y, sr, n_steps=4)

Shift down by a tritone (six half-steps)

>>> y_tritone = librosa.effects.pitch_shift(y, sr, n_steps=-6)

Shift up by 3 quarter-tones

>>> y_three_qt = librosa.effects.pitch_shift(y, sr, n_steps=3,
...                                          bins_per_octave=24)