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)