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], 一種快速 Griffin-Lim 演算法 [Perraudin et al., 2013] 和 從修改後的短時傅立葉轉換進行訊號估計 [Griffin and Lim, 1983]。
- 參數:
n_fft (int, optional) – FFT 大小,產生
n_fft // 2 + 1
個 bins。(預設值:400
)n_iter (int, optional) – 相位恢復過程的迭代次數。(預設值:
32
)win_length (int or None, optional) – 視窗大小。(預設值:
n_fft
)hop_length (int or None, optional) – STFT 視窗之間的 hop 長度。(預設值:
win_length // 2
)window_fn (Callable[..., Tensor], optional) – 一個建立視窗 tensor 的函數,該 tensor 將被應用/乘以每個 frame/window。(預設值:
torch.hann_window
)power (float, optional) – magnitude spectrogram 的指數 (必須 > 0),例如,magnitude 為 1,power 為 2,等等。(預設值:
2
)wkwargs (dict or None, optional) – 視窗函數的參數。(預設值:
None
)momentum (float, optional) – 用於快速 Griffin-Lim 的 momentum 參數。將其設定為 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
的教學課程