2017-07-08 17:08:26 +00:00
import argparse
import os
import re
from hparams import hparams , hparams_debug_string
from synthesizer import Synthesizer
2018-07-03 23:53:07 +00:00
from util import plot
2017-07-08 17:08:26 +00:00
sentences = [
2018-07-03 23:53:07 +00:00
# From July 8, 2017 New York Times:
2018-07-05 18:13:55 +00:00
' Scientists at the CERN laboratory say they have discovered a new particle. ' ,
' There’ s a way to measure the acute emotional intelligence that has never gone out of style. ' ,
' President Trump met with other leaders at the Group of 20 conference. ' ,
' The Senate \' s bill to repeal and replace the Affordable Care Act is now imperiled. ' ,
# From Google's Tacotron example page:
' Generative adversarial network or variational auto-encoder. ' ,
' The buses aren \' t the problem, they actually provide a solution. ' ,
' Does the quick brown fox jump over the lazy dog? ' ,
' Talib Kweli confirmed to AllHipHop that he will be releasing an album in the next year. ' ,
# From mycroft
2018-07-03 23:53:07 +00:00
" It took me quite a long time to develop a voice, and now that I have it I ' m not going to be silent. " ,
2018-09-05 17:40:46 +00:00
" As commander-in-chief of the Continental Army during the American Revolutionary War, he was the principal force in the surrender of the British at Yorktown " ,
2018-07-03 23:53:07 +00:00
" Be a voice, not an echo. " ,
" The human voice is the most perfect instrument of all. " ,
" I ' m sorry Dave, I ' m afraid I can ' t do that. " ,
" This cake is great, It ' s so delicious and moist. " ,
2018-09-05 17:40:46 +00:00
" hello, my name is mycroft. " ,
2018-07-03 23:53:07 +00:00
" hi. " ,
" wow. " ,
" cool. " ,
" great. " ,
2017-07-08 17:08:26 +00:00
]
def get_output_base_path ( checkpoint_path ) :
base_dir = os . path . dirname ( checkpoint_path )
m = re . compile ( r ' .*? \ .ckpt \ -([0-9]+) ' ) . match ( checkpoint_path )
name = ' eval- %d ' % int ( m . group ( 1 ) ) if m else ' eval '
return os . path . join ( base_dir , name )
def run_eval ( args ) :
print ( hparams_debug_string ( ) )
synth = Synthesizer ( )
synth . load ( args . checkpoint )
base_path = get_output_base_path ( args . checkpoint )
for i , text in enumerate ( sentences ) :
2018-07-03 23:53:07 +00:00
wav_path = ' %s - %d .wav ' % ( base_path , i )
align_path = ' %s - %d .png ' % ( base_path , i )
print ( ' Synthesizing and plotting: %s ' % wav_path )
wav , alignment = synth . synthesize ( text )
with open ( wav_path , ' wb ' ) as f :
2018-09-28 22:18:55 +00:00
f . write ( wav )
2018-07-03 23:53:07 +00:00
plot . plot_alignment (
alignment , align_path ,
info = ' %s ' % ( text )
)
2017-07-08 17:08:26 +00:00
def main ( ) :
parser = argparse . ArgumentParser ( )
2018-07-05 18:13:55 +00:00
parser . add_argument (
' --checkpoint ' , required = True ,
help = ' Path to model checkpoint ' )
parser . add_argument (
' --hparams ' , default = ' ' ,
help = ' Hyperparameter overrides as a comma-separated list of name=value pairs ' )
parser . add_argument (
' --force_cpu ' , default = False ,
help = ' Force synthesize with cpu ' )
parser . add_argument (
' --gpu_assignment ' , default = ' 0 ' ,
help = ' Set the gpu the model should run on ' )
2017-07-08 17:08:26 +00:00
args = parser . parse_args ( )
2018-07-05 18:13:55 +00:00
os . environ [ ' CUDA_VISIBLE_DEVICES ' ] = args . gpu_assignment
2018-06-18 17:20:09 +00:00
if args . force_cpu :
os . environ [ ' CUDA_VISIBLE_DEVICES ' ] = ' '
2018-07-05 18:13:55 +00:00
2017-07-08 17:08:26 +00:00
os . environ [ ' TF_CPP_MIN_LOG_LEVEL ' ] = ' 2 '
hparams . parse ( args . hparams )
run_eval ( args )
2017-09-05 03:47:44 +00:00
if __name__ == ' __main__ ' :
2017-07-08 17:08:26 +00:00
main ( )