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的教程