Hands Free Google Assistant for Raspberry Pi

59,711

658

326

Published

Introduction: Hands Free Google Assistant for Raspberry Pi

About: Nerdy, Quirky, 3D Obsessed.. If you have a question regarding one of my Instructables please ask, I am happy to help!

Hello and welcome to my first Instructable!

In this instructable I am going to show you what I consider to be the easiest way to install an all singing, all dancing Google Assistant on your Raspberry Pi. She is completely hands free with the OK Google command and she starts up automatically when you boot up your Pi. She's super cool and seriously easy to setup!

So how's this all possible?

A short while ago Google released a do-it-yourself AI kit with issue #57 of The Magpi. This made it extremely easy to create your own Google assistant however getting hold of the voice kit was little bit harder and in many places it sold out within hours.

Fortunately, Google made all the software available online complete with full instructions. This meant that we did not need a copy of The Magpi to take advantage of all that hard work.

Despite this, there doesn't appear to be any clear instructions online on utilizing the voice kit without a copy of the magazine or without the hardware that was shipped with it. Instead, most of the tutorials attempt to install everything from scratch often resulting in mess of code that's impossible to follow for non-coders like me.

And that's where this Instructable comes in. It is the outcome of 2 days hard work looking at hundreds of tutorials, videos and posts online. The result is a stable Google Assistant which runs on startup and is voice activated with the 'OK Google' hotword.

What’s required?

To complete this Instructable successfully you will need the following:

  • A Raspberry Pi 3 (with the usual microSD card and power cord). *Thank you to MichaelW142 who has confirmed that this also works with Raspberry Pi 2.
  • A basic speaker with a 3.5 mm aux connection
  • A USB microphone
  • A mouse and keyboard

Step 1: Formatting the SD Card

The very first thing that we need to do is to format our SD card. Let’s use the SD Association's Formatting Tool which is recommended by the official Raspberry Pi Foundation.

Once installed, launch the application and click ‘Option’ You need to change the option for ‘FORMAT SIZE ADJUSTMENT’ to ‘ON’.

Now click ‘OK’ and double check that we are formatting the correct drive, then click ‘Format’. This shouldn’t take too long, just wait for the confirmation that the drive was formatted successfully before you move onto the next step.

Step 2: Preparing the SD Card

Next we need to download the Voice Kit microSD card image for the Raspberry Pi. You can download the image from my Google Drive.

In order to transfer the image that we just downloaded onto our SD card we are going to use a program called Etcher.io. It’s free, open source and does not require installation.

Once you’ve downloaded Etcher, run the program and you should see a screen like the one above. It can take a minute or two to load so if it doesn’t load right away be patient.

Click ‘Select image’ and navigate to the voice kit image that we just downloaded (aiyprojects-2017-05-03.img). Once selected double check that you are writing the contents onto the correct disk. Assuming that we have the correct disk selected then click ‘Flash!’.

It can take around 20 minutes or more to write the image to your SD card so feel free to go and make yourself a nice cup of tea and I will see you back here in a bit!

Step 3: Power Up That Pi!

As soon as the SD card is ready we can put the microSD card into our Raspberry Pi. At this point we also need to connect our power lead, HDMI cable, keyboard, mouse, monitor, speaker and USB microphone. Hopefully your setup should look something like mine.

I am using a wireless keyboard and mouse so don’t freak out if you end up with a couple of extra cables with your own setup!

With the power cable plugged in allow your Raspberry Pi to boot up and you will soon be presented with the standard Pixel desktop.

Step 4: Initial Configuration

Grab your cursor and navigate to the Raspberry Pi logo at the top left of your screen. From the dropdown select ‘Preferences’ and then ‘Raspberry Pi Configuration’.

Next, go to ‘Interfaces’ and enable 'SSH'.

Now click on the WiFi logo at the top right of the screen and select your WiFi network. If your WiFi is password protected you will prompted to enter that in. The green tick confirms that we connected successfully and we’re ready to move onto the next step.

Step 5: Updating the Installation

This is about as advanced as this tutorial gets. We are going to use the dev terminal to update the Google Assistant SDK, Project Kit & dependencies to ensure we have the latest versions. Do not panic if none of this makes much sense to you but it is essential that we do not skip this step. Just do exactly as this tutorial says being careful not to make any typos and it will all work out just fine.

So, panic over, let’s begin! Double click on the desktop icon name ‘Start dev terminal’.

You should see a scary looking dev terminal window like the one above.

Next type the following commands into the terminal exactly as they appear below. There are 9 commands here and each should be entered separately in the order in which they appear. After typing each command hit ‘Enter’ on your keyboard before moving onto the next one. Some of the commands will take a few seconds to complete so be patient waiting for each to finish before moving onto the next one.

cd ~/assistant-sdk-python
git checkout master
git pull origin master
cd ~/voice-recognizer-raspi
git checkout master
git pull origin master
cd ~/voice-recognizer-raspi 
rm -rf env
scripts/install-deps.sh

Step 6: Preparing the Configuration Files

Next we need to backup our existing configurations files and bring over the newest versions that were just updated. Here’s 4 more commands for you to do just that. These can be done in the same dev terminal that we were just using. Once again, they must be done in this order and should be typed precisely as they appear below:

cp ~/.config/status-led.ini ~/.config/status-led.ini~
cp ~/.config/voice-recognizer.ini ~/.config/voice-recognizer.ini~
cp ~/voice-recognizer-raspi/config/status-led.ini.default ~/.config/status-led.ini
cp ~/voice-recognizer-raspi/config/voice-recognizer.ini.default ~/.config/voice-recognizer.ini

Step 7: Setting Up the Hotword

Awesome work so far! We are getting really close now so hang in there.

We now need to change the trigger for our Google AIY project kit so that it responds to our voice when we speak the words ‘OK Google’.

Type the following command into the dev terminal:

nano ~/.config/voice-recognizer.ini

This will produce this even scarier window.

Within this new window, look for the following code:

# Select the trigger: gpio (default), clap, ok-google.
# trigger = clap

We need to change this code to:

# Select the trigger: gpio (default), clap, ok-google.
trigger = ok-google

If you use the arrow keys on your keyboard you will notice a curser appears. Using the arrow keys, bring the curser down to the line of text that we are trying to change. Using the backspace key on your keyboard delete the line of text that we are trying to change and retype it just like the example above.

Notice that I have also removed the # symbol, it is important we do not include the # in this new line of text.

I have attached a before and after screenshot of what this should all look like (encase I lost you there).

Assuming your window looks exactly like mine we can close and save the changes. Hold ‘Ctrl’ on your keyboard and press ‘X’ to close the window. We will then be prompted to save the changes we made, press ‘Y’ and then hit ‘Enter’ on your keyboard. The window will now close and the changes have been saved.

To ensure the changes have taken affect we need to restart the service. Type the following command into the terminal window and hit ‘Enter’:

sudo systemctl restart voice-recognizer.service

Step 8: Audio Configuration (Part 1)

Right now Google Assistant more or less alive and ready to serve.. Congratulations!

However, before you get too excited, you cannot hear each other. That’s because the Google AIY Project Image was configured to work with the hardware that was shipped with the kit. Since we are using a standard aux speaker and usb microphone we need to tweak some of the configuration.

Once again we will use the same dev terminal window, this time type:

sudo leafpad /boot/config.txt

This will open a text window. Scroll to the very bottom of the document and remove the # in front the the line dtparam=audio=on and insert a # in front of the two lines below it.

After you have made these changes it should exactly like this:

# Enable audio (loads snd_bcm2835)
dtparam=audio=on
#dtoverlay=i2s-mmap
#dtoverlay=googlevoicehat-soundcard

I have also attached a screenshot to show you what this will look like.

Go to ‘File’ then click ‘Save. You can now close the document.

Step 9: Audio Configuration (Part 2)

Back in the dev terminal again, type:

sudo leafpad /etc/asound.conf

When you hit ‘Enter’ a new text document will open. This time delete ALL the text within the document and replace it with the following:

pcm.!default {
type asym capture.pcm "mic" playback.pcm "speaker" } pcm.mic { type plug slave { pcm "hw:1,0" } } pcm.speaker { type plug slave { pcm "hw:0,0" } }

Again I have attached a screenshot showing you what this will look like.

Once again save and close the document.

Now it is time to reboot your Raspberry Pi. Click on the Raspberry Pi logo at the top left of your screen and click on ‘Shutdown’ then ‘Reboot’.

After you have rebooted the Pi we have just one more tweak to make. Double click on the ‘Start dev terminal’ icon once again and type the following:

leafpad /home/pi/voice-recognizer-raspi/checkpoints/check_audio.py

In this final document you need to locate the line of code that reads:

VOICEHAT_ID = ‘googlevoicehat’ 

Change this to:

VOICEHAT_ID = ‘bcm2835’

Once you have made these changes, just as we did before, save then close this document.

Step 10: Testing the Audio

On the desktop there is a file called ‘Check audio’. Double click on this and follow the prompts to ensure that both the speak and microphone is working.

If you followed this Instructable correctly there should be no problems. However if you cannot hear anything, double check that the volume is turned up and that your Raspberry Pi is using ‘Analog’ for sound output. You can do this by right-clicking on the sound icon at the top of the screen. ‘Analog’ should be ticked just like the example in the screenshot.

Assuming you passed the audio check, we can move onto the next step.

Step 11: Connecting to the Cloud

Before Google Assistant will give us answers to life’s burning questions we need to connect her to Google’s Cloud Services.

This is easy to do but if you haven’t been in the cloud before then it may seem a bit daunting at first.

Here’s what we need to do:

1) On the Raspberry Pi open up the Chrome internet browser and go to the Cloud Console: https://console.cloud.google.com/

2) Sign in with an existing Google account or sign up if you do not have one.

3) Create a new project and give it a name. I called mine ‘Google Pi

4) Using the search bar start typing ‘Google Assistant’ and you should see the ‘Google Assistant API’. Click on it and then when the next page loads click ‘Enable’ to activate the API.

5) Go to ‘API Manager’ then ‘Credentials’ and create an ‘OAuth 2.0 client’.

6) Click ‘Create credentials’ and select ‘OAuth client ID’. If you have never been in the cloud before then you will now be prompted to configure your consent screen. You’ll need to name your app, I called mine 'Raspberry Pi'. All other fields can be left blank.

7) In the Credentials list, find your new credentials and click the download icon on the right.

8) The chrome browser will now download a small JSON file with all your credentials stored safely inside. Find this file and rename it to ‘assistant.json’ then move it to /home/pi/assistant.json.

9) Finally, go to the Activity Controls page: https://myaccount.google.com/activitycontrols and turn on the following services: Web and app activity, Location history, Device information, Voice and audio activity. Be sure to log in with the same Google account as before!

If you got stuck at any point during this stage, do not freak out, Google has done an excellent job at documenting this process with screenshots for each step over on the Google AIY Kit website.

Step 12: Final Testing

If everything was setup correctly in the cloud we are now ready to talk to Google. Using the ‘Start dev terminal’ command window again, type the following:

src/main.py

This will wake up our assistant but since this is the first time that we are connecting to Google’s Services, a web browser will open and you will need to login to Google to give permission for the Raspberry Pi to access the Google Assistant API. Again making sure that you use the same Google account logins as you did before.

Once you have logged in successfully and granted permission you will be prompted to close the window. The command window will now look like the screenshot attached confirming that everything was setup correctly.

Go ahead, ask a question, she’s listening!

Before you get too excited though, we are not quite finished. When you have finished playing, close the window, to do this just use the white cross at the top right of the window.

Step 13: Setting Up Google Assistant on Startup

I promised you that our Google Assistant would startup automatically when we power up the Raspberry Pi. To do this, open a fresh command window using the ‘Start dev terminal’ icon on the desktop. Type the following line of code into your terminal window and hit ‘Enter’ on your keyboard:

sudo systemctl enable voice-recognizer

We just configured auto startup of our Google Assistant with one line of code.. How easy was that!!

Step 14: The Finish Line

Now that you have completed all the steps go ahead and reboot your Raspberry Pi. If you have followed all these instructions carefully then Google Assistant should be running in the background when the Pi loads up. Give it a try, say OK Google to wake her and ask her anything you like!

I really hope you liked this Instructable. It is a result of 2 days hard work and lots of online reading. I am definitely not a coder so I have tried to find the easiest and most logical way to get a working Google Assistant onto a Raspberry Pi and I believe this is it.

If you have any questions or suggestions with regards to this Instructable please let me know in the comments below. I would also love to hear how yours turned out.

I read a lot of tutorials, blog posts and forum entries but my biggest breakthroughs with this project came from 2 posts online that were both trying to accomplish similar tasks: http://eduncan911.com/stem/embedded/aiy-google-assistant-upgrades-may-2017.html and http://www.androidauthority.com/build-google-assistant-raspberry-pi-770296/. This Instructable is a result of figuring out how to put the two together in an easy and straight forward Instructable!

Extra Credits

- The Google Assistant SDK already has a huge number of features built-in however there are lots of 'mods' that you can add to the AIY Kit to give it some extra functionality. Ktinkerer has an up to date list of the latest mods available, check it out!Thank you cyberwolves for pointing this out :)

- How about a speaker enclosure for your squeeky new AI? Checkout this one by adylinn.

If you can think of anything else to add to this Instructable, please get in touch :)

First Time Author Contest

Runner Up in the
First Time Author Contest

4 People Made This Project!

Recommendations

  • Make it Move Contest

    Make it Move Contest
  • Casting Contest

    Casting Contest
  • Microcontroller Contest

    Microcontroller Contest
user

We have a be nice policy.
Please be positive and constructive.

Tips

15 Questions

0

Hi Everything seemed fine until I started to create my OAuth 2.0 client. I added the name but to save and leave the page I needed to choose app type. I chose other. After that I could follow the instructions with no issue. However at the when executing src/main.py (after granting permission I get the attached error message. Any thoughts on what could be wrong. Thanks for any help!

I cannot cd into voice-recognizer-raspi. I get the message "No such file or directory" -I have tried the both the 2017-09-11 and 2018-02-21 images and neither work. Can you help? Thanks.

0

This is going to sound silly, but I cant see the desktop icon 'start dev terminal' all I have got is a wastepaper basket. Can someone help me out, thanks

Hello, i'm new on this place. I tried to do the assistant project. Everything worked ok till the last instruction: src/main.py

I received this message:

(env) pi@raspberrypi:~/voice-recognizer-raspi $ src/main.py

[2018-04-02 20:49:29,522] INFO:urllib3.connectionpool:Starting new HTTPS connection (1): accounts.google.com

ERROR: failed to import the Google Assistant Library. This is required for

"OK Google" hotwording, but is only available for Raspberry Pi 2/3. It can be

installed with:

env/bin/pip install google-assistant-library==0.0.2

After this it is impossible to install it.

Can anybody help me?

0

Hi, Is there a possibility to change the default English language?

0

I went through the entire setup and everything seems to work, "ok google" wakes up the assistant but it promptly responds that there's a problem, glitch or whatever. so it's like the assistant has no connection to the internet.

0

OK, I was impatient, as I see your links to what you are using.


Having a problem with my mic, though. Not picking up sound (using webcam). Tried the fix by adding the .asound file, but no go. Will work on it later and let people know the outcome.

Really want to follow your build. Questions: What speaker are you using? What microphone are you using? Rather than WiFi, any differences if choosing to go hard-wired, other than leaving out SSID for WiFi? Thanks for your work. Looking g forward to completing my build after acquiring speakers and microphone.

0

pi@raspberrypi:~/voice-recognizer-raspi $ src/main.py

Traceback (most recent call last):

File "src/main.py", line 30, in <module>

import auth_helpers

File "/home/pi/voice-recognizer-raspi/src/auth_helpers.py", line 21, in <module>

import google_auth_oauthlib.flow

ImportError: No module named 'google_auth_oauthlib'

What can I do?

0

Anyone know the password for root and Pi ? trying to SSH in directly

0

pretty sure it's raspberry or Raspberry

Hi!
I have one off the google kits for this project, but I can't get it to start on start up, and I can't get this code to work, can you explain a litle bit better what is needed for it to work

Problem with running setup for grpcio
it is loading and loading.....

hello i can turn my volume up on the pi and the sound icon are there a read x over when i test aoudio is says Failed to find the voiceHAT soundcard. Refer to HACKING.md for how to
setup the voiceHAT driver: https://git.io/v99yK
Press Enter to close...


is that wrong hope you can help 8D

/home/pi/voice-recognizer-raspi: No such file or directory

udpated aiy image doesnt have any directory voice-recognizer-raspi
any fix>?

326 Comments

After this point my mic is not working how can I fix this issuce

Ty for your awesome project, i made it and work perfect. There is a solution for change the language to italian, france and others?

ATTENTION!

For any people that are copy pasting the commands, be careful:

When you need to write the line VOICEHAT_ID = ‘bcm2835’ ,

make sure that the quotes at the start and end of bcm2835 are correct! That's why when you run the python script, the command line says `SyntaxError: invalid character in identifier`

So, the correct line here is :

VOICEHAT_ID = 'bcm2835'

You can just copy paste that here!

Enjoy!

And if you run into any problems with the desktop icons not running, make sure that the shortcuts are pointing to the correct file using the text editor on the .desktop file.

Have fun!

Hi i'm Shahid Afridi

I have respeaker seeed-voicecard 2 mic hat

How can i use that respeaker seeed-voicecard 2 mic hat instead of the google voicehat soundcard ?

If you use the putty program, you can just copy/paste all those commands. You just have to find the pi's address, (I used the Fing app), and shh in using pi=user raspberry=password

hey great tutorial, so far ive only had one issue and that is with the sound, analog is ticked, ive gone back into the sound files that were edited and its the exact word/code for word/code. i am using the PI2 mod b. i have not gone passed this step. thanks for your help in advanced. using hdmi to monitor.

4 replies

i forgot to mention, no sound is playing when the check sound is executed. i have also tried playing audio through youtube and im getting nothing at all. either my audio track on the pi is busted or ive macked it :P

RIGHT CLICK ON YOUR VOLUME ICON AND CHANGE IT TO ANALOG

figured it out :) went into preferences/audiodevice settings/ select controls/ selected PCM and made it default and it came through :)

Hey Simon, glad you got it sorted.. Congrats. And thanks for posting the solution for others to see :)

So im at the final test when you type src/main.py and it gives me an error saying unknow trigger 'ok-google' anyone else have this problem. i did the step to add the ok-google to the file but not working

7 replies

Hi kevin31466 - I get the same error message ERROR:main:Unknown trigger ‘ok-google’

Did you find a solution to this? I’m stumped!

Hi,

You figure it out yet? I'm stuck here too!!!

I did a clean install and it worked for 5 min, then I had mic issues with the Jabra 510. I haven't had luck with usb audio or 3.5mm jack audio, just Bluetooth audio.

No, I’m afraid not! In desperation, I re-installed the image, reset everything to the way it was before, then went through every step again, making sure I put in the extra step for the mic in the home/pi/asoundrc file, and.... came to the same error message! I’m not sure I know enough to do or suggest anything else?... unless someone else can help...!

Hey Kevin,

Any luck finding a solution? I'm in the same boat.

Cheers,

I am having the same problem...

I'm not much of a gadgets person though. I see that at step 7 my version did not have the 'ok google' part of the code. This could be the problem. I have not found a solution though

hmm... After trying the same thing multiple times, I must have gotten lucky and it seemed to work. The only thing was that in step 7 I added in the okay- google part of the code, like shown in the screenshots. Then I just followed the rest of the instructions as I did before. I did have to start from scratch though...

Hope this helps!

I'm having some troubles and was hoping to find a solution from somebody. I followed all the oauth instructions thoroughly. When i try to run main.py, i get the error:

File "src/main.py", line 30, in <module>

import auth_helpers

File "/home/pi/voice-recognizer-raspi/src/auth_helpers.py", line 21 in <module>

import google_auth_oauthlib.flow

ImportError: No module named 'google_auth_oauthlib"

I tried recreating my credentials to no avail. Hopefully i can find a solution.

1 reply

Hi Madison, can you confirm the file name of the disk image you are using?