def get_authorization(): # Load configuration dictionary config = helper.read_dict('config.dict') cherrypy.config.update({'server.socket_host': '0.0.0.0', }) cherrypy.config.update({'server.socket_port': int(os.environ.get('PORT', '5000')), }) cherrypy.quickstart(Start(config))
alexa = alexa_device.AlexaDevice(config) speech = alexa.set_speech_instance(mic_device) player = alexa.set_player_instance(alexa.playback_progress_report_request, speaker_device) player.setup(volume) player.blocking_play('files/hello.mp3') while 1: try: if not wake_word: text = raw_input("Press enter anytime to start recording (or 'q' to quit).") if text == 'q': alexa.close() sys.exit() break else: speech.connect() except (KeyboardInterrupt, EOFError, SystemExit): alexa.close() sys.exit() break alexa.user_initiate_audio() if __name__ == "__main__": config = helper.read_dict('config.dict') if 'refresh_token' not in config: print("Please go to http://localhost:5000") authorization.get_authorization() config = helper.read_dict('config.dict') work(config)
# While the stop event is not set while True: # Prompt user to press enter to start a recording, or q to quit text = input("Press enter anytime to start recording (or 'q' to quit).") # If 'q' is pressed if text == 'q': # Set stop event and break out of loop alexa_device.close() break # If enter was pressed (and q was not) # Get raw audio from the microphone alexa_device.user_initiate_audio() if __name__ == "__main__": # Load configuration file (contains the authorization for the user and device information) config = helper.read_dict('config.dict') # Check for authorization, if none, initialize and ask user to go to a website for authorization. if 'refresh_token' not in config: print("Please go to http://localhost:5000") authorization.get_authorization() config = helper.read_dict('config.dict') # Create alexa device alexa_device = alexa_device.AlexaDevice(config) user_input_loop(alexa_device) print("Done")