SpectralCentroid¶
- class torchaudio.transforms.SpectralCentroid(sample_rate: int, 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>, wkwargs: ~typing.Optional[dict] = None)[source]¶
计算每个通道沿时间轴的谱质心。
谱质心定义为频率值的加权平均值,权重为其幅度。
- 参数:
sample_rate (int) – 音频信号的采样率。
n_fft (int, optional) – FFT 大小,创建
n_fft // 2 + 1
个频 bins。(默认值:400
)win_length (int 或 None, optional) – 窗口大小。(默认值:
n_fft
)hop_length (int 或 None, optional) – STFT 窗口之间的跳跃长度。(默认值:
win_length // 2
)pad (int, optional) – 信号的双边填充。(默认值:
0
)window_fn (Callable[..., Tensor], optional) – 用于创建窗口张量的函数,该张量应用于/乘以每个帧/窗口。(默认值:
torch.hann_window
)wkwargs (dict 或 None, optional) – 窗口函数的参数。(默认值:
None
)
- 示例
>>> waveform, sample_rate = torchaudio.load("test.wav", normalize=True) >>> transform = transforms.SpectralCentroid(sample_rate) >>> spectral_centroid = transform(waveform) # (channel, time)