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

Function process_utterance

data_gen/tts/data_gen_utils.py:93–147  ·  view source on GitHub ↗
(wav_path,
                      fft_size=1024,
                      hop_size=256,
                      win_length=1024,
                      window="hann",
                      num_mels=80,
                      fmin=80,
                      fmax=7600,
                      eps=1e-10,
                      sample_rate=22050,
                      loud_norm=False,
                      min_level_db=-100,
                      return_linear=False,
                      trim_long_sil=False, vocoder='pwg')

Source from the content-addressed store, hash-verified

91
92
93def process_utterance(wav_path,
94 fft_size=1024,
95 hop_size=256,
96 win_length=1024,
97 window="hann",
98 num_mels=80,
99 fmin=80,
100 fmax=7600,
101 eps=1e-10,
102 sample_rate=22050,
103 loud_norm=False,
104 min_level_db=-100,
105 return_linear=False,
106 trim_long_sil=False, vocoder='pwg'):
107 if isinstance(wav_path, str):
108 if trim_long_sil:
109 wav, _, _ = trim_long_silences(wav_path, sample_rate)
110 else:
111 wav, _ = librosa.core.load(wav_path, sr=sample_rate)
112 else:
113 wav = wav_path
114
115 if loud_norm:
116 meter = pyln.Meter(sample_rate) # create BS.1770 meter
117 loudness = meter.integrated_loudness(wav)
118 wav = pyln.normalize.loudness(wav, loudness, -22.0)
119 if np.abs(wav).max() > 1:
120 wav = wav / np.abs(wav).max()
121
122 # get amplitude spectrogram
123 x_stft = librosa.stft(wav, n_fft=fft_size, hop_length=hop_size,
124 win_length=win_length, window=window, pad_mode="constant")
125 spc = np.abs(x_stft) # (n_bins, T)
126
127 # get mel basis
128 fmin = 0 if fmin == -1 else fmin
129 fmax = sample_rate / 2 if fmax == -1 else fmax
130 mel_basis = librosa.filters.mel(sample_rate, fft_size, num_mels, fmin, fmax)
131 mel = mel_basis @ spc
132
133 if vocoder == 'pwg':
134 mel = np.log10(np.maximum(eps, mel)) # (n_mel_bins, T)
135 else:
136 assert False, f'"{vocoder}" is not in ["pwg"].'
137
138 l_pad, r_pad = audio.librosa_pad_lr(wav, fft_size, hop_size, 1)
139 wav = np.pad(wav, (l_pad, r_pad), mode='constant', constant_values=0.0)
140 wav = wav[:mel.shape[1] * hop_size]
141
142 if not return_linear:
143 return wav, mel
144 else:
145 spc = audio.amp_to_db(spc)
146 spc = audio.normalize(spc, {'min_level_db': min_level_db})
147 return wav, mel, spc
148
149
150def get_pitch(wav_data, mel, hparams):

Callers 1

wav2specMethod · 0.90

Calls 3

trim_long_silencesFunction · 0.85
padMethod · 0.80
normalizeMethod · 0.80

Tested by

no test coverage detected