頻譜質心¶
- 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)[原始碼]¶
計算沿時間軸的每個通道的頻譜質心。
頻譜質心定義為頻率值的加權平均值,權重為其幅度。
- 參數:
sample_rate (int) – 音訊訊號的取樣率。
n_fft (int, 選用) – FFT 大小,建立
n_fft // 2 + 1
個頻率箱。(預設值: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
)wkwargs (dict 或 None, 選用) – 視窗函數的引數。(預設值:
None
)
- 範例
>>> waveform, sample_rate = torchaudio.load("test.wav", normalize=True) >>> transform = transforms.SpectralCentroid(sample_rate) >>> spectral_centroid = transform(waveform) # (channel, time)