Turn your Raspberry Pi into homemade Google Home

Keval Patel
Jul 8, 2017 · 7 min read

Google Home is a beautiful device with built-in Google Assistant — A state of the art digital personal assistant by Google. — which you can place anywhere at your home and it will do some amazing things for you. It will save your reminders, shopping lists, notes and most importantly answers your questions and queries based on the context of the conversations.

In this article, you are going to learn to turn your Raspberry Pi into homemade Google Home device which is,

  • Powered by Google Assistant.
  • Voice activated. No need to press any button, just say “Ok Google” or “Hey Google” and ask your question.
  • There will be a LED indicator which will stay on whenever the conversation between the user and the Google Assistant it in progress.
  • It can initialize on boot so no need to login and run the script from terminal after reboots.

So, let’s get started.

What things will you need?

  • MicroSD card with Raspbian on it (Minimum 8GB recommended).
  • Power supply to feed your raspberry pi. (Any USB mobile charger with minimum 5V, 2A output will work.)
  • USB mic (As Raspberry Pi doesn’t have an inbuilt mic. I used MI-305).
  • A speaker.
  • A LED.
  • A couple of wires to connect LED.

Once you have all these things, login to Raspbian desktop and go to the following steps one by one.

Step -1: Setting up USB mic.

  • Plug your USB mic into any of the USB slots of your Raspberry Pi.
  • Go to the terminal and type following command.
  • This command will list all the available audio record devices. You should get below output.

As you can see your USB device is attached to card 1 and the device id is 0. Raspberry Pi recognizes card 0 as the internal sound card (which is bcm2835) and other external sound cards as external sound cards.

  • Now, let’s change the audio configs. Type below command to edit the asound.conf file.
  • Add below lines in the file. Then press Ctrl+X and after that Y to save the file.

This will set your external mic (see pcm.mic) as the audio capture device (see in pcm!.default) and your inbuilt sound card (card 0) as the speaker device.

  • Create a new file named .asoundrc in the home directory (/home/pi) by issuing following command and paste above configurations (which you added in /etc/asound.conf file.) to this file.

Step -2: Setting up your speaker output.

  • Run below command to open raspberry pi configuration screen.
  • Go to Advanced Options > Audio and select the desired output device.

Step -3: Test the mic and speakers.

  • To test your mic run following command. This will record a short audio clip. If you get any error check step 1 again.
  • Play the recorded audio and confirm everything works correctly by issuing following command.

Okay. Our hardware is set.

Step -4: Download required packages and configure Python environment:

  • Run below command one by one in the terminal.

This will create Python 3 environment (As the Google Assistant library runs on Python 3.x only) in your raspberry pi and install required dependencies.

  • Activate the python environment.
  • Now, install the Google Assistant SDK package, which contains all the code required to get the Google Assistant running on the Raspberry Pi. It should download the Google Assistant Library and the demo.

Step -5: Enabling the Google Assistant cloud project.

  • Head over to API manager and enable the Google Assistant API.
  • - Make sure that you enable Web & App Activity, Device Information and Voice & Audio Activity in Activity Controls for the account.
  • - Go to “Credentials" and set up OAuth Content Screen.
  • Go to “Credentials” tab and Create new OAuth client ID.
  • Select application type as “Other” and give the name of the key.
  • Download the JSON file that stores the OAuth key information and keep it safe.

Step -6: Authenticating your Raspberry Pi.

  • Run the tool by running following command. Make sure you provide correct path for the JSON file you downloaded in step 5.
  • It should display as shown below. Copy the URL and paste it into a browser (this can be done on your developmen

If instead, it displays: InvalidGrantError then an invalid code was entered. Try again.

Step -7: Setting up the LED indicator.

  • The idea here is simple. We are going to set the GPIO pin 25 as the output pin. Google Assistant SDK provides a callback EventType.ON_CONVERSATION_TURN_STARTED when the conversion with the Google Assistant begins. At that point, we are going to set the GPIO 25 to glow the LED. Whenever the conversation terminates EventType.ON_CONVERSATION_TURN_FINISHED callback will be received. At that point, we will reset the GPIO 25 to turn off the LED.

Step -8: Initialise on boot complete:

  • First add RPi.GPIO package to add GPIO support using following command.
  • Go to the user directory. Create new python file main.py.
  • Write following script and save the file.
  • Now create one shell script that will initialize and run the Google Assistant.
  • Paste below lines into the file and save the file.
  • Grant the execute permission.

You can run google-assistant-init.sh to initiate the Google Assistant any time.

Let’s see how you can start the Google Assistant while booting.

1. Autostart with Pixel Desktop on Boot:

  • This will start the Google Assistant as soon as Pixel desktop boots up. Make sure you have “Desktop” boot selected in Raspberry Pi configurations.
  • Type below command.
  • Add the following after @xscreensaver -no-splash
  • Save and exit by pressing “Ctrl+X” and then “Y”.

2. Autostart with CLI on Boot:

  • This will start the Google Assistant if you have set CLI boot. Make sure you have “CLI” boot selected in Raspberry Pi configurations.
  • Type below command.
  • Add below line at the end of the file.
  • Save and exit by pressing “Ctrl+X” and then “Y”.

That’s all!!! You “Homemade Google Home” is now ready. Reboot the device and ask your first question to your Google Assistant.


~If you liked the article, click the 💚 below so more people can see it! Also, you can follow me on Medium or on My Blog, so you get updates regarding my future articles!!~

Keval Patel

Written by

www.kevalpatel2106.com | Android Developer | Machine learner | Gopher | Open Source Contributor

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade