Some curl scripts to allow interfacing with Alexa using text as input.
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...
Motivated by Miguel Mota Creditshttps://miguelmota.com/blog/alexa-voice-service-with-curl
- 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. The way this works:
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. Requirements:
How to use:
- Follow the instructions from Miguel here: https://miguelmota.com/blog/alexa-voice-service-authentication/ This sets up the service authentication.
- Replace the CLIENT_ID in the auth_code.sh file
- Run auth_code.sh (./auth_code.sh)
- Copy/paste the given URL into a browser and login to your amazon account
- Look for the code= in the authresponse in the url of the 'failed' webpage
- Replace CLIENT_ID, CLIENT_SECRET, and CODE in the auth_token.sh file
- 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.