示例#1
0
def work(config):
    volume = 60
    wake_word = True
    
    # defualt if pulseaudio otherwise plughw:[CARDID]
    mic_device = 'default'
    speaker_device = 'plughw:1'

    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()
示例#2
0
def start():
    global alexa
    if alexa is not None:
        return
    alexa_config = alexa_http_config.load_config()
    if alexa_config is not None:
        print("Alexa found config.")
        alexa = alexa_device.AlexaDevice(alexa_config)
示例#3
0
    # 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")