Update spec_gen.py

This commit is contained in:
Stardust·减
2023-08-03 18:20:06 +08:00
committed by GitHub
parent b91d6d8cb5
commit 5571f76b34

View File

@@ -5,28 +5,14 @@ import commons
import utils import utils
from data_utils import TextAudioSpeakerLoader, TextAudioSpeakerCollate from data_utils import TextAudioSpeakerLoader, TextAudioSpeakerCollate
from tqdm import tqdm from tqdm import tqdm
from multiprocessing import Pool
from text import cleaned_text_to_sequence, get_bert from text import cleaned_text_to_sequence, get_bert
config_path = 'configs/config.json' config_path = 'configs/config.json'
hps = utils.get_hparams_from_file(config_path) hps = utils.get_hparams_from_file(config_path)
# train_dataset = TextAudioSpeakerLoader(hps.data.training_files, hps.data) def process_line(line):
# eval_dataset = TextAudioSpeakerLoader(hps.data.validation_files, hps.data)
#
# collate_fn = TextAudioSpeakerCollate()
# train_loader = DataLoader(train_dataset, num_workers=12, shuffle=False,
# batch_size=32, pin_memory=True,
# drop_last=False, collate_fn=collate_fn)
# eval_loader = DataLoader(eval_dataset, num_workers=12, shuffle=False,
# batch_size=32, pin_memory=True,
# drop_last=False, collate_fn=collate_fn)
# for _ in tqdm(train_loader):
# pass
# for _ in tqdm(eval_loader):
# pass
for line in tqdm( open(hps.data.training_files).readlines()):
_id, spk, language_str, text, phones, tone, word2ph = line.strip().split("|") _id, spk, language_str, text, phones, tone, word2ph = line.strip().split("|")
phone = phones.split(" ") phone = phones.split(" ")
tone = [int(i) for i in tone.split(" ")] tone = [int(i) for i in tone.split(" ")]
@@ -35,7 +21,6 @@ for line in tqdm( open(hps.data.training_files).readlines()):
w2pho = [i for i in word2ph] w2pho = [i for i in word2ph]
word2ph = [i for i in word2ph] word2ph = [i for i in word2ph]
phone, tone, language = cleaned_text_to_sequence(phone, tone, language_str) phone, tone, language = cleaned_text_to_sequence(phone, tone, language_str)
pold2 = phone
if hps.data.add_blank: if hps.data.add_blank:
phone = commons.intersperse(phone, 0) phone = commons.intersperse(phone, 0)
@@ -44,7 +29,7 @@ for line in tqdm( open(hps.data.training_files).readlines()):
for i in range(len(word2ph)): for i in range(len(word2ph)):
word2ph[i] = word2ph[i] * 2 word2ph[i] = word2ph[i] * 2
word2ph[0] += 1 word2ph[0] += 1
wav_path = f'dataset/{spk}/{_id}.wav' wav_path = f'{_id}'
bert_path = wav_path.replace(".wav", ".bert.pt") bert_path = wav_path.replace(".wav", ".bert.pt")
try: try:
@@ -55,3 +40,9 @@ for line in tqdm( open(hps.data.training_files).readlines()):
assert bert.shape[-1] == len(phone) assert bert.shape[-1] == len(phone)
torch.save(bert, bert_path) torch.save(bert, bert_path)
with open(hps.data.training_files) as f:
lines = f.readlines()
with Pool() as pool:
for _ in tqdm(pool.imap_unordered(process_line, lines)):
pass