forked from keithito/tacotron
-
Notifications
You must be signed in to change notification settings - Fork 103
/
preprocess.py
129 lines (109 loc) · 4.29 KB
/
preprocess.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
import argparse
import os
from multiprocessing import cpu_count
from tqdm import tqdm
from datasets import amy, blizzard, ljspeech, kusal, mailabs
from datasets import mrs
from hparams import hparams, hparams_debug_string
import sys
def preprocess_blizzard(args):
in_dir = os.path.join(args.base_dir, 'Blizzard2012')
out_dir = os.path.join(args.base_dir, args.output)
os.makedirs(out_dir, exist_ok=True)
metadata = blizzard.build_from_path(
in_dir, out_dir, args.num_workers, tqdm=tqdm)
write_metadata(metadata, out_dir)
def preprocess_ljspeech(args):
in_dir = os.path.join(args.base_dir, 'LJSpeech-1.1')
out_dir = os.path.join(args.base_dir, args.output)
os.makedirs(out_dir, exist_ok=True)
metadata = ljspeech.build_from_path(
in_dir, out_dir, args.num_workers, tqdm=tqdm)
write_metadata(metadata, out_dir)
def preprocess_mrs(args):
in_dir = args.mrs_dir
out_dir = os.path.join(args.base_dir, args.output)
username = args.mrs_username
os.makedirs(out_dir, exist_ok=True)
metadata = mrs.build_from_path(
in_dir, out_dir, username, args.num_workers, tqdm=tqdm)
write_metadata(metadata, out_dir)
def preprocess_amy(args):
in_dir = os.path.join(args.base_dir, 'amy')
out_dir = os.path.join(args.base_dir, args.output)
os.makedirs(out_dir, exist_ok=True)
metadata = amy.build_from_path(in_dir, out_dir, args.num_workers, tqdm=tqdm)
write_metadata(metadata, out_dir)
def preprocess_kusal(args):
in_dir = os.path.join(args.base_dir, 'kusal')
out_dir = os.path.join(args.base_dir, args.output)
os.makedirs(out_dir, exist_ok=True)
metadata = kusal.build_from_path(
in_dir, out_dir, args.num_workers, tqdm=tqdm)
write_metadata(metadata, out_dir)
def preprocess_mailabs(args):
in_dir = os.path.join(args.mailabs_books_dir)
out_dir = os.path.join(args.base_dir, args.output)
os.makedirs(out_dir, exist_ok=True)
books = args.books
metadata = mailabs.build_from_path(
in_dir, out_dir, books, args.num_workers, tqdm)
write_metadata(metadata, out_dir)
def write_metadata(metadata, out_dir):
with open(os.path.join(out_dir, 'train.txt'), 'w', encoding='utf-8') as f:
for m in metadata:
f.write('|'.join([str(x) for x in m]) + '\n')
frames = sum([m[2] for m in metadata])
hours = frames * hparams.frame_shift_ms / (3600 * 1000)
print('Wrote %d utterances, %d frames (%.2f hours)' %
(len(metadata), frames, hours))
print('Max input length: %d' % max(len(m[3]) for m in metadata))
print('Max output length: %d' % max(m[2] for m in metadata))
with open("metadata.txt", 'w') as f:
f.write(
'''
Wrote {} utterances, {} frames, {} hours\n
Max input lengh: {} \n
Max output length: {} \n
'''.format(
len(metadata), frames, hours,
max(len(m[3]) for m in metadata), max(m[2] for m in metadata)
)
)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--base_dir', default=os.path.expanduser('~/tacotron'))
parser.add_argument('--mrs_dir', required=False)
parser.add_argument('--mrs_username', required=False)
parser.add_argument('--output', default='training')
parser.add_argument(
'--dataset', required=True, choices=['amy', 'blizzard', 'ljspeech', 'kusal', 'mailabs','mrs']
)
parser.add_argument('--mailabs_books_dir',
help='absolute directory to the books for the mlailabs')
parser.add_argument(
'--books',
help='comma-seperated and no space name of books i.e hunter_space,pink_fairy_book,etc.',
)
parser.add_argument('--num_workers', type=int, default=cpu_count())
args = parser.parse_args()
if args.dataset == 'mailabs' and args.books is None:
parser.error("--books required if mailabs is chosen for dataset.")
if args.dataset == 'mailabs' and args.mailabs_books_dir is None:
parser.error(
"--mailabs_books_dir required if mailabs is chosen for dataset.")
print(hparams_debug_string())
if args.dataset == 'amy':
preprocess_amy(args)
elif args.dataset == 'blizzard':
preprocess_blizzard(args)
elif args.dataset == 'ljspeech':
preprocess_ljspeech(args)
elif args.dataset == 'kusal':
preprocess_kusal(args)
elif args.dataset == 'mailabs':
preprocess_mailabs(args)
elif args.dataset == 'mrs':
preprocess_mrs(args)
if __name__ == "__main__":
main()