• Skip to primary navigation
  • Skip to main content
  • Skip to footer

Miguel Ángel Antolín Bermúdez

Personal portfolio & Blog

  • Home
  • Blog & posts
You are here: Home / Engineering / how to / Google assistant on Raspberry pi

how to, Raspberry Pi, Software engineering / 28th January 2018

Google assistant on Raspberry pi

To install and set up Google assistant for Raspberry pi, you’ll need a Raspberry Pi 2 or 3, a Google developer account, a speaker and a microphone.

Optionally you can wire a LED to GPIO pin 25 and a button on GPIO 28 to add press to speak functions and a visual indicator.

Before you begin, you must configure the audio on the Raspberry Pi, it will make accessible your microphone and speaker to the Google Assistant instance:

Configuring the audio device

Locate your USB microphone in the list of capture hardware devices.

arecord -l

Locate your speaker in the list of playback hardware devices. 3.5mm-jack is usually labeled Analog or bcm2835 ALSA.

aplay -l

Create a new file named .asoundrc in the home directory (/home/pi), use the configuration below but replace <card number> and <device number>with the numbers that you’ve obtained on the previous step.

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>"
  }
}

Let’s check that we can play or record any sound:

Play a test sound with the following. (Ctrl+C to stop it).

speaker-test -t wav

Record a short audio clip & test the recording by playing it.

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

Configuring the project in our Google’s Developer Account

We need to create a Google Developer Project to be able to give to our device access to the Google Assistant API.

To enable access to the Google Assistant API, do the following:

  1. In the Cloud Platform Console, go to the Projects page. Select an existing project or create a new project. Go to the project’s page
  2. Enable the Google Assistant API on the project you selected. Enable the API
  3. Create an OAuth Client ID. Create an OAuth client ID
    1. You may need to set a product name for the product consent screen. On the OAuth consent screen tab, give the product a name and click Save.
    2. Click Other and give the client ID a name.
    3. Click Create. A dialog box appears that shows you a client ID and secret. (No need to remember or save this, just close the dialog.)
    4. Click ⬇ (at the far right of screen) for the client ID to download the client secret JSON file (client_secret_<client-id>.json).

You can also follow this steps –> https://developers.google.com/assistant/sdk/guides/library/python

Downloading and building the Assistant SDK

The downloaded JSON file client_secret_<client-id>.json, has to be renamed to assistant.json and copied to /home/pi/. Open a new terminal window in your raspberry and run the following:

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
ln -s assistant_library_with_local_commands_demo.py src/main.py
sudo apt-get install python3-dev python3-venv
python3 -m venv env
env/bin/python -m pip install --upgrade pip setuptools
source env/bin/activate
cd ~/voice-recognizer-raspi 
python3 src/main.py

On the first running of main.py it will prompt us with a link on the terminal to finish the connection with our Google Account and save the OAuth credentials, click on the link to grant all the needed privileges. Now we will be able to say “Ok, google” and ask our new assistant!

Now, we just finished with Google assistant Raspberry pi.

The next tutorial will be about how to code custom actions for Google Assistant.

If you want some more tutorials about Raspberry Pi, please check my blog posts.

This project is based on AIY Voice Kit .

Filed Under: how to, Raspberry Pi, Software engineering Tagged With: Google assistant, GPIO, Python, Raspberry

Footer

Find me at

  • GitHub
  • LinkedIn

Recent Posts

  • Passwordless auth through SSH
  • Raspberry Pi 4 Overclocked!
  • Raspberry 3B+ Overclock
  • Google assistant on Raspberry pi
  • Block ads anywhere with Pi-hole and a VPN

© 2020 · Made with ❤ in Seville