Introduction: Add Trigger Start Sound to Google AIY Voice Kit

About: Educator, designer, tinkerer.

This tutorial is pretty simple. I have been really enjoying the Google AIY Voice Kit, but really like on my normal Google Home's the noise they make to confirm that they are actively listening. This is not setup by default in any of the examples that are pre-loaded on the AIY Voice Kit image.

I'm also including a link to the stock Start and Confirm noises that I recorded from my actual Google Home's with my Zoom recorder.

Here we go—my first instructable!

Step 1: Required Materials & Files

  1. Fully functional Google AIY Voice Kit—to set up your kit visit the official AIY Voice Kit page.
  2. Ability to access your Pi's terminal via SSH, VNC, or with a monitor and keyboard
  3. .Wav file that you want to play when Pi is listening for voice input—If not using custom file, download standard "St art Talking" file here or download it from the attached link.
  4. (Optional) Audio editor that can convert files and change their bit and sample rate

Step 2: Step 2: Check Out the Voicehat.py File for More Information

IMPORTANT!

I'm not using the latest image on my voice kit that includes the code for both the Voice and Vision kit (i.e. aiyprojects-2018-01-03.img). I'm using the code from the Voice Kit branch that can be found on the Google AIY Raspbian GitHub. My personal opinion is to just use the Voice Kit branch to keep it simple and not need to deal with the Vision code when you are working with your voice kit.

Moving on...

This step is not totally mandatory, but it will show you where Google has buried the instructions for getting this working if you want to take this a step further or understand why the code I'm adding working.

pi@raspberry: cd AIY-voice-kit-python/src/aiy/

Then we are going to check out the voicehat.py file in that folder:

pi@raspberry: ~/AIY-voice-kit-python/src/aiy/sudo nano voicehat.py

The attached picture shows where you can learn about Status UIs and how to use a sound during the trigger.

Alright, now let's add some code to one of the example files to get this thing working.

Step 3: Step 3: Add Trigger Sound Code to Demo Code

First, navigate to the AIY-voice-kit-python folder and run the source code

cd AIY-voice-kit-python
source env/bin/activate
cd src

Then use 'sudo nano' into either 'assistant_grpc_demo.py' or 'assistant_library_demo.py'

The different between the two files is that assistant_grpc_demo.py uses the button to trigger Google Assistant and assistant_library_demo.py uses the activation word "Ok, Google" to trigger the Google Assistant.

For both of these files you only need to add ONE line of code:

status_ui.set_trigger_sound_wave('/home/pi/googlestart.wav')

This assumes you have placed your start sound in the /home/pi/ folder and named it googlestart.wav. Change these based on whatever you named your file and wherever you located it.

The line of code we are looking for is below:

status_ui.status('listening')

We want to add our new line of code BEFORE that line of code...

For the 'assistant_library_demo.py' example it can be found here:

elif event.type == EventType.ON_CONVERSATION_TURN_STARTED:
# And now add our code
    status_ui.set_trigger_sound_wave('home/pi/googlestart.wav')
    status_ui.status('listening')

For the 'assistant_grpc_demo.py' example it can be found here:

button.wait_for_press()
# And now add our code
status_ui.set_trigger_sound_wave('/home/pi/googlestart.wav')
status_ui.status('listening')

This assumes you have placed your start sound in the /home/pi/ folder and named it googlestart.wav. Change these based on whatever you named your file and wherever you located it.

Hit CTRL-X & Y to save everything.

***NOTE: I have found something a little goofy. For the 'assistant_library_demo.py' adding the trigger sound seems to not make any difference in the function of the speech recognition. For the 'assistant_grpc_demo.py' though, it seems when you have the trigger sound implemented it cuts off the first word or two that you say. Not totally sure why. Still trying to figure it out.

Step 4: Step 4: Run the Code and Make Sure Everything Is Good to Go

pi@raspberry: cd AIY-voice-kit-python

and load up virtualenv

pi@raspberry:~/AIY-voice-kit-python $ source env/bin/activate

and run it!

(env) pi@raspberry:~/AIY-voice-kit-python $ src/assistant_library_demo.py

or

(env) pi@raspberry:~/AIY-voice-kit-python $ src/assistant_grpc_demo.py

Now say "Okay, Google" or Press that Button and see if it works!

The next page will help you out if you have your own custom file and the appropriate bit and sample rates for your .wav file

Step 5: Step 5: Create Your Own .wav File

If you aren't interested in using my .wav file of the standard Google Home start sound, you'll need to create your own .wav file. It took a bit of trial and error to get the correct bit and sample rate to work for me.

I used Logic Pro X to do all my editing (pictured), which is a fully-fledged DAW for creating and producing music. Two options I have found that could be suitable are Switch or MediaHuman Audio Converter. I assume you could do this with Garageband if you have a Mac, but I haven't tried that out.

There are three key parts of your file that are needed for it to work with the demo code.

  1. Must be a MONO audio file
  2. Sample rate must be 32000
  3. Must be a .wav file
  4. (Optional) 16 bit resolution has worked best for me

Step 6: Step 6: Adding the Confirmation Sound?

This is where I am stuck if anyone has any thoughts. I would love to add the confirmation noise if the system recognizes the voice input like on a normal Google Home.

I have attached the stock Confirmation noise below for your convenience.

Enjoy!