Alexa Notifications - Override/Reroute Speech Commands

Ask questions about integrating other services (internet and otherwise) and applications with Indigo.
James
Posts: 22
Joined: Tue Aug 16, 2011 6:37 pm

Alexa Notifications - Override/Reroute Speech Commands

Post by James »

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.
rapamatic
Posts: 283
Joined: Mon Aug 03, 2015 2:54 pm
Location: Glencoe, IL

Re: Alexa Notifications - Override/Reroute Speech Commands

Post by rapamatic »

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!
James
Posts: 22
Joined: Tue Aug 16, 2011 6:37 pm

Re: Alexa Notifications - Override/Reroute Speech Commands

Post by James »

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 314 times
rapamatic
Posts: 283
Joined: Mon Aug 03, 2015 2:54 pm
Location: Glencoe, IL

Re: Alexa Notifications - Override/Reroute Speech Commands

Post by rapamatic »

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
User avatar
indigobo
Posts: 22
Joined: Fri Jan 04, 2019 11:45 am
Location: Raleigh, NC

Re: Alexa Notifications - Override/Reroute Speech Commands

Post by indigobo »

This is an awesome addition to my Indigo setup, thank you!!

I have successfully gotten things to work as advertised but I'm trying to figure out a way to run the Terminal command [node ./send-alexa-command.js] from within Indigo but haven't been successful.

My current work around is to use a Keyboard Maestro script to activate Terminal and send the command. It's not elegant, but does work and allows me to connect Indigo triggers with Alexa speech actions.

I do have two questions though (forgive my "newbeeness").

1) Is there an easy way to send the Terminal command from within Indigo?

2) The weather command [sendCommand("weather", "", "Family Room");] works perfectly. Is there a similar command for reading today's calendar events or tomorrow's calendar events?

Thank you again for your fantastic contribution!
James
Posts: 22
Joined: Tue Aug 16, 2011 6:37 pm

Re: Alexa Notifications - Override/Reroute Speech Commands

Post by James »

indigobo wrote: 1) Is there an easy way to send the Terminal command from within Indigo?
Sure. You can make an Action Group or Trigger to run a file or script.

Image
indigobo wrote: 2) The weather command [sendCommand("weather", "", "Family Room");] works perfectly. Is there a similar command for reading today's calendar events or tomorrow's calendar events?
There are actually! Here is a list of commands you can use using my previous example:
  • weather
    traffic
    flashbriefing
    goodmorning
    singasong
    tellstory
    calendarToday
    calendarTomorrow
    calendarNext
    volume*
    deviceStop
    speak*
    notification*
    announcement*
    ssml*
* Requires additional value

There is MUCH more you can do if you are familiar with programming. See the source file for all the functions you can perform:

https://github.com/Apollon77/alexa-remo ... -remote.js
User avatar
indigobo
Posts: 22
Joined: Fri Jan 04, 2019 11:45 am
Location: Raleigh, NC

Re: Alexa Notifications - Override/Reroute Speech Commands

Post by indigobo »

Wow! Thank you very much!! You've made me a happy camper :D
ckeyes888
Posts: 2438
Joined: Thu Nov 26, 2009 2:41 pm
Location: Kalispell, MT

Re: Alexa Notifications - Override/Reroute Speech Commands

Post by ckeyes888 »

Love to try this but am confused by step 1.

When the linked file is downloaded it's node-v10.16.3.pkg. You mention putting it into the Alexa desktop folder and renaming to remove the .txt
extension...which it doesn't have. Maybe I need to run the .pkg first them move the installed file to the Alexa folder?

Thanks,

Carl
User avatar
indigobo
Posts: 22
Joined: Fri Jan 04, 2019 11:45 am
Location: Raleigh, NC

Re: Alexa Notifications - Override/Reroute Speech Commands

Post by indigobo »

You might have "Show all filename extensions" unchecked in the Finder.

Choose menu item [img][img][/img][/img] Finder >> Preferences >>and then clicking on the Advanced tab.
Attachments
scrennshot.jpg
scrennshot.jpg (80.56 KiB) Viewed 7581 times
ckeyes888
Posts: 2438
Joined: Thu Nov 26, 2009 2:41 pm
Location: Kalispell, MT

Re: Alexa Notifications - Override/Reroute Speech Commands

Post by ckeyes888 »

No, it's not unchecked and still very confused.

Carl
ckeyes888
Posts: 2438
Joined: Thu Nov 26, 2009 2:41 pm
Location: Kalispell, MT

Re: Alexa Notifications - Override/Reroute Speech Commands

Post by ckeyes888 »

Making some progress but get this error in Terminal.

Code: Select all

TV:~ TV$ cd ~/Desktop/Alexa && npm install github:Apollon77/alexa-remote.git && node ./send-alexa-command.js
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://[email protected]/Apollon77/alexa-remote.git
npm ERR! 
npm ERR! dyld: Library not loaded: @rpath/DVTFoundation.framework/Versions/A/DVTFoundation
npm ERR!   Referenced from: /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild
npm ERR!   Reason: no suitable image found.  Did find:
npm ERR! 	/Applications/Xcode.app/Contents/Developer/usr/bin/../../../SharedFrameworks/DVTFoundation.framework/Versions/A/DVTFoundation: cannot load '/Applications/Xcode.app/Contents/Developer/usr/bin/../../../SharedFrameworks/DVTFoundation.framework/Versions/A/DVTFoundation' because Objective-C garbage collection is not supported
npm ERR! xcrun: error: unable to locate xcodebuild, please make sure the path to the Xcode folder is set correctly!
npm ERR! xcrun: error: You can set the path to the Xcode folder using /usr/bin/xcode-select -switch
npm ERR! 
npm ERR! exited with error code: 69

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/TV/.npm/_logs/2019-09-30T21_40_22_279Z-debug.log
Seems it needs something from Xcode it's not finding?

Thanks,

Carl
User avatar
indigobo
Posts: 22
Joined: Fri Jan 04, 2019 11:45 am
Location: Raleigh, NC

Re: Alexa Notifications - Override/Reroute Speech Commands

Post by indigobo »

I'm a newb myself, but I did have success with using the above instructions. Did you download Node.js?
James
Posts: 22
Joined: Tue Aug 16, 2011 6:37 pm

Re: Alexa Notifications - Override/Reroute Speech Commands

Post by James »

You may have to install the Xcode Command Line Tools.

I believe this method still works:

http://osxdaily.com/2014/02/12/install- ... -mac-os-x/


Sent from my iPhone using Tapatalk
User avatar
mundmc
Posts: 1068
Joined: Fri Sep 14, 2012 4:34 pm

Alexa Notifications - Override/Reroute Speech Commands

Post by mundmc »

This looks awesome and will be on my to do list... but first, does this handle Amazon accounts with 2-factor authentication?
autolog
Posts: 4077
Joined: Tue Sep 10, 2013 3:07 am
Location: West Sussex, UK
Contact:

Re: Alexa Notifications - Override/Reroute Speech Commands

Post by autolog »

mundmc wrote:This looks awesome and will be on my to do list... but first, does this handle Amazon accounts with 2-factor authentication?
Yes :)
Post Reply

Return to “Integrating Services/Applications”