MCPcopy Create free account
hub / github.com/MYZY-AI/Muyan-TTS / spectrogram_torch

Function spectrogram_torch

sovits/module/mel_processing.py:51–85  ·  view source on GitHub ↗
(y, n_fft, sampling_rate, hop_size, win_size, center=False)

Source from the content-addressed store, hash-verified

49
50
51def spectrogram_torch(y, n_fft, sampling_rate, hop_size, win_size, center=False):
52 if torch.min(y) < -1.0:
53 print("min value is ", torch.min(y))
54 if torch.max(y) > 1.0:
55 print("max value is ", torch.max(y))
56
57 global hann_window
58 dtype_device = str(y.dtype) + "_" + str(y.device)
59 wnsize_dtype_device = str(win_size) + "_" + dtype_device
60 if wnsize_dtype_device not in hann_window:
61 hann_window[wnsize_dtype_device] = torch.hann_window(win_size).to(
62 dtype=y.dtype, device=y.device
63 )
64
65 y = torch.nn.functional.pad(
66 y.unsqueeze(1),
67 (int((n_fft - hop_size) / 2), int((n_fft - hop_size) / 2)),
68 mode="reflect",
69 )
70 y = y.squeeze(1)
71 spec = torch.stft(
72 y,
73 n_fft,
74 hop_length=hop_size,
75 win_length=win_size,
76 window=hann_window[wnsize_dtype_device],
77 center=center,
78 pad_mode="reflect",
79 normalized=False,
80 onesided=True,
81 return_complex=False,
82 )
83
84 spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6)
85 return spec
86
87
88def spec_to_mel_torch(spec, n_fft, num_mels, sampling_rate, fmin, fmax):

Callers 1

get_spepcFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected