DIY Google AI Assistant Using A Raspberry Pi

Introduction

 
This article demonstrates how to build and set up Pi-powered Google Assistant, also known as Google Home. This is early adoption of integrating Google Home to the Raspberry Pi.
 

Google Assistant

 
Google Home speakers enable the users to give voice commands to interact with services through Google's personal assistant software called Google Assistant.
 
DIY Google AI Assistant using a Raspberry Pi
 
Equipment List
  • Raspberry Pi 2 or 3
  • Micro SD Card
  • USB Microphone
  • Speakers 
Step 1
 
Register and set up a project on the Google Action console. You must have logged into your Google account and you will be greeted with the following screen to create a new project. Here, our project name is Ras-Pi and then, click the "Create" button.
 
DIY Google AI Assistant using a Raspberry Pi 
 
Navigate to the credentials page and enable the Google Assistant API before you go to select the project.
 
DIY Google AI Assistant using a Raspberry Pi 
 
Select OAuth consent screen and create a new application with a name same as the project name.
 
DIY Google AI Assistant using a Raspberry Pi
 
Click the drop-down button and select the client ID.
 
DIY Google AI Assistant using a Raspberry Pi 
 
After that, select the application type. This is the Linux operating system, so select the "Other" option.
 
DIY Google AI Assistant using a Raspberry Pi 
 
Provide the code for client ID and client secret.
 
DIY Google AI Assistant using a Raspberry Pi 
 
Step 2 
 
Download the JSON file in Raspberry Pi. The download location is "home/pi/Downloads".
 
DIY Google AI Assistant using a Raspberry Pi
DIY Google AI Assistant using a Raspberry Pi 
 
Go to the following link https://myaccount.google.com/activitycontrols to enable the voice and audio activity.
 
DIY Google AI Assistant using a Raspberry Pi 
 
Step 3
 
Open Noobs terminal or Putty. To learn how to connect putty, refer to my article Lightweight Raspberry Pi 3 Web Server Using PHP And HTML and install the latest Python IDE.
  1. sudo apt-get install python3-dev python3-venv  
Set up the Python IDE.
  1. python3 -m venv env  
Upgrade the Python setup tool and activate.
  1. env/bin/python -m pip install --upgrade pip setuptools --upgrade  
  2. source env/bin/activate  
DIY Google AI Assistant using a Raspberry Pi
 
Download the following library for Google Assistant.
  1. python -m pip install --upgrade https://github.com/googlesamples/assistant-sdk-python/releases/download/0.3.0/google_assistant_library-0.0.2-py2.py3-none-linux_armv7l.whl  
 DIY Google AI Assistant using a Raspberry Pi
 
Install the Google Authentication Library tool.
  1. python -m pip install --upgrade google-auth-oauthlib[tool]  
Step 4 
 
Obtaining an authentication key, replace the idxxx with your client Id file. 
  1. google-oauthlib-tool --client-secrets /home/pi/Downloads/client_secret_client-idxxx.json --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save --headless  
Google APIs provide the authorization link. Then, browse the given link to generate the authorization key.
 
DIY Google AI Assistant using a Raspberry Pi 
DIY Google AI Assistant using a Raspberry Pi 
Copy this code and switch to your application and paste. 
  1. Enter the authorization code :  XXXXXXXXXXXXXXXX  
Output
 
If you ask a question, the Assistant will reply.
 
DIY Google AI Assistant using a Raspberry Pi
 
See the EventType for details on all events and their arguments.
 
"What time is it?" -> "The time is 9:02 PM"
                              or 
"Set a timer" -> "Okay, for how long?" ->
"5 minutes" -> "Sure, 5 minutes, starting now!"
 

Summary

 
Finally, we have successfully created a DIY Google AI Assistant using Raspberry Pi.