|
import json |
|
from pypinyin import lazy_pinyin, load_phrases_dict |
|
from shutil import copy |
|
import os |
|
from pathlib import Path |
|
import tqdm as tq |
|
import re |
|
|
|
|
|
source = 'D:/Samples/AI相关/原始数据集/Merged_Chinese_Wav' |
|
dist = 'C:/临时数据集/降临者&NPC' |
|
genshin = 'result.json' |
|
language = 'CHS' |
|
filter = 'fetter|battle|life|monster' |
|
clear_text = '^#' |
|
|
|
|
|
personalized_dict = { |
|
'嗯': [['en']], |
|
'八重': [['ba'], ['chong']], |
|
'重云': [['chong'], ['yun']] |
|
} |
|
|
|
renameDict = { |
|
'万叶': '枫原万叶', |
|
"#{REALNAME[ID(1)|HOSTONLY(true)]}": '流浪者', |
|
'影': '雷电将军', |
|
'公子': '达达利亚', |
|
'散兵': '流浪者', |
|
'幽夜菲谢尔': '菲谢尔', |
|
'绿色的家伙': '温迪', |
|
} |
|
|
|
charList = ['艾莉丝'] |
|
|
|
load_phrases_dict(personalized_dict) |
|
|
|
|
|
def is_in(full_path, regx): |
|
if re.findall(regx, full_path): |
|
return True |
|
else: |
|
return False |
|
|
|
|
|
def is_in_text(text, regx): |
|
if re.findall(regx, text): |
|
return True |
|
else: |
|
return False |
|
|
|
|
|
def is_empty(file_path): |
|
fsize = os.path.getsize(file_path) |
|
if fsize == 0: |
|
return True |
|
else: |
|
return False |
|
|
|
|
|
json_path = source + '/' + genshin |
|
f = open(json_path, encoding='utf8') |
|
data = json.load(f) |
|
for k in tq.tqdm(data.keys()): |
|
value = data.get(k).get('language') |
|
if value is not None: |
|
if value != language: |
|
continue |
|
text = data.get(k).get('text') |
|
char_name = data.get(k).get('npcName') |
|
path = data.get(k).get('fileName') |
|
path = path.replace(".wem", ".wav") |
|
path = path.replace("\\", "/") |
|
wav_source = source + '/' + path |
|
wav_file = os.path.basename(path) |
|
lab_file = wav_file.replace('.wav', '.lab') |
|
if text is not None and char_name is not None: |
|
if char_name in renameDict: |
|
char_name = renameDict[char_name] |
|
if char_name in charList: |
|
pinyin = " ".join(lazy_pinyin(text, errors='ignore')) |
|
dis_dir = dist + '/可使用/' + char_name |
|
clear_dir = dist + '/需确认/' + char_name |
|
lab_path = dis_dir + '/' + lab_file |
|
wav_path = dis_dir + '/' + wav_file |
|
lab_clear_path = clear_dir + '/' + lab_file |
|
wav_clear_path = clear_dir + '/' + wav_file |
|
try: |
|
if text is not None and is_in(path, filter) == False: |
|
if not os.path.exists(dis_dir): |
|
os.makedirs(dis_dir) |
|
if not os.path.exists(clear_dir): |
|
os.makedirs(clear_dir) |
|
if is_in_text(text, clear_text) == True: |
|
Path(lab_clear_path).write_text( |
|
text, encoding='utf-8') |
|
copy(wav_source, wav_clear_path) |
|
if is_empty(lab_clear_path) == True: |
|
os.remove(lab_clear_path) |
|
os.remove(wav_clear_path) |
|
if is_in_text(text, clear_text) == False: |
|
copy(wav_source, wav_path) |
|
Path(lab_path).write_text(pinyin, encoding='utf-8') |
|
if is_empty(lab_path) == True: |
|
os.remove(lab_path) |
|
os.remove(wav_path) |
|
except Exception as e: |
|
pass |
|
continue |
|
f.close() |
|
|