Google AIY Voice Kit

Part 2 – “Make it Automagic”

This article is picking up from where Part 1 left off, where we built up the system and got the demo program working.  If you’re coming in late, Part 1 can be found here – https://www.follandfamily.com/google-aiy-voice-kit-pt1/

This part is actually short and sweet, but Part 1 was so long that I decided to break it out.

Before we get started, I should mention that this stuff is for the Voice Recognizer API, not the Cloud Speech one.  Voice Recognizer is basically a pared-down Google Assistant with some hardware to play with, where Cloud Speech is geared towards developers (Cloud Speech is also not free).

This also doesn’t create a full-blown Assistant.  It can control your home automation stuff, but can’t talk to the Chromecast or play music (for example).  It also doesn’t show up in your Home app, making it difficult to control with other Assistant-enabled devices.

Anyway, it’s a good time to mention that before we begin, we should back up the SD card in case we really foul things up.  I like the  instructions at Pimylifeup. https://pimylifeup.com/backup-raspberry-pi/

First things first, it’s a good time to make sure everything is up-to-date (unless you’re coming straight off the last tutorial).

Connect to the Pi, and open up the terminal:

sudo apt-get update
sudo apt-get upgrade

Now, somewhere along the line (probably an update) something usually pukes and I get an error “No module named ‘google_auth_oauthlib’“.  What seems to be happening is that that the Assistant demo uses it’s own Python source code, but suddenly it’s trying to use the system implementation which breaks everything.  The fix, thankfully, is simple:

cd ~/AIY-voice-kit-python
source env/bin/activate
python3 src/assistant_library_demo.py

which forces the demo to use the proper Python.  You’ll probably have to do the python3 line for the other demos (replace the .py script name in the command line).  Hopefully this doesn’t hap pen to you, but keep it in mind just in case.  Note: after you’ve run this command sequence, run the demo without the python3, e.g.: just src/assistant_library_demo.py

And, we’re finally ready to get Voice started at boot.  There’s a bunch of things that need to happen, but thankfully it’s all automated.  Basically, we need to download a version of Voice Recognizer that runs stand-alone, and enable to run in the background.

So, in the terminal:  (Note: I’ve added blank lines to make it easy to differentiate the commands)

git clone -b voicekit https://github.com/google/aiyprojects-raspbian.git ~/voice-recognizer-raspi

cd ~/voice-recognizer-raspi

scripts/install-deps.sh

sudo scripts/install-services.sh

cp src/assistant_library_with_local_commands_demo.py src/main.py

sudo systemctl enable voice-recognizer.service

And wander off for a while.  The scripts take some time to run.  Like, a lot of ‘some time’.

Once the scripts are finally finished, sudo reboot and make sure everything worked as planned.  If it worked, the LED should be flashing, and you should be able to talk to it with “OK Google“.

Play with it for a while, and then shut down the computer with
“OK Google power off”
And this time, I highly recommend backing up the SD card, because when you break it in the future, you can always fall back to a pristine installation.

And we’re done (for now)!  I’ll make a new page and link it here as I add more features.

PS~ if you want to play with the demo scripts at this point, you need to stop the service that now runs at boot.  Starting and stopping commands are, respectively,

sudo systemctl stop voice-recognizer.service
sudo systemctl start voice-recognizer.service

Starting and stopping the service will not affect it starting again next time you boot.

PS here’s a small list of project ideas.  I have not tried any of them yet, so I can’t say they won’t  break stuff.  Keep backups of your SD card. http://ktinkerer.co.uk/list-mods-raspberry-pi-aiy-project/

PPS~ if an update breaks your Assistant, you should be able to restore it similar to how we fixed the demo:

cd~/voice-recognizer-raspi
source env/bin/activate
python3 src/main.py

Gateway to the Follandverse