update preprocess_text.py:过滤音频不存在的情况 (#58)

This commit is contained in:
Sora
2023-10-12 15:03:11 +08:00
committed by GitHub
parent 5dfe7c9493
commit e3ce4d5a94

View File

@@ -1,4 +1,5 @@
import json import json
import os.path
from collections import defaultdict from collections import defaultdict
from random import shuffle from random import shuffle
from typing import Optional from typing import Optional
@@ -68,11 +69,18 @@ def main(
with open(transcription_path, encoding="utf-8") as f: with open(transcription_path, encoding="utf-8") as f:
audioPaths = set() audioPaths = set()
countSame = 0
countNotFound = 0
for line in f.readlines(): for line in f.readlines():
utt, spk, language, text, phones, tones, word2ph = line.strip().split("|") utt, spk, language, text, phones, tones, word2ph = line.strip().split("|")
if utt in audioPaths: if utt in audioPaths:
# 过滤数据集错误相同的音频匹配多个文本导致后续bert出问题 # 过滤数据集错误相同的音频匹配多个文本导致后续bert出问题
print(f"重复音频文本:{line}") print(f"重复音频文本:{line}")
countSame += 1
continue
if not os.path.isfile(utt):
print(f"没有找到对应的音频:{utt}")
countNotFound += 1
continue continue
audioPaths.add(utt) audioPaths.add(utt)
spk_utt_map[spk].append(line) spk_utt_map[spk].append(line)
@@ -80,6 +88,7 @@ def main(
if spk not in spk_id_map.keys(): if spk not in spk_id_map.keys():
spk_id_map[spk] = current_sid spk_id_map[spk] = current_sid
current_sid += 1 current_sid += 1
print(f"总重复音频数:{countSame},总未找到的音频数:{countNotFound}")
train_list = [] train_list = []
val_list = [] val_list = []