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

Function get_pitch

data_gen/tts/data_gen_utils.py:150–184  ·  view source on GitHub ↗

:param wav_data: [T] :param mel: [T, 80] :param hparams: :return:

(wav_data, mel, hparams)

Source from the content-addressed store, hash-verified

148
149
150def get_pitch(wav_data, mel, hparams):
151 """
152
153 :param wav_data: [T]
154 :param mel: [T, 80]
155 :param hparams:
156 :return:
157 """
158 time_step = hparams['hop_size'] / hparams['audio_sample_rate'] * 1000
159 f0_min = 80
160 f0_max = 750
161
162 if hparams['hop_size'] == 128:
163 pad_size = 4
164 elif hparams['hop_size'] == 256:
165 pad_size = 2
166 else:
167 assert False
168
169 f0 = parselmouth.Sound(wav_data, hparams['audio_sample_rate']).to_pitch_ac(
170 time_step=time_step / 1000, voicing_threshold=0.6,
171 pitch_floor=f0_min, pitch_ceiling=f0_max).selected_array['frequency']
172 lpad = pad_size * 2
173 rpad = len(mel) - len(f0) - lpad
174 f0 = np.pad(f0, [[lpad, rpad]], mode='constant')
175 # mel and f0 are extracted by 2 different libraries. we should force them to have the same length.
176 # Attention: we find that new version of some libraries could cause ``rpad'' to be a negetive value...
177 # Just to be sure, we recommend users to set up the same environments as them in requirements_auto.txt (by Anaconda)
178 delta_l = len(mel) - len(f0)
179 assert np.abs(delta_l) <= 8
180 if delta_l > 0:
181 f0 = np.concatenate([f0, [f0[-1]] * delta_l], 0)
182 f0 = f0[:len(mel)]
183 pitch_coarse = f0_to_coarse(f0)
184 return f0, pitch_coarse
185
186
187def remove_empty_lines(text):

Callers 3

get_pitchMethod · 0.90
after_inferMethod · 0.90
save_resultMethod · 0.90

Calls 2

f0_to_coarseFunction · 0.90
padMethod · 0.80

Tested by

no test coverage detected