/AlexaNotificationCurl

Some curl scripts to allow interfacing with Alexa using text as input.

Primary LanguageShell

AlexaNotificationCurl

Some curl scripts to allow interfacing with Alexa using text as input.

Demo

https://youtu.be/WLPApYslQVM

I'm using this along with OpenCV to do face recognition and then let me know who is at the front door: "Simon says, Joe is at the front door."

Initially, I just used my Alexa bluetooth and espeak (very bad sound), but I wanted it to sound like Alexa. So, I wrote this...

Credits

Motivated by Miguel Mota https://miguelmota.com/blog/alexa-voice-service-with-curl

The way this works:

- The text given to alexa.sh is converted into an wav file and sent to the alexa voice service. - The response is then piped to a 'play' command (espeak) to give the response.

Requirements:

You will need - curl - sox (Ubuntu packages: sox libsox-fmt-mp3) - pico2wav (Ubuntu package: libttspico-utils) - espeak (Not used in current version) NOTE: You could change the alexa.sh to use a different speech module, but I've found pico2wav to be pretty good.

How to use:

  1. Follow the instructions from Miguel here: https://miguelmota.com/blog/alexa-voice-service-authentication/ This sets up the service authentication.
  2. Replace the CLIENT_ID in the auth_code.sh file
  3. Run auth_code.sh (./auth_code.sh)
  4. Copy/paste the given URL into a browser and login to your amazon account
  5. Look for the code= in the authresponse in the url of the 'failed' webpage
  6. Replace CLIENT_ID, CLIENT_SECRET, and CODE in the auth_token.sh file
  7. Run the auth_token.sh (./auth_token.sh)

If all goes well, you will then have two files: token.dat and refresh.dat

For the next hour, you will be able to run the alexa.sh command. If an hour passes, you'll need to run the refresh_token.sh, then run alexa.sh NOTE: Be sure to update refresh_token.sh with your CLIENT_ID and CLIENT_SECRET

I setup the refresh_token.sh to run every hour in cron, then I don't worry about it again.

Note: The steps 1-7 above should only be needed once. The refresh_token should be able to keep an active token from that point on.

Sample:

./alexa.sh "Tell me a joke"

Troubleshooting:

Look at the various log files for errors. Also, I 'tee' out the audio sent and audio response.