Indicate Device State with Sounds
Modify your UImanager file
When your customer speaks the wake word "Alexa", they'll want an indicator that your product heard them. This may be an LED activating or changing color on the device. But what if your customer puts your product up on a high shelf, around the corner, or somewhere they can't see it? Maybe there just wasn't a good place on your product to put some LEDs? In this case, you may want your device to play an audio cue to confirm when Alexa recognizes the wake word.
Amazon provides a library of sound clips for you to use when designing your product. Your commercial device should behave consistently with other AVS products so your customer can easily understand the device state. In this step, you'll modify the User Interface Manager to play a Wake sound each time Alexa's state changes to
First, you'll need to download the sound library. From your AVS Dashboard, click on your Resources tab next to Analytics Dashboard under your Alexa Voice Service link.
Scroll down until you see the Alexa Sound Library for AVS box, click on the View box, then click "Download" to get the library onto your Pi. Navigate to your /home/pi/Downloads folder in the file explorer, and right-click on the zipped archive and select Extract Here.
Now, you have local copies of the key sounds you'll use to inform users of your product state. Open the "Key Sounds for AVS" folder and copy the file med_ui_wakesound.wav. Paste a copy of this sound into your /home/pi/sounds folder - this is the path we'll point to later when we're ready to play the sound!
In the File Manager, navigate to /home/pi/avs-device-sdk/SampleApp/src/ and open UIManager.cpp with a text editor.
Near the top of the file where you see the other #include statements, add
#include <cstdlib>. This will enable the play function that you'll add in the next step.
You'll need to find the right UX State and add a path to the Wake Sound .wav file to enable your audio cue. Near the bottom of UIManager.cpp in the
printState() function, where it says
case DialogUXState::LISTENING:, add the following command:
Don't forget to save your text file before closing it! If you get a "Save As…" dialog and are unable to save the file as the same name, you'll need to update ownership permissions. In the terminal, type the following and hit return:
sudo chown -R pi:pi /home/pi
After successfully saving UIManager.cpp you'll need to rebuild the Sample App for the changes to take effect. First, quit out of your existing instance of the Sample App (if it's still running) by typing q in the terminal and hitting return. Still in the terminal window, input the following command to rebuild the Sample App:
cd /home/pi/build/SampleApp sudo make
It'll take a minute to rebuild with the changes you made to UIManager.cpp. Once you get to 100%, restart your Sample App by initiating the startsample.sh script in a terminal:
cd /home/pi/ sudo bash startsample.sh
Every time you speak the wake word "Alexa" to your prototype (Alexa's state changes to "Listening…") you should hear the wake sound play, indicating that your client device has opened a channel to the cloud. If you initiate a multi-turn interaction, you'll also hear the sound when Alexa is awaiting your answer. In the terminal window, you'll see the following message when your sound clip is successfully played.
Have fun modifying the UI Manager on your prototype - feel free to get creative and experiment with different sounds at various states. Share what you've built by sending us a link via the feedback button!
Ready for more Advanced Pi tutorials? Click the Next button below to learn how modifying your Alexa Focus Manager Library can enhance product-specific use cases!