频谱图¶
- class torchaudio.transforms.Spectrogram(n_fft: int = 400, win_length: ~typing.Optional[int] = None, hop_length: ~typing.Optional[int] = None, pad: int = 0, window_fn: ~typing.Callable[[...], ~torch.Tensor] = <built-in method hann_window of type object>, power: ~typing.Optional[float] = 2.0, normalized: ~typing.Union[bool, str] = False, wkwargs: ~typing.Optional[dict] = None, center: bool = True, pad_mode: str = 'reflect', onesided: bool = True, return_complex: ~typing.Optional[bool] = None)[source]¶
从音频信号创建频谱图。
- 参数:
n_fft (int, 可选) – FFT 大小,创建
n_fft // 2 + 1
个 bin。(默认值:400
)win_length (int 或 None, 可选) – 窗口大小。(默认值:
n_fft
)hop_length (int 或 None, 可选) – STFT 窗口之间的跳跃长度。(默认值:
win_length // 2
)pad (int, 可选) – 信号的两侧填充。(默认值:
0
)window_fn (Callable[..., Tensor], 可选) – 一个用于创建窗口张量并应用于/乘以每个帧/窗口的函数。(默认值:
torch.hann_window
)power (float 或 None, 可选) – 幅度频谱的指数(必须 > 0),例如 1 表示幅度,2 表示功率等。如果为 None,则返回复数频谱。(默认值:
2
)normalized (bool 或 str, 可选) – 是否在 STFT 后按幅度归一化。如果输入是 str,选项为
"window"
和"frame_length"
,如果需要特定类型的归一化。True
对应于"window"
。(默认值:False
)wkwargs (dict 或 None, 可选) – 窗口函数的参数。(默认值:
None
)center (bool, 可选) – 是否在
waveform
的两侧填充,使得第 \(t\) 帧中心位于时间 \(t \times \text{hop\_length}\)。(默认值:True
)pad_mode (string, 可选) – 控制当
center
为True
时使用的填充方法。(默认值:"reflect"
)onesided (bool, 可选) – 控制是否返回一半结果以避免冗余(默认值:
True
)return_complex (bool, 可选) – 已弃用且未使用。
- 示例
>>> waveform, sample_rate = torchaudio.load("test.wav", normalize=True) >>> transform = torchaudio.transforms.Spectrogram(n_fft=800) >>> spectrogram = transform(waveform)
- 使用
Spectrogram
的教程