MCPcopy Create free account
hub / github.com/MoonInTheRiver/DiffSinger / stft

Function stft

modules/parallel_wavegan/losses/stft_loss.py:12–31  ·  view source on GitHub ↗

Perform STFT and convert to magnitude spectrogram. Args: x (Tensor): Input signal tensor (B, T). fft_size (int): FFT size. hop_size (int): Hop size. win_length (int): Window length. window (str): Window function type. Returns: Tensor: Magnitu

(x, fft_size, hop_size, win_length, window)

Source from the content-addressed store, hash-verified

10
11
12def stft(x, fft_size, hop_size, win_length, window):
13 """Perform STFT and convert to magnitude spectrogram.
14
15 Args:
16 x (Tensor): Input signal tensor (B, T).
17 fft_size (int): FFT size.
18 hop_size (int): Hop size.
19 win_length (int): Window length.
20 window (str): Window function type.
21
22 Returns:
23 Tensor: Magnitude spectrogram (B, #frames, fft_size // 2 + 1).
24
25 """
26 x_stft = torch.stft(x, fft_size, hop_size, win_length, window)
27 real = x_stft[..., 0]
28 imag = x_stft[..., 1]
29
30 # NOTE(kan-bayashi): clamp is needed to avoid nan or inf
31 return torch.sqrt(torch.clamp(real ** 2 + imag ** 2, min=1e-7)).transpose(2, 1)
32
33
34class SpectralConvergengeLoss(torch.nn.Module):

Callers 2

forwardMethod · 0.90
forwardMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected