PitchShift
Added in v0.4.0
Pitch shift the sound up or down without changing the tempo.
You can choose between method="signalsmith_stretch" and method="librosa_phase_vocoder". If you need other pitch shifting methods, consider the following alternatives:
Input-output example
Here we pitch down a piano recording by 4 semitones, using the signalsmith_stretch
method:
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: [-24.0, 24.0]- Default:
-4.0
. Minimum semitones to shift. A negative number means shift down. max_semitones
:float
• unit: semitones • range: [-24.0, 24.0]- Default:
4.0
. Maximum semitones to shift. A positive number means shift up. backend
:str
• choices:"librosa_phase_vocoder"
,"signalsmith_stretch"
-
Default:
"signalsmith_stretch"
."signalsmith_stretch"
: Use signalsmith-stretch. Pros: 50-100% faster than librosa_phase_vocoder, and provides significantly higher audio quality. Con: Does not support more than 2 channels (stereo)."librosa_phase_vocoder"
: Use librosa.effects.pitch_shift, which performs time stretching (by phase vocoding) followed by resampling. Pro: Supports any number of channels. Con: phase vocoding can significantly degrade the 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.
p
:float
• range: [0.0, 1.0]- Default:
0.5
. The probability of applying this transform.