PitchShiftΒΆ
- class torchaudio.transforms.PitchShift(sample_rate: int, n_steps: int, bins_per_octave: int = 12, n_fft: int = 512, win_length: ~typing.Optional[int] = None, hop_length: ~typing.Optional[int] = None, window_fn: ~typing.Callable[[...], ~torch.Tensor] = <built-in method hann_window of type object>, wkwargs: ~typing.Optional[dict] = None)[source]ΒΆ
Shift the pitch of a waveform by
n_steps
steps.- Parameters
waveform (Tensor) β The input waveform of shape (β¦, time).
sample_rate (int) β Sample rate of waveform.
n_steps (int) β The (fractional) steps to shift waveform.
bins_per_octave (int, optional) β The number of steps per octave (Default :
12
).n_fft (int, optional) β Size of FFT, creates
n_fft // 2 + 1
bins (Default:512
).win_length (int or None, optional) β Window size. If None, then
n_fft
is used. (Default:None
).hop_length (int or None, optional) β Length of hop between STFT windows. If None, then
win_length // 4
is used (Default:None
).window (Tensor or None, optional) β Window tensor that is applied/multiplied to each frame/window. If None, then
torch.hann_window(win_length)
is used (Default:None
).
- Example
>>> waveform, sample_rate = torchaudio.load("test.wav", normalize=True) >>> transform = transforms.PitchShift(sample_rate, 4) >>> waveform_shift = transform(waveform) # (channel, time)