頻譜圖¶
- class torchaudio.transforms.Spectrogram(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>, power: ~typing.Optional[float] = 2.0, normalized: ~typing.Union[bool, str] = False, wkwargs: ~typing.Optional[dict] = None, center: bool = True, pad_mode: str = 'reflect', onesided: bool = True, return_complex: ~typing.Optional[bool] = None)[source]¶
從音訊訊號建立頻譜圖。
- 參數:
n_fft (int, optional) – FFT 的大小,會產生
n_fft // 2 + 1
個 bins。(預設值:400
)win_length (int 或 None, optional) – 視窗大小。(預設值:
n_fft
)hop_length (int 或 None, optional) – STFT 視窗之間的 hop 長度。(預設值:
win_length // 2
)pad (int, optional) – 訊號的雙邊填充。(預設值:
0
)window_fn (Callable[..., Tensor], optional) – 一個用來創建視窗 tensor 的函數,該 tensor 會被應用/乘到每個 frame/window 上。(預設值:
torch.hann_window
)power (float 或 None, optional) – magnitude spectrogram 的指數 (必須 > 0),例如:1 代表 magnitude,2 代表 power 等。如果為 None,則改為回傳 complex spectrum。(預設值:
2
)normalized (bool 或 str, optional) – 是否在 stft 後對 magnitude 進行正規化。 如果輸入為 str,則選項為
"window"
和"frame_length"
,如果需要特定的正規化類型。True
對應到"window"
。(預設值:False
)wkwargs (dict 或 None, optional) – 視窗函數的引數。(預設值:
None
)center (bool, optional) – 是否在兩側填充
waveform
,以便第 \(t\) 個 frame 位於時間 \(t \times \text{hop\_length}\) 的中心。(預設值:True
)pad_mode (string, optional) – 控制當
center
為True
時使用的填充方法。(預設值:"reflect"
)onesided (bool, optional) – 控制是否回傳一半的結果以避免冗餘(預設值:
True
)return_complex (bool, optional) – 已棄用且未使用。
- 範例
>>> waveform, sample_rate = torchaudio.load("test.wav", normalize=True) >>> transform = torchaudio.transforms.Spectrogram(n_fft=800) >>> spectrogram = transform(waveform)
- 使用
Spectrogram
的教學課程