@@ -21,6 +21,7 @@ def parse_args() -> argparse.Namespace:
21
21
help = "A voice name to use. If this parameter is missing, then the server will try a first available model "
22
22
"based on parameter `--language-code`." ,
23
23
)
24
+ parser .add_argument ("--text" , type = str , required = True , help = "Text input to synthesize." )
24
25
parser .add_argument ("-o" , "--output" , type = Path , help = "Output file .wav file to write synthesized audio." )
25
26
parser .add_argument (
26
27
"--play-audio" ,
@@ -32,7 +33,8 @@ def parse_args() -> argparse.Namespace:
32
33
parser .add_argument ("--output-device" , type = int , help = "Output device to use." )
33
34
parser .add_argument ("--language-code" , default = 'en-US' , help = "A language of input text." )
34
35
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
+ )
36
38
parser .add_argument (
37
39
"--stream" ,
38
40
action = "store_true" ,
@@ -74,33 +76,33 @@ def main() -> None:
74
76
out_f .setnchannels (nchannels )
75
77
out_f .setsampwidth (sampwidth )
76
78
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 :
98
88
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
100
92
if sound_stream is not None :
101
93
sound_stream (resp .audio )
102
94
if out_f is not None :
103
95
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 )
104
106
finally :
105
107
if out_f is not None :
106
108
out_f .close ()
0 commit comments