ChromaSpectrogram¶
- class torchaudio.prototype.transforms.ChromaSpectrogram(sample_rate: int, n_fft: int, *, 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: float = 2.0, normalized: bool = False, wkwargs: ~typing.Optional[dict] = None, center: bool = True, pad_mode: str = 'reflect', n_chroma: int = 12, tuning: float = 0.0, ctroct: float = 5.0, octwidth: ~typing.Optional[float] = 2.0, norm: int = 2, base_c: bool = True)[source]¶
为音频信号生成色度图。
组合了
torchaudio.transforms.Spectrogram()
和torchaudio.prototype.transforms.ChromaScale()
。- 参数:
sample_rate (int) – 音频信号的采样率。
n_fft (int, optional) – FFT 大小,创建
n_fft // 2 + 1
个 bin。win_length (int 或 None, optional) – 窗口大小。(默认值:
n_fft
)hop_length (int 或 None, optional) – STFT 窗口之间的跳跃长度。(默认值:
win_length // 2
)pad (int, optional) – 信号的两侧填充。(默认值:
0
)window_fn (Callable[..., torch.Tensor], optional) – 用于创建窗口张量并将其应用于/乘以每个帧/窗口的函数。(默认值:
torch.hann_window
)power (float, optional) – 幅度谱的指数(必须 > 0),例如,1 表示能量,2 表示功率等。(默认值:
2
)normalized (bool, optional) – 是否在 STFT 后按幅度进行归一化。(默认值:
False
)wkwargs (Dict[..., ...] 或 None, optional) – 窗口函数的参数。(默认值:
None
)center (bool, optional) – 是否在
waveform
的两侧进行填充,以便第 \(t\) 帧以时间 \(t \times \text{hop\_length}\) 为中心。(默认值:True
)pad_mode (string, optional) – 控制当
center
为True
时使用的填充方法。(默认值:"reflect"
)n_chroma (int, optional) – 色度数量。(默认值:
12
)tuning (float, optional) – A440 的调音偏差,以色度 bin 的分数表示。(默认值: 0.0)
ctroct (float, optional) – 高斯优势窗口的中心,用于按八度对滤波器进行加权。(默认值: 5.0)
octwidth (float 或 None, optional) – 高斯优势窗口的宽度,用于按八度对滤波器进行加权。如果为
None
,则完全禁用加权。(默认值: 2.0)norm (int, optional) – 用于归一化滤波器组的范数阶数。(默认值: 2)
base_c (bool, optional) – 如果为 True,则从 C 开始滤波器组。否则,从 A 开始。(默认值: True)
- 示例
>>> waveform, sample_rate = torchaudio.load("test.wav", normalize=True) >>> transform = transforms.ChromaSpectrogram(sample_rate=sample_rate, n_fft=400) >>> chromagram = transform(waveform) # (channel, n_chroma, time)