Skip to content

PitchShift

Added in v0.4.0

Pitch shift the sound up or down without changing the tempo.

Under the hood, this performs time stretching (by phase vocoding) followed by resampling. Note that phase vocoding can degrade audio quality by "smearing" transient sounds, altering the timbre of harmonic sounds, and distorting pitch modulations. This may result in a loss of sharpness, clarity, or naturalness in the transformed audio.

If you need a better sounding pitch shifting method, consider the following alternatives:

Input-output example

Here we pitch down a piano recording by 4 semitones:

Input-output waveforms and spectrograms

Input sound Transformed sound

Usage example

from audiomentations import PitchShift

transform = PitchShift(
    min_semitones=-5.0,
    max_semitones=5.0,
    p=1.0
)

augmented_sound = transform(my_waveform_ndarray, sample_rate=44100)

PitchShift API

min_semitones: float • unit: semitones • range: [-12.0, 12.0]
Default: -4.0. Minimum semitones to shift. A negative number means shift down.
max_semitones: float • unit: semitones • range: [-12.0, 12.0]
Default: 4.0. Maximum semitones to shift. A positive number means shift up.
p: float • range: [0.0, 1.0]
Default: 0.5. The probability of applying this transform.

Source code

audiomentations/augmentations/pitch_shift.py