forked from X-E-Speech/X-E-Speech-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess_cn.py
29 lines (24 loc) · 1.17 KB
/
preprocess_cn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import argparse
import text_cn
from tqdm import tqdm
def load_filepaths_and_text(filename, split="|"):
with open(filename, encoding='utf-8') as f:
filepaths_and_text = [line.strip().split(split) for line in f]
return filepaths_and_text
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--out_extension", default="cleaned")
parser.add_argument("--text_index", default=1, type=int)
parser.add_argument("--filelists", nargs="+", default=["dataset/ESD/output_cn.txt.jieba.txt"])
parser.add_argument("--text_cleaners", nargs="+", default=["chinese_cleaners1"])
args = parser.parse_args()
for filelist in args.filelists:
print("START:", filelist)
filepaths_and_text = load_filepaths_and_text(filelist)
for i in tqdm(range(len(filepaths_and_text))):
original_text = filepaths_and_text[i][args.text_index]
cleaned_text = text_cn._clean_text(original_text, args.text_cleaners)
filepaths_and_text[i][args.text_index] = cleaned_text
new_filelist = filelist + "." + args.out_extension
with open(new_filelist, "w", encoding="utf-8") as f:
f.writelines(["|".join(x) + "\n" for x in filepaths_and_text])