Giter Site home page Giter Site logo

python-alexa-voice-service's Introduction

Python Alexa Voice Service

This project is a Python implementation of Amazon's Alexa Voice Service (AVS). The goal of this project is to create cross-platform example Alexa device that is completely compatible with the current AVS API (v20160207). This is a work in progress.

Requirements

Getting Started

Install the necessary requirements and clone the repository.

git clone https://github.com/nicholasjconn/python-alexa-voice-service

cd python-alexa-voice-service

Extract and copy the ffmpeg folder to the project's folder. Rename to ffmpeg, so that the ffmpeg command is located in python-alexa-voice-service/ffmpeg/bin/ffmpeg.

Follow the directions from Amazon on how to get your Client ID, Client Secret, and ProductID (parts of Chapter 3 and Chapter 6).

https://github.com/amzn/alexa-avs-raspberry-pi

Rename config_example.dict to config.dict. Then open the file and update the Client ID, Client Secret, and ProductID values to your own values

Run the main.py script. If you run into any errors, chances are that you have missed one of the requirements.

python3 main.py

Using the Code

This is a command line based program. You will be receive notices and prompts via the command line. Start a voice command by pressing enter. The software is not always listening (I am waiting on a response from Amazon before enabling this), so a button press is required to active the microphone.

When you would like to close the program, press 'q' and then enter.

Errors and other text may be printed out if anything goes wrong. This is a work in progress.

Example Alexa Commands

  • "What time is it?"
  • "Set an alarm."
  • "Where am I?"
  • "What is the weather tomorrow?"
  • "Are you a robot?"

If you have the Wink hub or any other supported home automation devices, you can connect them via the Android Alexa App. Once connected, you can say things like "turn on bedroom lights" or "set bedroom lights to 50%".

Have fun!

Cross-Platform

This code has only been tested on Windows. This project will eventually support Linux and hopefully OS X. The final goal is for this project to work out of the box on a Raspberry Pi.

Alexa Voice Service

The following link has all of the information needed to understand the Alexa Voice Service API:

https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/content/avs-api-overview

Bugs

If you run into any bugs, please create an issue on GitHub. Don't hesitate to submit bugs for the README.md as well! I can't promise that I will get to it quickly, but I will do my best to keep this project as bug free as possible (given the time I have to work on it).

Contributing

Feel free contribute to the code! I will be actively adding new feature until it is full-featured. If you get to a feature before me, I may be able to use your code!

License

MIT - See LICENSE

Future Work

Please feel free to add functionality or fix any bugs that you find. I will be working on this project whenever I have time, so stay tuned for updates.

Currently, only the SpeechRecognizer and SpeechSynthesizer interfaces are supported. More will be added in the near future.

Change Log

  • Version 0.2 - Added Alert (alarm and timer) functionality, and updated README.md

python-alexa-voice-service's People

Contributors

calebcgates avatar nicholasjconn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-alexa-voice-service's Issues

Alarms and timers

I've been looking for a way to do the latest API version of AVS using curl or something that didn't require java and I ran into this. I'm running on Linux and for the most part it is working except for timers and alarms.

When I set the timer or alarm I don't see anything in the downstream channel. I was under the impression that I would see something in this channel if a timer or an alarm was set.

Has anyone else tried this? Am I correct I should be focused in on looking at the downstream_thread?

Authentication Issue

I'm new to alexa voice services ,I have followed all the steps correctly . Cherrpy is giving warning that Unable to verify that server is bound on 3000 warnings.warn(msg) and m running it on windows machine. I was hopping if you could provide me some insights about th
issue_preview
is issue and guide me through this

Auth issue

Hi Nick, thanks for the great work, I'm hoping to get it running. The issue I'm facing is when I execute 'python main.py' and then go to 'http://localhost:5000' in a browser, I get the following error from amazon:

"... Error Summary
400 Bad Request
The redirect URI you provided has not been whitelisted for your application. Please add your redirect URI in the 'Allowed Return URLs' section under 'Web Settings' for your Security Profile on Amazon Developer Portal."

In my security profile for AVS, in 'Allowed Origins', I have included 'http://localhost:5000'. In 'Allowed Return URLs', I have included 'http://localhost:5000/authresponse'.

However, I note that when I hover over the question mark for 'Allowed Origins', I read: "...Origins must use the HTTPS protocol... ". Also, the directions inhttps://github.com/amzn/alexa-avs-raspberry-pi in section 6.1 specify using https.

So I'm not able to authenticate. How did you manage through this? thanks

Stuck at SynchronizeState event

I am able to see the success of sending the 1st GET to establish the downchannel stream, but fail to see the response from sending the SynchronizeState event. The error I got is

PUSH b'{"header":{"namespace":"System","name":"Exception","messageId":"7d621fd0-f7fc-4c9a-b666-273e8a8ca2ac"},"payload":{"code":"INVALID_REQUEST_EXCEPTION","description":"Bad Request"}}' Exception in thread Thread-1: Traceback (most recent call last): File "/usr/local/lib/python3.5/threading.py", line 914, in _bootstrap_inner self.run() File "/usr/local/lib/python3.5/threading.py", line 862, in run self._target(*self._args, **self._kwargs) File "/home/pi/python-alexa-voice-service/alexa_device.py", line 181, in device_thread_function process_response_handle=self.process_response) File "/home/pi/python-alexa-voice-service/alexa_communication.py", line 178, in __init__ self.init_connection() File "/home/pi/python-alexa-voice-service/alexa_communication.py", line 201, in init_connection raise NameError("Bad status (%s)" % data.status) NameError: Bad status (400)

Any idea?

TypeError: Can't convert 'bytes' object to str implicitly

I'll go ahead and put this as a separate issue. I'm using python 3.5 as specified. I did google and find this that says "In Python 3, the socket returns data as bytes (it was string in Python 2)." which makes me think may be python version related, but that must not be the case because when I run main.py with python 2.7 it fails because no urllib.

Anyway below is what I got, any help is appreciated.

C:\Users\young_000\OneDrive\Code\Echo\python-alexa-voice-service>python main.py
Press enter anytime to start recording (or 'q' to quit).Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\young_000\AppData\Local\Programs\Python\Python35-32\lib\threading.py", line 914, in bootstrap_inner
self.run()
File "C:\Users\young_000\AppData\Local\Programs\Python\Python35-32\lib\threading.py", line 862, in run
self.target(self._args, *self._kwargs)
File "C:\Users\young_000\OneDrive\Code\Echo\python-alexa-voice-service\alexa_device.py", line 181, in device_thread_function
process_response_handle=self.process_response)
File "C:\Users\young_000\OneDrive\Code\Echo\python-alexa-voice-service\alexa_communication.py", line 178, in __init
self.init_connection()
File "C:\Users\young_000\OneDrive\Code\Echo\python-alexa-voice-service\alexa_communication.py", line 200, in init_connection
print("PUSH" + data.read())
TypeError: Can't convert 'bytes' object to str implicitly

You can start talking now...
Traceback (most recent call last):
File "main.py", line 45, in
user_input_loop(alexa_device)
File "main.py", line 30, in user_input_loop
alexa_device.user_initiate_audio()
File "C:\Users\young_000\OneDrive\Code\Echo\python-alexa-voice-service\alexa_device.py", line 203, in user_initiate_audio
stream_id = self.alexa.start_recognize_event(raw_audio)
AttributeError: 'NoneType' object has no attribute 'start_recognize_event'

RepromptText Error

Great program. Thank you.
One issue I've run into is that re prompts don't work after you let the primary prompt time out.
It appears the issue is that the reprompt message doesn't contain the dialogRequestId

Primary Message

alexa_devices.py
line 315 on
def process_directive_speech_recognizer(self,content,attachment):
header = content['directive']['header']
print(str(header))
### Primary Header
{'name': 'ExpectSpeech', 'messageId': 'aed9edd3-3d84-4e17-9000-3acb0ca6dded', 'namespace': 'SpeechRecognizer', 'dialogRequestId': 'njc_dialog_id-1495477099-0'}
Start talking now, you have 8 seconds
Speech timeout.

### Reprompt Header
{'name': 'ExpectSpeech', 'messageId': '4fc551b2-2082-4073-a8c7-6b3fa3f1953a', 'namespace': 'SpeechRecognizer'}

Error inside def process_directive_speech_recognizer() because dialogRequestId is not defined in the reprompt
dialog_request_id = header['dialogRequestId']

My solution was to create a class variable in the AlexaDevices init called
170 self.dialogRequestIdReprompt = None

I then added this qualifier to process_directive_speech_recognizer()

330         if name == 'ExpectSpeech':
331             # Get specific fields for expect speech
332             dialog_request_id = self.dialogRequestIdReprompt
333             if 'dialogRequestId' in header:
334                 dialog_request_id = header['dialogRequestId']
335                 self.dialogRequestIdReprompt = dialog_request_id
336             timeout = payload['timeoutInMilliseconds']/1000

This seemed to work. if the dialogRequestId was not specified it would use the last one that was.

However, I don't know enough about the whole project and api to feel comfortable merging an ad-hoc solution with your project.

Please take a look at this when you have a chance.
Thanks -X

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.