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
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.
Automotive | Engineering |
Transportation |
Whiskies Galore by Ian Buxton(41506)
Introduction to Aircraft Design (Cambridge Aerospace Series) by John P. Fielding(32874)
Small Unmanned Fixed-wing Aircraft Design by Andrew J. Keane Andras Sobester James P. Scanlan & András Sóbester & James P. Scanlan(32554)
Craft Beer for the Homebrewer by Michael Agnew(17916)
Turbulence by E. J. Noyes(7679)
The Complete Stick Figure Physics Tutorials by Allen Sarah(7114)
Kaplan MCAT General Chemistry Review by Kaplan(6562)
The Thirst by Nesbo Jo(6420)
Bad Blood by John Carreyrou(6257)
Modelling of Convective Heat and Mass Transfer in Rotating Flows by Igor V. Shevchuk(6214)
Learning SQL by Alan Beaulieu(6009)
Weapons of Math Destruction by Cathy O'Neil(5802)
Man-made Catastrophes and Risk Information Concealment by Dmitry Chernov & Didier Sornette(5618)
Digital Minimalism by Cal Newport;(5350)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5164)
iGen by Jean M. Twenge(5141)
Secrets of Antigravity Propulsion: Tesla, UFOs, and Classified Aerospace Technology by Ph.D. Paul A. Laviolette(4890)
Design of Trajectory Optimization Approach for Space Maneuver Vehicle Skip Entry Problems by Runqi Chai & Al Savvaris & Antonios Tsourdos & Senchun Chai(4829)
Electronic Devices & Circuits by Jacob Millman & Christos C. Halkias(4724)
