forked from isletennos/MMVC_Trainer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_dataset_jtalk.py
201 lines (187 loc) · 8.17 KB
/
create_dataset_jtalk.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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import glob
import sys
import os
import argparse
import pyopenjtalk
import json
def mozi2phone(mozi):
text = pyopenjtalk.g2p(mozi)
text = "sil " + text + " sil"
text = text.replace(' ', '-')
return text
def create_json(filename, num_speakers, sr, config_path):
if os.path.exists(config_path):
with open(config_path, "r", encoding="utf-8") as f:
data = json.load(f)
data['data']['training_files'] = 'filelists/' + filename + '_textful.txt'
data['data']['validation_files'] = 'filelists/' + filename + '_textful_val.txt'
data['data']['training_files_notext'] = 'filelists/' + filename + '_textless.txt'
data['data']['validation_files_notext'] = 'filelists/' + filename + '_val_textless.txt'
data['data']['sampling_rate'] = sr
data['data']['n_speakers'] = num_speakers
with open("./configs/" + filename + ".json", 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
def create_dataset(filename):
speaker_id = 107
textful_dir_list = glob.glob("dataset/textful/*")
textless_dir_list = glob.glob("dataset/textless/*")
textful_dir_list.sort()
textless_dir_list.sort()
Correspondence_list = list()
output_file_list = list()
output_file_list_val = list()
output_file_list_textless = list()
output_file_list_val_textless = list()
for d in textful_dir_list:
wav_file_list = glob.glob(d+"/wav/*.wav")
lab_file_list = glob.glob(d + "/text/*.txt")
wav_file_list.sort()
lab_file_list.sort()
if len(wav_file_list) == 0:
continue
counter = 0
for lab, wav in zip(lab_file_list, wav_file_list):
with open(lab, 'r', encoding="utf-8") as f:
mozi = f.read().split("\n")
print(str(mozi))
test = mozi2phone(str(mozi))
print(test)
print(wav + "|"+ str(speaker_id) + "|"+ test)
if counter % 10 != 0:
output_file_list.append(wav + "|"+ str(speaker_id) + "|"+ test + "\n")
else:
output_file_list_val.append(wav + "|"+ str(speaker_id) + "|"+ test + "\n")
counter = counter +1
Correspondence_list.append(str(speaker_id)+"|"+os.path.basename(d) + "\n")
speaker_id = speaker_id + 1
if speaker_id > 108:
break
for d in textless_dir_list:
wav_file_list = glob.glob(d+"/*.wav")
wav_file_list.sort()
counter = 0
for wav in wav_file_list:
print(wav + "|"+ str(speaker_id) + "|a")
if counter % 10 != 0:
output_file_list_textless.append(wav + "|"+ str(speaker_id) + "|a" + "\n")
else:
output_file_list_val_textless.append(wav + "|"+ str(speaker_id) + "|a" + "\n")
counter = counter +1
Correspondence_list.append(str(speaker_id)+"|"+os.path.basename(d) + "\n")
speaker_id = speaker_id + 1
with open('filelists/' + filename + '_textful.txt', 'w', encoding='utf-8', newline='\n') as f:
f.writelines(output_file_list)
with open('filelists/' + filename + '_textful_val.txt', 'w', encoding='utf-8', newline='\n') as f:
f.writelines(output_file_list_val)
with open('filelists/' + filename + '_textless.txt', 'w', encoding='utf-8', newline='\n') as f:
f.writelines(output_file_list_textless)
with open('filelists/' + filename + '_val_textless.txt', 'w', encoding='utf-8', newline='\n') as f:
f.writelines(output_file_list_val_textless)
with open('filelists/' + filename + '_Correspondence.txt', 'w', encoding='utf-8', newline='\n') as f:
f.writelines(Correspondence_list)
return speaker_id
def create_dataset_zundamon(filename):
textful_dir_list = glob.glob("dataset/textful/*")
textless_dir_list = glob.glob("dataset/textless/*")
textful_dir_list.sort()
textless_dir_list.sort()
Correspondence_list = list()
output_file_list = list()
output_file_list_val = list()
output_file_list_textless = list()
output_file_list_val_textless = list()
#paths
my_path = "dataset/textful/00_myvoice"
zundamon_path = "dataset/textful/1205_zundamon"
#set list wav and text
#myvoice
speaker_id = 107
d = my_path
wav_file_list = glob.glob(d + "/wav/*.wav")
lab_file_list = glob.glob(d + "/text/*.txt")
wav_file_list.sort()
lab_file_list.sort()
if len(wav_file_list) == 0:
print("Error" + d + "/wav に音声データがありません")
exit()
counter = 0
for lab, wav in zip(lab_file_list, wav_file_list):
with open(lab, 'r', encoding="utf-8") as f:
mozi = f.read().split("\n")
print(str(mozi))
test = mozi2phone(str(mozi))
print(test)
print(wav + "|"+ str(speaker_id) + "|"+ test)
if counter % 10 != 0:
output_file_list.append(wav + "|"+ str(speaker_id) + "|"+ test + "\n")
else:
output_file_list_val.append(wav + "|"+ str(speaker_id) + "|"+ test + "\n")
counter = counter +1
Correspondence_list.append(str(speaker_id)+"|"+os.path.basename(d) + "\n")
speaker_id = 100
d = zundamon_path
wav_file_list = glob.glob(d + "/wav/*.wav")
lab_file_list = glob.glob(d + "/text/*.txt")
wav_file_list.sort()
lab_file_list.sort()
if len(wav_file_list) == 0:
print("Error" + d + "/wav に音声データがありません")
exit()
counter = 0
for lab, wav in zip(lab_file_list, wav_file_list):
with open(lab, 'r', encoding="utf-8") as f:
mozi = f.read().split("\n")
print(str(mozi))
test = mozi2phone(str(mozi))
print(test)
print(wav + "|"+ str(speaker_id) + "|"+ test)
if counter % 10 != 0:
output_file_list.append(wav + "|"+ str(speaker_id) + "|"+ test + "\n")
else:
output_file_list_val.append(wav + "|"+ str(speaker_id) + "|"+ test + "\n")
counter = counter +1
Correspondence_list.append(str(speaker_id)+"|"+os.path.basename(d) + "\n")
for d in textless_dir_list:
wav_file_list = glob.glob(d+"/*.wav")
wav_file_list.sort()
counter = 0
for wav in wav_file_list:
print(wav + "|"+ str(speaker_id) + "|a")
if counter % 10 != 0:
output_file_list_textless.append(wav + "|"+ str(speaker_id) + "|a" + "\n")
else:
output_file_list_val_textless.append(wav + "|"+ str(speaker_id) + "|a" + "\n")
counter = counter +1
Correspondence_list.append(str(speaker_id)+"|"+os.path.basename(d) + "\n")
speaker_id = speaker_id + 1
with open('filelists/' + filename + '_textful.txt', 'w', encoding='utf-8', newline='\n') as f:
f.writelines(output_file_list)
with open('filelists/' + filename + '_textful_val.txt', 'w', encoding='utf-8', newline='\n') as f:
f.writelines(output_file_list_val)
with open('filelists/' + filename + '_textless.txt', 'w', encoding='utf-8', newline='\n') as f:
f.writelines(output_file_list_textless)
with open('filelists/' + filename + '_val_textless.txt', 'w', encoding='utf-8', newline='\n') as f:
f.writelines(output_file_list_val_textless)
with open('filelists/' + filename + '_Correspondence.txt', 'w', encoding='utf-8', newline='\n') as f:
f.writelines(Correspondence_list)
return 109
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--filename', type=str, required=True,
help='filelist for configuration')
parser.add_argument('-s', '--sr', type=int, default=24000,
help='sampling rate (default = 24000)')
parser.add_argument('-z', '--zundamon', type=bool, default=False,
help='U.N. zundamon Was Her? (default = False)')
parser.add_argument('-c', '--config', type=str, default="./configs/baseconfig.json",
help='JSON file for configuration')
args = parser.parse_args()
filename = args.filename
print(filename)
if args.zundamon:
n_spk = create_dataset_zundamon(filename)
else:
n_spk = create_dataset(filename)
create_json(filename, n_spk, args.sr, args.config)
if __name__ == '__main__':
main()