Commit
•
218d726
1
Parent(s):
25a4599
上传整理脚本
Browse files- Scripts/genshin_label.py +109 -0
Scripts/genshin_label.py
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from pypinyin import lazy_pinyin, load_phrases_dict
|
3 |
+
from shutil import copy
|
4 |
+
import os
|
5 |
+
from pathlib import Path
|
6 |
+
import tqdm as tq
|
7 |
+
import re
|
8 |
+
# ===============路径设置===============
|
9 |
+
# 原神数据集目录,Merged_Chinese_Wav文件夹的内容需要放到Chinese目录里面
|
10 |
+
source = 'D:/Samples/AI相关/原始数据集/Merged_Chinese_Wav'
|
11 |
+
dist = 'C:/临时数据集/降临者&NPC' # 输出目录
|
12 |
+
genshin = 'result.json' # 配套json,要和Chinese目录在同一个位置
|
13 |
+
filter = 'fetter|battle|life|monster' # 滤除包含特定名字的文件
|
14 |
+
clear_text = '^#' # 筛选文本中带特定文字的内容
|
15 |
+
# ===============字典设置===============
|
16 |
+
# --------------发音重定向--------------
|
17 |
+
personalized_dict = {
|
18 |
+
'嗯': [['en']],
|
19 |
+
'八重': [['ba'], ['chong']],
|
20 |
+
'重云': [['chong'], ['yun']]
|
21 |
+
}
|
22 |
+
# --------------角色重命名--------------
|
23 |
+
renameDict = {
|
24 |
+
'万叶': '枫原万叶',
|
25 |
+
"#{REALNAME[ID(1)|HOSTONLY(true)]}": '流浪者',
|
26 |
+
'影': '雷电将军',
|
27 |
+
'公子': '达达利亚',
|
28 |
+
'散兵': '流浪者',
|
29 |
+
'幽夜菲谢尔': '菲谢尔',
|
30 |
+
'绿色的家伙': '温迪',
|
31 |
+
}
|
32 |
+
# ---------------所需角色---------------
|
33 |
+
charList = ['艾莉丝']
|
34 |
+
# =========以下内容请勿擅自修改==========
|
35 |
+
load_phrases_dict(personalized_dict)
|
36 |
+
|
37 |
+
|
38 |
+
def is_in(full_path, regx):
|
39 |
+
if re.findall(regx, full_path):
|
40 |
+
return True
|
41 |
+
else:
|
42 |
+
return False
|
43 |
+
|
44 |
+
|
45 |
+
def is_in_text(text, regx):
|
46 |
+
if re.findall(regx, text):
|
47 |
+
return True
|
48 |
+
else:
|
49 |
+
return False
|
50 |
+
|
51 |
+
|
52 |
+
def is_empty(file_path):
|
53 |
+
fsize = os.path.getsize(file_path)
|
54 |
+
if fsize == 0:
|
55 |
+
return True
|
56 |
+
else:
|
57 |
+
return False
|
58 |
+
|
59 |
+
|
60 |
+
json_path = source + '/' + genshin
|
61 |
+
f = open(json_path, encoding='utf8')
|
62 |
+
data = json.load(f)
|
63 |
+
for k in tq.tqdm(data.keys()):
|
64 |
+
value = data.get(k).get('language')
|
65 |
+
if value is not None:
|
66 |
+
if value != 'CHS':
|
67 |
+
continue
|
68 |
+
text = data.get(k).get('text')
|
69 |
+
char_name = data.get(k).get('npcName')
|
70 |
+
path = data.get(k).get('fileName')
|
71 |
+
path = path.replace(".wem", ".wav")
|
72 |
+
path = path.replace("\\", "/")
|
73 |
+
wav_source = source + '/' + path
|
74 |
+
wav_file = os.path.basename(path)
|
75 |
+
lab_file = wav_file.replace('.wav', '.lab')
|
76 |
+
if text is not None and char_name is not None:
|
77 |
+
if char_name in renameDict:
|
78 |
+
char_name = renameDict[char_name]
|
79 |
+
if char_name in charList:
|
80 |
+
pinyin = " ".join(lazy_pinyin(text, errors='ignore'))
|
81 |
+
dis_dir = dist + '/可使用/' + char_name
|
82 |
+
clear_dir = dist + '/需确认/' + char_name
|
83 |
+
lab_path = dis_dir + '/' + lab_file
|
84 |
+
wav_path = dis_dir + '/' + wav_file
|
85 |
+
lab_clear_path = clear_dir + '/' + lab_file
|
86 |
+
wav_clear_path = clear_dir + '/' + wav_file
|
87 |
+
try:
|
88 |
+
if text is not None and is_in(path, filter) == False:
|
89 |
+
if not os.path.exists(dis_dir):
|
90 |
+
os.makedirs(dis_dir)
|
91 |
+
if not os.path.exists(clear_dir):
|
92 |
+
os.makedirs(clear_dir)
|
93 |
+
if is_in_text(text, clear_text) == True:
|
94 |
+
Path(lab_clear_path).write_text(
|
95 |
+
text, encoding='utf-8')
|
96 |
+
copy(wav_source, wav_clear_path)
|
97 |
+
if is_empty(lab_clear_path) == True:
|
98 |
+
os.remove(lab_clear_path)
|
99 |
+
os.remove(wav_clear_path)
|
100 |
+
if is_in_text(text, clear_text) == False:
|
101 |
+
copy(wav_source, wav_path)
|
102 |
+
Path(lab_path).write_text(pinyin, encoding='utf-8')
|
103 |
+
if is_empty(lab_path) == True:
|
104 |
+
os.remove(lab_path)
|
105 |
+
os.remove(wav_path)
|
106 |
+
except Exception as e:
|
107 |
+
pass
|
108 |
+
continue
|
109 |
+
f.close()
|