- 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)¶
Compute the spectral centroid for each channel along the time axis.
The spectral centroid is defined as the weighted average of the frequency values, weighted by their magnitude.
sample_rate (int) – Sample rate of audio signal.
n_fft (int, optional) – Size of FFT, creates
n_fft // 2 + 1bins. (Default:
win_length (int or None, optional) – Window size. (Default:
hop_length (int or None, optional) – Length of hop between STFT windows. (Default:
win_length // 2)
pad (int, optional) – Two sided padding of signal. (Default:
window_fn (Callable[..., Tensor], optional) – A function to create a window tensor that is applied/multiplied to each frame/window. (Default:
wkwargs (dict or None, optional) – Arguments for window function. (Default:
>>> waveform, sample_rate = torchaudio.load("test.wav", normalize=True) >>> transform = transforms.SpectralCentroid(sample_rate) >>> spectral_centroid = transform(waveform) # (channel, time)