Caution

You're reading the documentation for a development version. For the latest released version, please have a look at 0.10.2.

librosa.effects.pitch_shift

librosa.effects.pitch_shift(y, *, sr, n_steps, bins_per_octave=12, res_type='soxr_hq', scale=False, **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. 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_typestring

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

See librosa.resample for more information.

scalebool

Scale the resampled signal so that y and y_hat have approximately equal total energy.

**kwargsadditional 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=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=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)