Signalling the mirror when Alexa listens

Editing the Java Client code to send messages when Alexa listens.

Advertisements

In this article I’ll be showing you the steps I took to signal the mirror when Alexa starts and stops listening.  Well, actually, I’m not alerting the mirror just yet, I’m sending a message to the debug hub.

In my last post I showed you how I was able to make a connection from the Java client to the debug hub using HTTP.  That’s great, but it was a quick and dirty solution.  We’re going to make this a bit more robust. I’ll start by adding a new class the the com.amazon.alexa.avs package, and call it “MirrorInterface“.  You can see it near the bottom of the screenshot:

Schermafbeelding 2017-01-25 om 20.19.02.png

The content is pretty simple.  I’ll be using the code to send the message and encapsulate it into a private method like so :

Schermafbeelding 2017-01-25 om 20.18.27.png

Notice how I already added support for both a command and extra content.  For now I’ll be focussing on only a command.  Also, the URL is added hardcoded too.  I plan on reading this from a config file, but that’s only a “nice to have” right now.

I intentionally made it private as the public methods all refer to this one.  I created a few, each serving their own purpose :

Schermafbeelding 2017-01-25 om 20.18.08.png

Notice the “VoiceActivated” and “VoiceDeactivated” methods.  I’ll be incorporating them in the code of the Java Client.  If you look in the “AVSController” java file you will see the following method overrides : “recordingStarted” and “recordingEnded”.  They get called whenever Alexa starts to listen, and stops listening.   That’s where I’ll be adding my code :

Schermafbeelding 2017-01-25 om 20.17.29.png

And that’s it.  I issue a question to Alexa, and voila, the result in the debug hub.

Schermafbeelding 2017-01-25 om 20.17.14.png

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s