Created
November 26, 2022 17:09
-
-
Save mizoru/ea1f5610d1fc3193489dd9a7fa74a375 to your computer and use it in GitHub Desktop.
get_data_to_buffer with f0 processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_data_to_buffer(train_config): | |
buffer = list() | |
text = process_text(train_config.data_path) | |
audio_files = sorted(Path(train_config.audio_path).iterdir()) | |
hop_length = 256 | |
frame_period = hop_length / 22_050 * 1000 | |
start = time.perf_counter() | |
for i, file in tqdm(zip(range(len(text)), audio_files)): | |
mel_gt_name = os.path.join( | |
train_config.mel_ground_truth, "ljspeech-mel-%05d.npy" % (i+1)) | |
mel_gt_target = np.load(mel_gt_name) | |
duration = np.load(os.path.join( | |
train_config.alignment_path, str(i)+".npy")) | |
character = text[i][0:len(text[i])-1] | |
character = np.array( | |
text_to_sequence(character, train_config.text_cleaners)) | |
wav, sr = librosa.load(file, sr=None, dtype=np.float64) | |
f0, t = pw.dio(wav, sr, frame_period=frame_period) | |
assert f0.shape[0] == mel_gt_target.shape[0] | |
character = torch.from_numpy(character) | |
duration = torch.from_numpy(duration) | |
mel_gt_target = torch.from_numpy(mel_gt_target) | |
f0 = torch.from_numpy(f0) | |
buffer.append({"text": character, "duration": duration, | |
"mel_target": mel_gt_target, "f0": f0}) | |
end = time.perf_counter() | |
print("cost {:.2f}s to load all data into buffer.".format(end-start)) | |
return buffer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment