class torchaudio.transforms.MelScale(n_mels: int = 128, sample_rate: int = 16000, f_min: float = 0.0, f_max: Optional[float] = None, n_stft: int = 201, norm: Optional[str] = None, mel_scale: str = 'htk')[source]

Turn a normal STFT into a mel frequency STFT with triangular filter banks.

This feature supports the following devices: CPU, CUDA This API supports the following properties: Autograd, TorchScript
  • n_mels (int, optional) – Number of mel filterbanks. (Default: 128)

  • sample_rate (int, optional) – Sample rate of audio signal. (Default: 16000)

  • f_min (float, optional) – Minimum frequency. (Default: 0.)

  • f_max (float or None, optional) – Maximum frequency. (Default: sample_rate // 2)

  • n_stft (int, optional) – Number of bins in STFT. See n_fft in Spectrogram. (Default: 201)

  • norm (str or None, optional) – If "slaney", divide the triangular mel weights by the width of the mel band (area normalization). (Default: None)

  • mel_scale (str, optional) – Scale to use: htk or slaney. (Default: htk)

>>> waveform, sample_rate = torchaudio.load("test.wav", normalize=True)
>>> spectrogram_transform = transforms.Spectrogram(n_fft=1024)
>>> spectrogram = spectrogram_transform(waveform)
>>> melscale_transform = transforms.MelScale(sample_rate=sample_rate, n_stft=1024 // 2 + 1)
>>> melscale_spectrogram = melscale_transform(spectrogram)

See also

torchaudio.functional.melscale_fbanks() - The function used to generate the filter banks.

forward(specgram: Tensor) Tensor[source]

specgram (Tensor) – A spectrogram STFT of dimension (…, freq, time).


Mel frequency spectrogram of size (…, n_mels, time).

Return type:



Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources