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)[原始碼]¶
將波形的音調移動
n_steps
步。- 參數:
waveform (Tensor) – 形狀為 (…, time) 的輸入波形。
sample_rate (int) – waveform 的取樣率。
n_steps (int) – 移動 waveform 的 (分數) 步數。
bins_per_octave (int, optional) – 每個八度的步數 (預設:
12
)。n_fft (int, optional) – FFT 大小,建立
n_fft // 2 + 1
個頻率箱 (預設:512
)。win_length (int 或 None, optional) – 視窗大小。如果為 None,則使用
n_fft
。(預設:None
)。hop_length (int 或 None, optional) – STFT 視窗之間的跳躍長度。如果為 None,則使用
win_length // 4
(預設:None
)。window (Tensor 或 None, optional) – 套用/乘到每個影格/視窗的視窗張量。如果為 None,則使用
torch.hann_window(win_length)
(預設:None
)。
- 範例
>>> waveform, sample_rate = torchaudio.load("test.wav", normalize=True) >>> transform = transforms.PitchShift(sample_rate, 4) >>> waveform_shift = transform(waveform) # (channel, time)