espnet2.utils.griffin_lim.griffin_lim
Less than 1 minute
espnet2.utils.griffin_lim.griffin_lim
espnet2.utils.griffin_lim.griffin_lim(spc: ndarray, n_fft: int, n_shift: int, win_length: int | None = None, window: str | None = 'hann', n_iter: int | None = 32) → ndarray
Convert linear spectrogram into waveform using Griffin-Lim.
This function reconstructs a waveform from a linear spectrogram using the Griffin-Lim algorithm, which iteratively refines the phase information to recover the audio signal.
- Parameters:
- spc – Linear spectrogram (T, n_fft // 2 + 1).
- n_fft – The number of FFT points.
- n_shift – Shift size in points.
- win_length – Window length in points (optional).
- window – Window function type (optional, default is “hann”).
- n_iter – The number of iterations (optional, default is 32).
- Returns: Reconstructed waveform (N,).
Examples
Example of using griffin_lim to convert a linear spectrogram back to audio
import numpy as np spc = np.random.rand(100, 1025) # Example linear spectrogram waveform = griffin_lim(spc, n_fft=2048, n_shift=512)
NOTE
This function requires librosa library version 0.7.0 or higher for the optimized Griffin-Lim algorithm. If an older version is used, a warning will be logged, and a slower implementation will be used.
- Raises:
- ValueError – If the input spectrogram shape does not match the expected
- dimensions. –