捷徑

頻譜圖

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]

從音訊訊號建立頻譜圖。

This feature supports the following devices: CPU, CUDA This API supports the following properties: Autograd, TorchScript
參數:
  • n_fft (int, optional) – FFT 的大小,會產生 n_fft // 2 + 1 個 bins。(預設值:400

  • win_length (intNone, optional) – 視窗大小。(預設值:n_fft

  • hop_length (intNone, optional) – STFT 視窗之間的 hop 長度。(預設值:win_length // 2

  • pad (int, optional) – 訊號的雙邊填充。(預設值:0

  • window_fn (Callable[..., Tensor], optional) – 一個用來創建視窗 tensor 的函數,該 tensor 會被應用/乘到每個 frame/window 上。(預設值:torch.hann_window

  • power (floatNone, optional) – magnitude spectrogram 的指數 (必須 > 0),例如:1 代表 magnitude,2 代表 power 等。如果為 None,則改為回傳 complex spectrum。(預設值:2

  • normalized (boolstr, optional) – 是否在 stft 後對 magnitude 進行正規化。 如果輸入為 str,則選項為 "window""frame_length",如果需要特定的正規化類型。True 對應到 "window"。(預設值:False

  • wkwargs (dictNone, optional) – 視窗函數的引數。(預設值:None

  • center (bool, optional) – 是否在兩側填充 waveform,以便第 \(t\) 個 frame 位於時間 \(t \times \text{hop\_length}\) 的中心。(預設值:True

  • pad_mode (string, optional) – 控制當 centerTrue 時使用的填充方法。(預設值:"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 的教學課程
Audio Feature Augmentation

音訊特徵擴增

音訊特徵擴增
StreamWriter Basic Usage

StreamWriter 基本用法

StreamWriter 基本用法
Music Source Separation with Hybrid Demucs

使用 Hybrid Demucs 的音樂源分離

使用 Hybrid Demucs 的音樂源分離
Speech Enhancement with MVDR Beamforming

使用 MVDR 波束成形的語音增強

使用 MVDR 波束成形的語音增強
Audio Feature Extractions

音訊特徵提取

音訊特徵提取
forward(waveform: Tensor) Tensor[source]
參數:

waveform (Tensor) – 音訊的 Tensor,維度為 (…, time)。

回傳:

維度為 (…, freq, time),其中 freq 為 n_fft // 2 + 1,其中 n_fft 是 Fourier bins 的數量,而 time 是 window hops 的數量 (n_frame)。

回傳類型:

Tensor

文件

存取 PyTorch 的全面開發者文件

檢視文件

教學

取得針對初學者和進階開發者的深入教學課程

檢視教學課程

資源

尋找開發資源並獲得問題解答

檢視資源