File size: 4,065 Bytes
218d726
 
 
 
 
 
 
 
 
 
 
 
9223930
218d726
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9223930
218d726
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
# ===============路径设置===============
# 原神数据集目录,Merged_Chinese_Wav文件夹的内容需要放到Chinese目录里面
source = 'D:/Samples/AI相关/原始数据集/Merged_Chinese_Wav'
dist = 'C:/临时数据集/降临者&NPC'  # 输出目录
genshin = 'result.json'  # 配套json,要和Chinese目录在同一个位置
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()