Programming Voice Interfaces by Walter Quesada & Bob Lautenbach

Programming Voice Interfaces by Walter Quesada & Bob Lautenbach

Author:Walter Quesada & Bob Lautenbach
Language: eng
Format: epub
Publisher: O'Reilly Media, Inc.
Published: 2017-10-11T04:00:00+00:00


def trigger_process(trigger): if player.is_playing(): player.stop() # clean up the temp directory if not debug: for some_file in os.listdir(tmp_path): file_path = os.path.join(tmp_path, some_file) try: if os.path.isfile(file_path): os.remove(file_path) except Exception as exp: logger.warning(exp) if event_commands['pre_interaction']: subprocess.Popen(event_commands['pre_interaction'], shell=True, stdout=subprocess.PIPE) force_record = None if trigger.event_type in triggers.types_continuous: force_record = (trigger.continuous_callback, trigger.event_type in triggers.types_vad) if trigger.voice_confirm: player.play_speech(resources_path + 'alexayes.mp3') audio_stream = capture.silence_listener(force_record=force_record) alexa_speech_recognizer(audio_stream) triggers.enable() if event_commands['post_interaction']: subprocess.Popen(event_commands['post_interaction'], shell=True, stdout=subprocess.PIPE)

The trigger_process function starts off with stopping the audio player then goes into cleaning up the /temp directory, which includes files like previously recorded audio, for example. Interestingly, the subsequent line is a conditional statement to see if there’s a pre_interaction event command specified. Additionally, at the bottom of the function, there’s a condition to check for post_interaction. If there is, it will execute it on a subprocess, which is a cool way to set up your own routine to run before and/or after the callback trigger executes.

The lines in between the pre_interaction and post_interaction conditions execute the trigger events, run a voice_confirm audio clip if the trigger is a voice confirmation, then listen for the audio from the microphone routing that same audio stream to the alexa_speech_recognizer function definition. This function essentially takes in an audio stream and prepares it for departure. Let’s break down the speech recognizer code for a bit:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.