Get CPR certified in 30 minutes at CPR Test Center.
Echo & Alexa Forums

Running Alexa from command line

0 Members and 1 Guest are viewing this topic.

Nathan

Running Alexa from command line
« on: May 17, 2017, 08:12:33 pm »
Hello,

As I said on a previous post, I bought Alexa with the express purpose of making an automated schedule of music without using any other device (like Sonos), and I am still filled with determination to get that to work.

One comment that was particularly useful directed me to the code of John Graves, which is a workaround for Push notifications.  This code interfaces with AVS, then obtains authentication code from Amazon's API for a specific Echo device to obtain the access token to interact with Alexa.

Having obtained the access token, Graves' code is able to run Alexa from command line:
Code: [Select]
./alexa.sh "tell me a joke"
However, I am stuck at this point for a couple of reasons:
1) The response from Alexa plays on my computer, not Echo. Graves recognizes this, and says you have to use bluetooth speakers. To me, this seems to completely defeat the purpose of Echo (the command is run from a computer, and only plays on a computer). Assuming I use this method, I would always need that computer up and running, and basically I could easily do the same thing on my own computer and throw Echo away.
2) Music doesn't play using this method. My computer says announces the music in Alexa's voice, but then doesn't do anything.

Is there a better way to control Alexa on command line, or is she not built for it?

Maybe I'll have to buy into Amazon's corporate schemes and hang up my CS degree for another day :(

meep

Re: Running Alexa from command line
« Reply #1 on: May 18, 2017, 05:02:47 am »
Hi Nathan

Got your PM and have arrived here.

I see what you mean when you say that the push notification workaround is not exactly want you need. I confess I have not implemented it, but I do have a good idea of how it works. I agree that it seems odd to be using a pc or other device and just using the echo as a speaker. However that solution has a specific purpose - to push spoken audio to an echo device that is indistinguishable from that presented by a skill for the purposes of providing updates to users. It would work in that context but does require additional hardware and doesn't play music, as you point out.

You will no doubt know that Amazon have themselves introduced push notifications (of a sort) this week. It's a half-baked attempt that essentially amounts to a message box - a skill can send a notification and the Echo will pulse green until the user asks 'what's new?' (or similar) resulting in the notification being delivered.

I guess to do what you envision, you'd probably need to build out a full skill of your own.

The Alexa skills kit (ASK) supports music playback through the echo. Within a skill, you can specify a single track or an .m3u playlist. Interestingly, from your requirements perspective, once a track/playlist is nearing completion, the echo will send a notification to your skill. I'm not 100% sure but I'd expect that the skill can then react to this event by sending the next track/playlist.

You could leverage this functionality for your needs. Once a track/playlist end notification arrives, check the time of day and use that to implement logic to pick the genre for the next batch of music.

That's broad strokes, of course and the devil would be in the detail, as they say. You won't have the ability to instantaneously push content to the echo from command line in this scenario but, if it suited your needs, you could send the notification to your skill which could queue it until the next 'end of track call in' event. Caveats abound!

I'm knee deep in skill development right now and the one thing I'm figuring out is that Alexa development is characterised by compromise. Once you can accept that, you'll have a lot of fun.

« Last Edit: May 18, 2017, 05:05:41 am by meep »

Nathan

Re: Running Alexa from command line
« Reply #2 on: May 18, 2017, 10:05:50 am »
Thanks for the advice :)

I don't have a bluetooth adapter on my PC (only my phone), so I can't fully implement the original workaround anyway.

I guess what I'm mainly confused about is why the command attempts to execute on the PC. If the command is sent to Alexa by sending a .mp3 through AVS, why wouldn't it then execute on the Echo? Other examples of the push notification workaround control the smarthome devices and such (looking at the YouTube demo), and surely those devices aren't controlled by your PC.

Who knows, with the rapid updates from Amazon recently, it could very well get that ability in the near future.

I have been very interested in the announcement of notifications for Echo (impeccable timing, at that), but I have a hard time wrapping my head around how that would be relevant to my scenario. Seems promising for sure.

Nathan