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

Estimate a STFT in normal frequency domain from mel frequency domain.

This feature supports the following devices: CPU, CUDA

It minimizes the euclidian norm between the input mel-spectrogram and the product between the estimated spectrogram and the filter banks using torch.linalg.lstsq.

  • n_stft (int) – Number of bins in STFT. See n_fft in Spectrogram.

  • 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)

  • 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)

  • driver (str, optional) – Name of the LAPACK/MAGMA method to be used for torch.lstsq. For CPU inputs the valid values are "gels", "gelsy", "gelsd", "gelss". For CUDA input, the only valid driver is "gels", which assumes that A is full-rank. (Default: "gels)

>>> waveform, sample_rate = torchaudio.load("test.wav", normalize=True)
>>> mel_spectrogram_transform = transforms.MelSpectrogram(sample_rate, n_fft=1024)
>>> mel_spectrogram = mel_spectrogram_transform(waveform)
>>> inverse_melscale_transform = transforms.InverseMelScale(n_stft=1024 // 2 + 1)
>>> spectrogram = inverse_melscale_transform(mel_spectrogram)
forward(melspec: Tensor) Tensor[source]

melspec (Tensor) – A Mel frequency spectrogram of dimension (…, n_mels, time)


Linear scale spectrogram of size (…, freq, 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