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]¶
使用 Griffin-Lim 变换从线性幅值谱图计算波形。
实现移植自 *librosa* [Brian McFee 等人, 2015]、*A fast Griffin-Lim algorithm* [Perraudin 等人, 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
的教程