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]¶
将波形音高移动
n_steps
步。- 参数:
waveform (Tensor) – 输入波形,形状为 (…, time)。
sample_rate (int) – 波形的采样率 waveform。
n_steps (int) – 移动波形 waveform 的(分数)步数。
bins_per_octave (int, 可选) – 每倍频程的步数(默认值:
12
)。n_fft (int, 可选) – FFT 大小,创建
n_fft // 2 + 1
个 bin(默认值:512
)。win_length (int 或 None, 可选) – 窗口大小。如果为 None,则使用
n_fft
。(默认值:None
)。hop_length (int 或 None, 可选) – STFT 窗口之间的跳跃长度。如果为 None,则使用
win_length // 4
(默认值:None
)。window (Tensor 或 None, 可选) – 应用/乘以每个帧/窗口的窗口张量。如果为 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)