快捷方式

梅爾譜圖

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 (整型, 可選) – 音訊訊號的取樣率。(預設值: 16000)

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

  • win_length (整型None, 可選) – 視窗大小。(預設值: n_fft)

  • hop_length (整型None, 可選) – STFT 視窗之間的跳躍長度。(預設值: win_length // 2)

  • f_min (浮點型, 可選) – 最小頻率。(預設值: 0.)

  • f_max (浮點型None, 可選) – 最大頻率。(預設值: None)

  • pad (整型, 可選) – 訊號的兩側填充。(預設值: 0)

  • n_mels (整型, 可選) – 梅爾濾波器組的數量。(預設值: 128)

  • window_fn (可呼叫物件[..., 張量], 可選) – 用於建立視窗張量的函式,該張量將應用於/乘以每個幀/視窗。(預設值: torch.hann_window)

  • power (浮點型, 可選) – 幅度譜的指數(必須 > 0),例如,1 表示幅度,2 表示功率等。(預設值: 2)

  • normalized (布林型, 可選) – 是否在 STFT 後按幅度歸一化。(預設值: False)

  • wkwargs (Dict[..., ...] 或 None, 可選) – 視窗函式的引數。(預設值: None)

  • center (布林型, 可選) – 是否在 waveform 兩側填充,以便第 \(t\) 個幀居中於時間 \(t \times \text{hop\_length}\)。(預設值: True)

  • pad_mode (字串, 可選) – 控制當 centerTrue 時使用的填充方法。(預設值: "reflect")

  • onesided – 已棄用且未使用。

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

  • mel_scale (字串, 可選) – 要使用的標度: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[source]
引數:

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

返回值:

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

返回型別:

張量

文件

檢視 PyTorch 的完整開發者文件

檢視文件

教程

獲取針對初學者和高階開發者的深入教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源