MCPcopy Create free account
hub / github.com/MeiGen-AI/MultiTalk / SourceModuleHnNSF

Class SourceModuleHnNSF

kokoro/istftnet.py:212–254  ·  view source on GitHub ↗

SourceModule for hn-nsf SourceModule(sampling_rate, harmonic_num=0, sine_amp=0.1, add_noise_std=0.003, voiced_threshod=0) sampling_rate: sampling_rate in Hz harmonic_num: number of harmonic above F0 (default: 0) sine_amp: amplitude of sine source signal (default: 0.

Source from the content-addressed store, hash-verified

210
211
212class SourceModuleHnNSF(nn.Module):
213 """ SourceModule for hn-nsf
214 SourceModule(sampling_rate, harmonic_num=0, sine_amp=0.1,
215 add_noise_std=0.003, voiced_threshod=0)
216 sampling_rate: sampling_rate in Hz
217 harmonic_num: number of harmonic above F0 (default: 0)
218 sine_amp: amplitude of sine source signal (default: 0.1)
219 add_noise_std: std of additive Gaussian noise (default: 0.003)
220 note that amplitude of noise in unvoiced is decided
221 by sine_amp
222 voiced_threshold: threhold to set U/V given F0 (default: 0)
223 Sine_source, noise_source = SourceModuleHnNSF(F0_sampled)
224 F0_sampled (batchsize, length, 1)
225 Sine_source (batchsize, length, 1)
226 noise_source (batchsize, length 1)
227 uv (batchsize, length, 1)
228 """
229 def __init__(self, sampling_rate, upsample_scale, harmonic_num=0, sine_amp=0.1,
230 add_noise_std=0.003, voiced_threshod=0):
231 super(SourceModuleHnNSF, self).__init__()
232 self.sine_amp = sine_amp
233 self.noise_std = add_noise_std
234 # to produce sine waveforms
235 self.l_sin_gen = SineGen(sampling_rate, upsample_scale, harmonic_num,
236 sine_amp, add_noise_std, voiced_threshod)
237 # to merge source harmonics into a single excitation
238 self.l_linear = nn.Linear(harmonic_num + 1, 1)
239 self.l_tanh = nn.Tanh()
240
241 def forward(self, x):
242 """
243 Sine_source, noise_source = SourceModuleHnNSF(F0_sampled)
244 F0_sampled (batchsize, length, 1)
245 Sine_source (batchsize, length, 1)
246 noise_source (batchsize, length 1)
247 """
248 # source for harmonic branch
249 with torch.no_grad():
250 sine_wavs, uv, _ = self.l_sin_gen(x)
251 sine_merge = self.l_tanh(self.l_linear(sine_wavs))
252 # source for noise branch, in the same shape as uv
253 noise = torch.randn_like(uv) * self.sine_amp / 3
254 return sine_merge, noise, uv
255
256
257class Generator(nn.Module):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected