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)[源码]¶
使用 Griffin-Lim 变换从线性幅度频谱图计算波形。
实现移植自 librosa [Brian McFee et al., 2015],A fast Griffin-Lim algorithm [Perraudin et al., 2013] 和 Signal estimation from modified short-time Fourier transform [Griffin and Lim, 1983]。
- 参数
n_fft (int, optional) – FFT 的大小,创建
n_fft // 2 + 1
个 bin。 (默认:400
)n_iter (int, optional) – 相位恢复过程的迭代次数。 (默认:
32
)win_length (int 或 None, optional) – 窗口大小。 (默认:
n_fft
)hop_length (int 或 None, optional) – STFT 窗口之间的跳跃长度。 (默认:
win_length // 2
)window_fn (Callable[..., Tensor], optional) – 一个用于创建窗口张量的函数,该张量将被应用于/乘以每个帧/窗口。 (默认:
torch.hann_window
)power (float, optional) – 幅度谱的指数,(必须大于 0)例如,1 表示幅度,2 表示功率,依此类推。 (默认:
2
)wkwargs (dict 或 None, optional) – 窗口函数的参数。 (默认:
None
)momentum (float, optional) – 快速 Griffin-Lim 的动量参数。将其设置为 0 可恢复原始的 Griffin-Lim 方法。接近 1 的值可能导致收敛加快,但大于 1 可能无法收敛。 (默认:
0.99
)length (int, optional) – 预期输出的数组长度。 (默认:
None
)rand_init (bool, optional) – 如果为 True,则随机初始化相位;否则初始化为零。 (默认:
True
)
- 示例
>>> batch, freq, time = 2, 257, 100 >>> spectrogram = torch.randn(batch, freq, time) >>> transform = transforms.GriffinLim(n_fft=512) >>> waveform = transform(spectrogram)
- 使用
GriffinLim
的教程