Hands Free Google Assistant for Raspberry Pi

72,702

672

365

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

5 People Made This Project!

Recommendations

  • PCB Contest

    PCB Contest
  • Make it Glow Contest 2018

    Make it Glow Contest 2018
  • Toys Contest

    Toys Contest

365 Discussions

0
None
Keekz

Question 12 days ago

Hi
I did all the steps, but in src/main.py step , I am getting ERROR:main:Unknown trigger 'ok-google'
Please advise .
Thanks,

0
None
TobyH18

Question 5 weeks ago on Step 12

TypeError: __init__() got an unexpected keyword argument 'serialized_options'



i get this after i do src/main.py in testing step?????

1 more answer
0
None
VesaM2TobyH18

Answer 18 days ago

pip install -U protobuf worked for me. It updated protobuf

0
None
AkhilR42

Question 4 weeks ago

after doing all the steps , i m also getting the same error.
TypeError: __init__() got an unexpected keyword argument 'serialized_options'

i had repeated 4 times with 4 new projects from google console and still i m having same problem.

please help me ....

1 more answer
0
None
VesaM2AkhilR42

Answer 18 days ago

pip install -U protobuf
worked for me. It updated protobuf

0
None
vigneshG11

4 weeks ago

after doing all the steps , i m also getting the same error.
TypeError: __init__() got an unexpected keyword argument 'serialized_options'

i had repeated 6 times with 2 new projects from google console and still i m having same problem.

please help me .... please AS FAST AS YOU CAN THROUGH MY EMAIL [jivi3411@gmail.com].....please hurry up i need this urgently !!!!!

1 reply
0
None
VesaM2vigneshG11

Reply 18 days ago

pip install -U protobuf

worked for me. It updated protobuf

0
None
TobyH18

Question 6 weeks ago on Step 10

I believe I did the audio config right but when I try the "check audio" app it flash a terminal and then nothing???

1 more answer
0
None
LukeK1990TobyH18

Answer 6 weeks ago

This is normal, the modifications we are doing to the AIY Kit software will break the check audio app but she should still work once you have completed all the steps.

0
None
giax1974

9 months ago

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

1 reply
0
None
apurioegiax1974

Reply 6 weeks ago

Just edit /home/pi/voice-recognizer-raspi/config/voice-recognizer.ini.default file, uncomment and modify the following line:

language = en-US

Currently the options are: de-DE, en-GB, en-US, es-ES, fr-FR and it-IT

0
None
JohanV113

7 weeks ago

Just finished this project and it's working fine, but when I use the English language to turn on my lights from Philps HUE it's working 100% but when I use the Dutch Language it say I can not help you with that. Is it possible that the Dutch language is not fully integrated in the API?

0
None
vincentdigitaal

2 months ago

nice thx a lot , is it possible to have a servo work? would want the servo to move when google talks. I would like to integrate this into a robot mouth. sorry for my bad English

0
None
ManfredS14

Question 3 months ago on Step 9

After the reboot, my pi has been stuck at bootloop. What to do??

0
None
Richard HansT

3 months ago on Step 2

why would anyone think it's a good idea to download some randomware and give it the most powerful access to everything in their personal network and devices????? Why isn't this software freely available from a known source, like sourceforge or github where a community of experts is willing to inspect it and declare whether or not it contains malware or spyware etc etc?

0
None
NivinA

Question 4 months ago

hi thanks for this tutorial i tried it the first time and it worked but with a usb mic. now i dont have a usb mic so can i use mic on my headset instead of a usb mic. i tried it already but but the audio check part is not working. how can i use a headset mic can you please tell me

0
None
kunupat

5 months ago

Hi,

Thanks for a great instructable! I have been trying to connect JBL Flip 3 (which is a Bluetooth speaker with inbuilt mic) to use Google Assistant on Raspberry Pi 3B that I have but no luck. It will be great if you can post how to achieve this. I am using Raspberry Pi3B with Raspbian Strech.

Thanks in advance!

0
None
MarcR74

Question 5 months ago

I want to use it like a real google home speaker (without keyboard, mouse and screen), but i think it's better to shutdown before unplug the power. Is it possible to shut it down with a "ok google" voice command ?

0
None
MarcR74

5 months ago

Great! Very nice job, I tried several tutorial to do it and it was missing each time information or steps, this is the only one to follow, clear, ordered and complete. Thank's, Marc.

Ps: I'll post " I made it! " later because i haven't a image to post for the moment

0
None
productionj

Question 6 months ago

Hello, Every things works fine but If I said "Hey google, play some music" google respond "Sorry,I don't know how to help with that yet"..

Songs,News,FM radio etc not working. Any help or suggestions for that..