class torchaudio.transforms.GriffinLim(n_fft: int = 400, n_iter: int = 32, win_length: ~typing.Optional[int] = None, hop_length: ~typing.Optional[int] = None, window_fn: ~typing.Callable[[...], ~torch.Tensor] = <built-in method hann_window of type object>, power: float = 2.0, wkwargs: ~typing.Optional[dict] = None, momentum: float = 0.99, length: ~typing.Optional[int] = None, rand_init: bool = True)[source]

Compute waveform from a linear scale magnitude spectrogram using the Griffin-Lim transformation.

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

Implementation ported from librosa [Brian McFee et al., 2015], A fast Griffin-Lim algorithm [Perraudin et al., 2013] and Signal estimation from modified short-time Fourier transform [Griffin and Lim, 1983].

  • n_fft (int, optional) – Size of FFT, creates n_fft // 2 + 1 bins. (Default: 400)

  • n_iter (int, optional) – Number of iteration for phase recovery process. (Default: 32)

  • win_length (int or None, optional) – Window size. (Default: n_fft)

  • hop_length (int or None, optional) – Length of hop between STFT windows. (Default: win_length // 2)

  • window_fn (Callable[..., Tensor], optional) – A function to create a window tensor that is applied/multiplied to each frame/window. (Default: torch.hann_window)

  • power (float, optional) – Exponent for the magnitude spectrogram, (must be > 0) e.g., 1 for magnitude, 2 for power, etc. (Default: 2)

  • wkwargs (dict or None, optional) – Arguments for window function. (Default: None)

  • momentum (float, optional) – The momentum parameter for fast Griffin-Lim. Setting this to 0 recovers the original Griffin-Lim method. Values near 1 can lead to faster convergence, but above 1 may not converge. (Default: 0.99)

  • length (int, optional) – Array length of the expected output. (Default: None)

  • rand_init (bool, optional) – Initializes phase randomly if True and to zero otherwise. (Default: True)

>>> batch, freq, time = 2, 257, 100
>>> spectrogram = torch.randn(batch, freq, time)
>>> transform = transforms.GriffinLim(n_fft=512)
>>> waveform = transform(spectrogram)
Tutorials using GriffinLim:
Text-to-Speech with Tacotron2

Text-to-Speech with Tacotron2

Text-to-Speech with Tacotron2
Audio Feature Extractions

Audio Feature Extractions

Audio Feature Extractions
forward(specgram: Tensor) Tensor[source]

specgram (Tensor) – A magnitude-only STFT spectrogram of dimension (…, freq, frames) where freq is n_fft // 2 + 1.


waveform of (…, time), where time equals the length parameter if given.

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