Pi Home, A Raspberry Powered Virtual Assistant: Instructables
Pi Home, A Raspberry Powered Virtual Assistant: Instructables
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
You'd Need:
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
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@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.
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 raspi-config
Go to Advanced Options > Audio and select the output device.(3.5mm jack or HDMI)
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-
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.
Play the recorded audio and confirm everything works properly by typing following command.
First, Update your operating system by running the commands one by one in the terminal.
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.
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.
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.
Run the tool by running following command. Make sure you provide correct path for the JSON file
you downloaded in step 6.
It should display as shown below. Copy the URL and paste it into a browser. If instead, it displays:
InvalidGrantError
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.
Run the steps one by one. Go to the user directory. Create new python file main.py.
cd /home/pi
sudo nano main.py
Now create one shell script that will initialize and run the Google Assistant.
Paste below lines into the file and save the file.
#!/bin/sh
/home/pi/env/bin/python3 -u /home/pi/main.py
You can run google-assistant-init.sh to initiate the Google Assistant any time.
To enable Google Assistant on Boot there are two ways. Let’s see each of them.
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.
@lxterminal -e "/home/pi/google-assistant-init.sh"
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 /home/pi/google-assistant-init.sh
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.