-
Notifications
You must be signed in to change notification settings - Fork 4
/
synthesize.py
55 lines (42 loc) · 1.87 KB
/
synthesize.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
import sys
import argparse
import logging
import tacorn.wrappers as wrappers
import tacorn.experiment as experiment
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(message)s')
logger = logging.getLogger(__name__)
def _get_sentences(args):
with open(args.sentences_file, 'rb') as f:
sentences = [l.decode("utf-8").rstrip() for l in f.readlines()]
return sentences
def synthesize(exp: experiment.Experiment, args) -> None:
""" Synthesizes inside an experiment folder. """
sentences = _get_sentences(args)
logger.info("Loading acoustic feature model wrapper %s for synthesis" %
(exp.config["acoustic_model"]))
acoustic_module_wrapper = wrappers.load(exp.config["acoustic_model"])
acoustic_module_wrapper.generate(exp, sentences, generate_features=args.use_wavegen,
generate_waveforms=(not args.use_wavegen))
logger.info("Synthesis from acoustic feature model done")
if args.use_wavegen:
wavegen_module_wrapper = wrappers.load(exp.config["wavegen_model"])
wavegen_module_wrapper.generate(exp)
def main():
""" main function for synthesis. """
parser = argparse.ArgumentParser()
parser.add_argument('experiment_dir',
help='Experiment directory.')
parser.add_argument('sentences_file',
help='File containing sentences to synthesize')
parser.add_argument('--use_wavegen', default='True',
help='Use the wavegen model for waveform generation, if False resort to e.g. Griffin-Lim')
args = parser.parse_args()
try:
exp = experiment.load(args.experiment_dir)
except Exception:
print("Invalid experiment folder given: %s" % (args.experiment_dir))
sys.exit(1)
synthesize(exp, args)
if __name__ == '__main__':
main()