2017-07-08 17:08:26 +00:00
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
from multiprocessing import cpu_count
|
|
|
|
from tqdm import tqdm
|
2018-04-02 19:46:26 +00:00
|
|
|
from datasets import amy, blizzard, ljspeech
|
2017-07-08 17:08:26 +00:00
|
|
|
from hparams import hparams
|
|
|
|
|
|
|
|
|
|
|
|
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.0')
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2018-04-02 19:46:26 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2017-07-08 17:08:26 +00:00
|
|
|
def write_metadata(metadata, out_dir):
|
2017-09-05 03:47:44 +00:00
|
|
|
with open(os.path.join(out_dir, 'train.txt'), 'w', encoding='utf-8') as f:
|
2017-07-08 17:08:26 +00:00
|
|
|
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))
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('--base_dir', default=os.path.expanduser('~/tacotron'))
|
|
|
|
parser.add_argument('--output', default='training')
|
2018-04-02 19:46:26 +00:00
|
|
|
parser.add_argument('--dataset', required=True, choices=['amy', 'blizzard', 'ljspeech'])
|
2017-07-08 17:08:26 +00:00
|
|
|
parser.add_argument('--num_workers', type=int, default=cpu_count())
|
|
|
|
args = parser.parse_args()
|
2018-04-02 19:46:26 +00:00
|
|
|
if args.dataset == 'amy':
|
|
|
|
preprocess_amy(args)
|
|
|
|
elif args.dataset == 'blizzard':
|
2017-07-08 17:08:26 +00:00
|
|
|
preprocess_blizzard(args)
|
|
|
|
elif args.dataset == 'ljspeech':
|
|
|
|
preprocess_ljspeech(args)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|