4141 assistant_helpers ,
4242 audio_helpers ,
4343 browser_helpers ,
44- device_helpers
44+ device_helpers ,
45+ text_helpers
4546 )
4647except (SystemError , ImportError ):
4748 import assistant_helpers
4849 import audio_helpers
4950 import browser_helpers
5051 import device_helpers
52+ import text_helpers
5153
5254
5355ASSISTANT_API_ENDPOINT = 'embeddedassistant.googleapis.com'
@@ -256,6 +258,10 @@ def gen_assist_requests(self):
256258 help = 'Enable visual display of Assistant responses in HTML.' )
257259@click .option ('--verbose' , '-v' , is_flag = True , default = False ,
258260 help = 'Verbose logging.' )
261+ @click .option ('--use-text-input' , is_flag = True , default = False ,
262+ help = 'Use the hacky text-to-speech stuff.' )
263+ @click .option ('--use-text-output' , is_flag = True , default = False ,
264+ help = 'Use the hacky speech-to-text stuff.' )
259265@click .option ('--input-audio-file' , '-i' ,
260266 metavar = '<input file>' ,
261267 help = 'Path to input audio file. '
@@ -293,7 +299,8 @@ def gen_assist_requests(self):
293299 help = 'Force termination after a single conversation.' )
294300def main (api_endpoint , credentials , project_id ,
295301 device_model_id , device_id , device_config ,
296- lang , display , verbose ,
302+ lang , display , verbose , use_text_input ,
303+ use_text_output ,
297304 input_audio_file , output_audio_file ,
298305 audio_sample_rate , audio_sample_width ,
299306 audio_iter_size , audio_block_size , audio_flush_size ,
@@ -336,7 +343,13 @@ def main(api_endpoint, credentials, project_id,
336343
337344 # Configure audio source and sink.
338345 audio_device = None
339- if input_audio_file :
346+ if use_text_input :
347+ audio_source = text_helpers .TextSource (
348+ "" ,
349+ sample_rate = audio_sample_rate ,
350+ sample_width = audio_sample_width
351+ )
352+ elif input_audio_file :
340353 audio_source = audio_helpers .WaveSource (
341354 open (input_audio_file , 'rb' ),
342355 sample_rate = audio_sample_rate ,
@@ -351,7 +364,13 @@ def main(api_endpoint, credentials, project_id,
351364 flush_size = audio_flush_size
352365 )
353366 )
354- if output_audio_file :
367+
368+ if use_text_output :
369+ audio_sink = text_helpers .TextSink (
370+ sample_rate = audio_sample_rate ,
371+ sample_width = audio_sample_width
372+ )
373+ elif output_audio_file :
355374 audio_sink = audio_helpers .WaveSink (
356375 open (output_audio_file , 'wb' ),
357376 sample_rate = audio_sample_rate ,
@@ -452,8 +471,15 @@ def blink(speed, number):
452471 # and playing back assistant response using the speaker.
453472 # When the once flag is set, don't wait for a trigger. Otherwise, wait.
454473 wait_for_user_trigger = not once
474+ first = True
455475 while True :
456- if wait_for_user_trigger :
476+ if use_text_input :
477+ if not first and use_text_output :
478+ logging .info ('Recognized response from Assistant: ' + audio_sink .recognize ())
479+ audio_sink .reset ()
480+ audio_source .reset_text (click .prompt ('' ))
481+ first = False
482+ elif wait_for_user_trigger :
457483 click .pause (info = 'Press Enter to send a new request...' )
458484 continue_conversation = assistant .assist ()
459485 # wait for user trigger if there is no follow-up turn in
0 commit comments