@@ -21,6 +21,7 @@ def parse_args() -> argparse.Namespace:
2121 help = "A voice name to use. If this parameter is missing, then the server will try a first available model "
2222 "based on parameter `--language-code`." ,
2323 )
24+ parser .add_argument ("--text" , type = str , required = True , help = "Text input to synthesize." )
2425 parser .add_argument ("-o" , "--output" , type = Path , help = "Output file .wav file to write synthesized audio." )
2526 parser .add_argument (
2627 "--play-audio" ,
@@ -32,7 +33,8 @@ def parse_args() -> argparse.Namespace:
3233 parser .add_argument ("--output-device" , type = int , help = "Output device to use." )
3334 parser .add_argument ("--language-code" , default = 'en-US' , help = "A language of input text." )
3435 parser .add_argument (
35- "--sample-rate-hz" , type = int , default = 44100 , help = "Number of audio frames per second in synthesized audio." )
36+ "--sample-rate-hz" , type = int , default = 44100 , help = "Number of audio frames per second in synthesized audio."
37+ )
3638 parser .add_argument (
3739 "--stream" ,
3840 action = "store_true" ,
@@ -74,33 +76,33 @@ def main() -> None:
7476 out_f .setnchannels (nchannels )
7577 out_f .setsampwidth (sampwidth )
7678 out_f .setframerate (args .sample_rate_hz )
77- while True :
78- text = input ("Speak: " )
79- print ("Generating audio for request..." )
80- print (f" > '{ text } ': " , end = '' )
81- start = time .time ()
82- if args .stream :
83- responses = service .synthesize_online (
84- text , args .voice , args .language_code , sample_rate_hz = args .sample_rate_hz
85- )
86- first = True
87- for resp in responses :
88- stop = time .time ()
89- if first :
90- print (f"Time to first audio: { (stop - start ):.3f} s" )
91- first = False
92- if sound_stream is not None :
93- sound_stream (resp .audio )
94- if out_f is not None :
95- out_f .writeframesraw (resp .audio )
96- else :
97- resp = service .synthesize (text , args .voice , args .language_code , sample_rate_hz = args .sample_rate_hz )
79+
80+ print ("Generating audio for request..." )
81+ start = time .time ()
82+ if args .stream :
83+ responses = service .synthesize_online (
84+ args .text , args .voice , args .language_code , sample_rate_hz = args .sample_rate_hz
85+ )
86+ first = True
87+ for resp in responses :
9888 stop = time .time ()
99- print (f"Time spent: { (stop - start ):.3f} s" )
89+ if first :
90+ print (f"Time to first audio: { (stop - start ):.3f} s" )
91+ first = False
10092 if sound_stream is not None :
10193 sound_stream (resp .audio )
10294 if out_f is not None :
10395 out_f .writeframesraw (resp .audio )
96+ else :
97+ resp = service .synthesize (
98+ args .text , args .voice , args .language_code , sample_rate_hz = args .sample_rate_hz
99+ )
100+ stop = time .time ()
101+ print (f"Time spent: { (stop - start ):.3f} s" )
102+ if sound_stream is not None :
103+ sound_stream (resp .audio )
104+ if out_f is not None :
105+ out_f .writeframesraw (resp .audio )
104106 finally :
105107 if out_f is not None :
106108 out_f .close ()
0 commit comments