GriffinLim¶
- 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.
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].
- Parameters:
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 energy, 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
)
- Example
>>> 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 Tacotron2Audio Feature Extractions