Your own Raspberry Pi Google Assistant by Janne Spijkervet


ith the holiday season around the corner — there is some more time to do a DIY project. I’ll be trying to make my own home a little smarter, using a Raspberry Pi as the main home controller. The Google Home and its smaller brother are beautiful devices with many amazing features.

In this article, I’ll lay out the steps I’ve taken to install the Google Assistant on a Raspberry Pi. You will be able to have the following functionalities:

  • Google Assistant (most features, except media playback on the Pi)
  • Voice / Hotword activation: “Hey Google” or “Ok Google” and ask the question
  • Initialized on boot with a service, so you do not have to manually start the program every reboot

Step 0: What you will need

  • Raspberry Pi 2 or 3
  • Micro SD card (minimum 8GB) with Raspbian installed (or any other Debian-based distribution)
  • USB microphone
  • A speaker

Step 1: Registering your Device

  1. Go to to register your project on the Google Actions Console.
  2. Next, go to to enable the Google Assistant API.

Make sure to select your newly created project in the selection panel next to the Cloud Platform logo!

3. Select the API & Services tab and search for and enable the Google Asssitant API

4. Make sure to enable all settings in so the API works correctly.

5. Go back to to register your Raspberry Pi device in the bottom right corner of the applications panel.

6. Download the credentials file so we can use them later on. We do not need to setup any of the traits.

Step 2: Audio setup

  1. Make note of the cards / device numbers of your audio devices by using:
arecord -l
aplay -l

2. Use the information to edit the asoundrc file:

nano /home/pi/.asoundrc 

pcm.!default {
  type asym
  capture.pcm "mic"
  playback.pcm "speaker"
pcm.mic {
  type plug
  slave {
    pcm "hw:<card number>,<device number>"
pcm.speaker {
  type plug
  slave {
    pcm "hw:<card number>,<device number>"

3. You can then test your devices using:

speaker-test -t wav

arecord --format=S16_LE --duration=5 --rate=16000 --file-type=raw out.raw 

aplay --format=S16_LE --rate=16000 out.raw 


Step 3: Installing the Google Assistant Library

  1. Set up the directories where we will install our virtual environment to:
mkdir ~/googleassistant

nano ~/googleassistant/credentials.json

2. We will be using a virtual environment so our global environment does not become cluttered. Install venv with:

sudo apt-get install python3-dev python3-venv

3. Initialise the environment, install the latest version of pip and activate the environment with:

python3 -m venv env && env/bin/python -m pip install --upgrade pip setuptools --upgrade && source env/bin/activate`

4. Now we can install the Google Assistant Library for Python:

python -m pip install --upgrade google-assistant-library google-assistant-sdk[samples]

Step 4: Authorizing the Pi for the Google Assistant

  1. Let’s install the authorization tool so we can authorize with the Google Assistant API we just enabled for our application:
python -m pip install --upgrade google-auth-oauthlib[tool]

2. The following will give us an authorization url:

google-oauthlib-tool --client-secrets ~/googleassistant/credentials.json \
--scope \
--scope \
--save --headless

3. You may get the following OAuth error:

4. To solve this, we can setup the consent screen for the application by going to Credentials -> OAuth Consent Screen on the Google Cloud Platform(Again, make sure to select your application!)

5. When filling in the authorization code, you will see:

Step 5: PortAudio errors

  1. You may encounter the following PortAudio error:

2. Install the dependency:

sudo apt-get install libportaudio2

3. To disable dropouts and delays in the audio signal, comment out the following in /etc/pulse/ :

4. Also run PulseAudio system-wide to avoid issues with the Google Assistant daemon:

sudo nano /etc/systemd/system/pulseaudio.service

5. Add the following lines:

Description=PulseAudio Sound Server in system-wide mode
ExecStart=/usr/bin/pulseaudio --system --disallow-exit=1 \ 
--disable-shm=1 --fail=1 --daemonize 


6. Enable the service and add the pi user to the pulse-access group:

sudo systemctl --system enable pulseaudio.service
sudo adduser pi pulse-access

7. Disable the following module to avoid audio delays in /etc/pulse/

#load-module module-suspend-on-idle

sudo nano /etc/systemd/system/assistant.service

Step 6: Turn the Assistant into a service

  1. Create a file ~/, using the device model ID obtained from the Google Action platform:
source /home/pi/googleassistant/env/bin/activate
googlesamples-assistant-hotword --device-model-id <your_device_model_id>

2. Make the script executable:

chmod +x

3. Create a service file in /etc/systemd/system/assistant.service

Description=Google Assistant

ExecStart=/bin/bash /home/pi/


4. Enable and start the service:

sudo systemctl enable assistant.service
sudo systemctl start assistant.service


Now you can enjoy the Google Assistant on your Raspberry Pi by querying it using the hotwords “Hey Google” or “Ok Google”. You can also register the device in the Google Assistant app on iOS or Android.

You can also make your own custom actions using Google Actions, e.g. opening garage doors, controlling your coffee machine, changing the lights. You name it :) — I look forward to hear about what home automation projects you are doing!

Originally posted at:

July 17, 2019
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
© HAKIN9 MEDIA SP. Z O.O. SP. K. 2023