Caution

You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.9.1.

librosa.effects.pitch_shift

librosa.effects.pitch_shift(y, sr, n_steps, bins_per_octave=12, res_type='kaiser_best', **kwargs)[source]

Shift the pitch of a waveform by n_steps semitones.

Parameters
ynp.ndarray [shape=(n,)]

audio time series

srnumber > 0 [scalar]

audio sampling rate of y

n_stepsfloat [scalar]

how many (fractional) half-steps to shift y

bins_per_octavefloat > 0 [scalar]

how many steps per octave

res_typestring

Resample type. Possible options: ‘kaiser_best’, ‘kaiser_fast’, and ‘scipy’, ‘polyphase’, ‘fft’. By default, ‘kaiser_best’ is used.

See core.resample for more information.

kwargs: additional keyword arguments.

See librosa.decompose.stft for details.

Returns
y_shiftnp.ndarray [shape=(n,)]

The pitch-shifted audio time-series

See also

time_stretch

time stretching

librosa.core.phase_vocoder

spectrogram phase vocoder

pyrubberband.pyrb.pitch_shift

high-quality pitch shifting using RubberBand

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)