Alexa Notifications - Override/Reroute Speech Commands

Posted on
Sat Aug 03, 2019 10:49 pm
James offline
Posts: 4
Joined: Aug 16, 2011

Alexa Notifications - Override/Reroute Speech Commands

I am using code to broadcast announcements to all my Amazon Echo devices simultaneously using SSML.

I was wondering if anyone knows how I could override, redirect, or piggyback on the Indigo speak function (indigo.server.speak) or even the underlying macOS say command to take the text string to be spoken and send it to my own function?

I could simply make my own function to use instead of Indigo's speak function; but ideally, I would like to make it global so all speech commands from triggers and actions (or even OS commands) would also be handled.

Any ideas?

Just in case anyone is interested in automating Alexa further, the alexa-remote code also provides the means to control many aspects of Alexa such as executing Routines, managing Devices, bluetooth connections, etc.

I'll certainly share the code I am creating when it's completed; but as much as I would like to, I doubt I will have the time to create a proper, fully-functioning Indigo plugin.

Posted on
Tue Aug 13, 2019 11:20 am
rapamatic offline
Posts: 236
Joined: Aug 03, 2015
Location: Glencoe, IL

Re: Alexa Notifications - Override/Reroute Speech Commands

Just so I understand, you are able to have your Alexas make voice announcements? I'm using Sonos for that now, and it feels like a hack at best - would be much nicer (I think) to leverage Alexa devices for this, at least in most cases. Would you mind sharing the code/process you've developed so far?

Thanks!

Posted on
Wed Aug 21, 2019 1:04 am
James offline
Posts: 4
Joined: Aug 16, 2011

Re: Alexa Notifications - Override/Reroute Speech Commands

Sure! I currently have my own code running in a Node.js Express server so I can send commands from anywhere on the network. It's pretty custom and still a messy work in progress; but here are some instructions and code I quickly put together, which will hopefully get you or other people started.


Before you can run it, you'll need to download and install Node.js if you don't already have it. (Download Node.js)

Step 1:

    Create a folder on your Desktop called "Alexa", download the attached file to that folder, and rename it to remove the ".txt" extension.

Step 2:

    Run the following command in Terminal to install alexa-remote from GitHub, as well as its dependencies:
    Code: Select all
    cd ~/Desktop/Alexa && npm install github:Apollon77/alexa-remote.git && node ./send-alexa-command.js

Step 3:

    The first time the code runs, you'll get an error like this one since it cannot login to your Amazon account yet:
    Code: Select all
    Alexa-Remote: Error from retrieving cookies
    Error: You can try to get the cookie manually by opening http://localhost:3001/ with your browser.

    Open http://localhost:3001/ with your browser, which brings up an Amazon login page (yup, it's in German). When you login, it will capture the cookie to use from then on.
    I added code to save and load the cookie from a file so you should only have to do this once (unless you don't use it long enough for the cookie to expire).



If everything worked, you should get an announcement on all your Alexa devices saying "This is a test."

Since this is just a sample/test program, I just have it exit after sending the command to Alexa. You can then edit the sendCommand call in the send-alexa-command.js file and use the following Terminal command to run it again:
Code: Select all
node ./send-alexa-command.js
The sendCommand function takes 3 parameters:
  1. command
    string - One of the commands in the createSequenceNode function in alexa-remote.js.
    For example:
    • speak
    • announcement
    • ssml (This is a speak command with advanced features like different voices/languages. Click here for reference.)
    • volume
    • singasong
  2. value
    string or number - If the command doesn't require a value, you can just leave this empty or null.
    When the command is ssml, you can enter SSML code or just a simple string that will be spoken using a default voice and language that can be set in the send-alexa-command.js file.
  3. deviceIDs
    Can be any one of the following:
    • string - Name of Alexa device
    • string - Serial number of Alexa device
    • array - A list of multiple device names or serial numbers
    • null - If omitted, the command will be sent to ALL devices.

You can also just call the functions in the AlexaRemote class directly, but I tried to make one intuitive function that handled all the commands I needed to make.


Examples:

Send SSML speech command to 2 devices named "Echo Show" and "Living Room":
Code: Select all
sendCommand("ssml", "This is a test.", ["Echo Show", "Living Room"]);

Have Alexa tell the weather from a device called "Family Room":
Code: Select all
sendCommand("weather", "", "Family Room");

Set the volume to 100% on ALL devices:
Code: Select all
sendCommand("volume", 100);

Send custom SSML to ALL devices:
Code: Select all
let customSSML = "<speak>" +
    "<lang xml:lang='en-US'>" +
    "<say-as interpret-as='interjection'>hiya. guess what.</say-as>" +
    "I wanna tell you a secret" +
    "<break time='500ms'/>" +
    "<amazon:effect name='whispered'>I can see your browser history.</amazon:effect>" +
    "<break time='1s'/>" +
    "<say-as interpret-as='interjection'>schwing. oh my.</say-as>" +
    "<break time='1500ms'/>" +
    "<say-as interpret-as='interjection'>ha ha. gotcha.</say-as>." +
    '</lang>' +
    '</speak>';
sendCommand("ssml", customSSML);


* The attached file will have to be edited if you are outside the United States. See the alexa-remote repo for more details.

EDIT: I thought I should mention that I have nothing to do with the GitHub repos or contributing projects that make this happen, I just edited the example.js file from Apollon77's repo and added a few of my own functions. All credit goes to them. :wink:
Attachments
send-alexa-command.js.txt
(6.24 KiB) Downloaded 2 times

Posted on
Wed Aug 21, 2019 6:21 am
rapamatic offline
Posts: 236
Joined: Aug 03, 2015
Location: Glencoe, IL

Re: Alexa Notifications - Override/Reroute Speech Commands

Wow, this looks awesome. Thanks for sharing your process! I'll definitely be playing around with this over the next few days.


Sent from my iPad using Tapatalk

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest