0% found this document useful (0 votes)
112 views13 pages

Pi Home, A Raspberry Powered Virtual Assistant: Instructables

A Raspberry Pi can be configured to function as a virtual assistant using the Google Assistant SDK. The document provides step-by-step instructions to set up the necessary hardware including a Raspberry Pi, USB microphone, and speakers. It then guides the user through installing software packages, setting up audio devices and authentication with Google, and implementing an LED indicator. Completing the guide results in a low-cost DIY virtual assistant using a Raspberry Pi that is comparable to commercial products like Google Home.

Uploaded by

Tom Dever
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views13 pages

Pi Home, A Raspberry Powered Virtual Assistant: Instructables

A Raspberry Pi can be configured to function as a virtual assistant using the Google Assistant SDK. The document provides step-by-step instructions to set up the necessary hardware including a Raspberry Pi, USB microphone, and speakers. It then guides the user through installing software packages, setting up audio devices and authentication with Google, and implementing an LED indicator. Completing the guide results in a low-cost DIY virtual assistant using a Raspberry Pi that is comparable to commercial products like Google Home.

Uploaded by

Tom Dever
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

instructables

Pi Home, a Raspberry Powered Virtual Assistant

by heroic_age

The Google Home is useful to have around the Google Home that responds to your voice
home.It is a beautiful device with built-in Google commands. Otherwise, it’s an Assistant with all the
Assistant — A state of the art digital personal features of Google Home. Which means it can do unit
assistant by Google. It can play media, save your conversions, play media, check scores, read audio
reminders and notes, tell you the length of your books to you, check the weather, and tons more. It
commute, do home automation.It can be placed will also work with a variety of home automation
anywhere at your home and it will do some amazing devices like smart light bulbs, so you can control
things for you, but, it’s an expensive proposition if them with your voice. Like the real Google Assistant,
you’re not sure you’ll use it. Good news though, you your DIY Google Home can be linked up to add more
can make a fully-functional one using a Raspberry Pi. features, like adding to-dos to Evernote or to get a
notification on your phone when the timer goes off.
By the end of this guide, you’ll have a fully functioning

Pi Home, a Raspberry Powered Virtual Assistant: Page 1


Step 1: Things You Need

You'd Need:

Raspberry Pi 3 or 2 with Raspbian installed, and Wi-Fi setup.


Power Supply and MicroUSB Power Cable. (Minimum 5V, 2A)
MicroSD Card. (Minimum 8GB)
A USB Microphone. (You will get plenty of how to setup's over the internet, also here...)
Speakers
A Keyboard and a Mouse for setup
A LED and couple of wires to connect

All the things gathered, connected and plugged in, Let's get it started.

6 5 4
7

2
3

1. Raspberry Pi 3B
2. USB Microphone
3. MicroSD Card(16 GB)
4. 3.5 mm jack
5. HDMI Cable
6. MicroUSB Cable
7. Power Supply
8. Speakers

Step 2: Setting Up USB Mic.

The Pi doesn’t have microphones inbuilt. You need to attach a USB microphone if you want to
record audio.
Plug your USB microphone into any of the USB slots of your Pi.
Type the following command in the terminal.

arecord -l

Pi Home, a Raspberry Powered Virtual Assistant: Page 2


This command will list all the available audio record devices. It will be empty if your USB mic in
connected. You should get following output.

pi@raspberrypi:~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

You can see that your USB device is attached to card 1 and the device id is 0. Raspberry Pi recognizes card 0 as
the internal sound card, that is, bcm2835 and other external sound cards as external sound cards named card 1,
card 2 and following...

Now, we'll have to change the audio configs. To edit the asound.conf file, type the following
command.

sudo nano /etc/asound.conf

Add below lines in the file. Then press Ctrl+X and after that Y to save the file.

pcm.!default {
type asym
capture.pcm "mic"
playback.pcm "speaker"
}
pcm.mic {
type plug
slave {
pcm "hw:1,0"
}
}
pcm.speaker {
type hw
card 0
}
ctl.!default {
type hw card 0
}

This will set your external mic (pcm.mic) as the audio capture device (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 were added in /etc/asound.conf file.) to this file.

sudo nano .asoundrc.

Pi Home, a Raspberry Powered Virtual Assistant: Page 3


Step 3: Setting Up Your Speaker Output.

Connect your speaker to 3.5mm headphone jack of the Raspberry Pi.


Run below command to open the pi's configuration screen.

sudo raspi-config

Go to Advanced Options > Audio and select the output device.(3.5mm jack or HDMI)

Pi Home, a Raspberry Powered Virtual Assistant: Page 4


Step 4: Test the Mic and Speakers.

To test your speaker run the following command in the terminal. This will play a test sound. Press
Ctrl+C to exit. If you are not able to hear the test sound check your speaker connection and power.
The test sounds like-

Front Left, Front Right

speaker-test -t wav

To test your mic, run following command. This will record a short audio clip of 5 seconds. If you get
any error check previous steps again.

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

Play the recorded audio and confirm everything works properly by typing following command.

aplay --format=S16_LE --rate=16k out.raw

Our hardware is set.

Pi Home, a Raspberry Powered Virtual Assistant: Page 5


Step 5: Download Required Packages and Configure Python Environment:

First, Update your operating system by running the commands one by one in the terminal.

sudo apt-get update


sudo apt-get upgrade

Running the commands one by one in the terminal will create Python 3 environment (The Google
Assistant library runs on Python 3 only) in your Pi and install required items.

sudo apt-get install python3-dev python3-venv


$ python3 -m venv env
$ env/bin/python -m pip install --upgrade pip setuptools

Activate the python environment. This will bring a "(env)" text in front of your Pi's command terminal.

source env/bin/activate

Install the Google Assistant SDK package, which contains all the code required to run the Google
Assistant on the Pi. It should download the Google Assistant Library and the significance.

python -m pip install --upgrade google-assistant-library

Pi Home, a Raspberry Powered Virtual Assistant: Page 6


Step 6: Enabling the Google Assistant Cloud Project.

Open the Google Cloud Console and create a new project. (Name it anything.) The account with
which you sign in will be used to send queries to Google Assistant and get your personalized
response.
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 Ac
tivity 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 saved.

Pi Home, a Raspberry Powered Virtual Assistant: Page 7


Step 7: Authenticating the Raspberry Pi

Install authorization tool by running below command.

(env) python -m pip install --upgrade google-auth-oauthlib[tool]

Run the tool by running following command. Make sure you provide correct path for the JSON file
you downloaded in step 6.

(env) google-oauthlib-tool --client-secrets "JSON_FILE_PATH" --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save --headless

It should display as shown below. Copy the URL and paste it into a browser. If instead, it displays:

InvalidGrantError

then an invalid code was entered. Try again.

Please go to this URL: https://...


Enter the authorization code:

Pi Home, a Raspberry Powered Virtual Assistant: Page 8


Step 8: Setting Up the LED Indicator.

Connect your LED between GPIO pin 25 and ground.


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.

Pi Home, a Raspberry Powered Virtual Assistant: Page 9


Step 9: Initialise on Boot Complete:

Whenever your Pi completes booting, we will run a python script that will verify and introduce the
Google Assistant on boot.
First add RPi.GPIO package to add GPIO support using following command.

pip install RPi.GPIO

Run the steps one by one. Go to the user directory. Create new python file main.py.

cd /home/pi
sudo nano main.py

Write the linked script and save the file.

Now create one shell script that will initialize and run the Google Assistant.

sudo nano google-assistant-init.sh

Paste below lines into the file and save the file.

#!/bin/sh
/home/pi/env/bin/python3 -u /home/pi/main.py

Grant the execute permission.

sudo chmod +x google-assistant-init.sh

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

Pi Home, a Raspberry Powered Virtual Assistant: Page 10


Download
https://www.instructables.com/ORIG/FI1/OMEJ/JQMO8NR8/FI1OMEJJQMO8NR8.zip

Pi Home, a Raspberry Powered Virtual Assistant: Page 11


Step 10: Starting the Google Assistant While Booting

To enable Google Assistant on Boot there are two ways. Let’s see each of them.

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.

sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart

Add the following after @xscreensaver -no-splash

@lxterminal -e "/home/pi/google-assistant-init.sh"

Save and exit by pressing “Ctrl+X” and then “Y.

2. Autostart with CLI on Boot:(I personally used this, though autostart works quit fine.)
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.

sudo nano /etc/profile

Add below line at the end of the file.

sudo /home/pi/google-assistant-init.sh

Save and exit by pressing “Ctrl+X” and then “Y”.

Pi Home, a Raspberry Powered Virtual Assistant: Page 12


Step 11: Conclusion

What exactly is different about this Home Pi? off the light, checking the door, you can do it with
Nothing, except expenses. The end result is basically integrating Google Actions in your Google Assistant.
the same, you can activate your DIY Google Home If you have any trouble with starting the Google
by saying the wake word “Ok Google/ Hey Google,” Assistant, leave a comment below. I will try to resolve
and the device works just like a real Assistant.You them as much as I can.
can do many daily activities with your Google Home.
If you want to perform your custom tasks like turning

This is super interesting, but I have one question. Since you are inputting code to make it work,
does this mean it is possible to change its name? Where in the code would I change it so I can say
"hey, JARVIS" instead of "hey, Google". Dumb question, I know, but if it is possible, I am seriously
doing this! Ha!
very interesting

Thanks Bro. Keep your support and I'll continue sharing more interesting projects.

Great first Instructable. Thanks for sharing with the community.

Thanks for supporting.

Pi Home, a Raspberry Powered Virtual Assistant: Page 13

You might also like