Caution

You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.10.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 steps.

A step is equal to a semitone if bins_per_octave is set to 12.

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

audio time series

srnumber > 0 [scalar]

audio sampling rate of y

n_stepsfloat [scalar]

how many (fractional) steps to shift y

bins_per_octavefloat > 0 [scalar]

how many steps per octave

res_typestring

Resample type. By default, ‘kaiser_best’ is used.

See librosa.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.phase_vocoder

spectrogram phase vocoder

pyrubberband.pyrb.pitch_shift

high-quality pitch shifting using RubberBand

Examples

Shift up by a major third (four steps if bins_per_octave is 12)

>>> y, sr = librosa.load(librosa.ex('choice'))
>>> y_third = librosa.effects.pitch_shift(y, sr, n_steps=4)

Shift down by a tritone (six steps if bins_per_octave is 12)

>>> 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)