捷徑

MelSpectrogram

class torchaudio.transforms.MelSpectrogram(sample_rate: int = 16000, n_fft: int = 400, win_length: ~typing.Optional[int] = None, hop_length: ~typing.Optional[int] = None, f_min: float = 0.0, f_max: ~typing.Optional[float] = None, pad: int = 0, n_mels: int = 128, 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', onesided: ~typing.Optional[bool] = None, norm: ~typing.Optional[str] = None, mel_scale: str = 'htk')[source]

為原始音訊訊號建立 MelSpectrogram。

This feature supports the following devices: CPU, CUDA This API supports the following properties: Autograd, TorchScript

這是 torchaudio.transforms.Spectrogram()torchaudio.transforms.MelScale() 的組合。

來源
參數:
  • sample_rate (int, optional) – 音訊訊號的取樣率。(預設值: 16000)

  • n_fft (int, optional) – FFT 的大小,建立 n_fft // 2 + 1 個 bin。(預設值: 400)

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

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

  • f_min (float, optional) – 最小頻率。(預設值: 0.)

  • f_max (floatNone, optional) – 最大頻率。(預設值: None)

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

  • n_mels (int, optional) – Mel 濾波器的數量。(預設值: 128)

  • window_fn (Callable[..., 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) – 控制當 centerTrue 時使用的填充方法。(預設值: "reflect")

  • onesided – 已棄用且未使用。

  • norm (strNone, optional) – 如果為 “slaney”,則將三角形 mel 權重除以 mel 頻帶的寬度 (面積歸一化)。(預設值: None)

  • mel_scale (str, optional) – 要使用的比例: htkslaney。(預設值: htk)

範例
>>> waveform, sample_rate = torchaudio.load("test.wav", normalize=True)
>>> transform = transforms.MelSpectrogram(sample_rate)
>>> mel_specgram = transform(waveform)  # (channel, n_mels, time)

另請參閱

torchaudio.functional.melscale_fbanks() - 用於生成濾波器組的函數。

使用 MelSpectrogram 的教學課程
Audio Feature Extractions

音訊特徵提取

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

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

回傳:

大小為 (…, n_mels, time) 的梅爾頻譜圖。

回傳類型:

Tensor

文件

存取 PyTorch 的完整開發者文件

檢視文件

教學

取得初學者和進階開發者的深度教學

檢視教學

資源

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

檢視資源