Build your own Google Home using a Raspberry Pi

If you need a project for the Raspberry Pi you have lying around, you could always turn it into a DIY Google Home.
With a minimal amount of hardware and setup, you can create a functioning home assistant linked to your Google account and controlled by voice commands.
Follow the steps below to install the Google Assistant SDK on your Raspberry Pi and set it up to listen for voice commands.
Hardware
To set up a Raspberry Pi with Google Assistant, you will need the following:
- Raspberry Pi 2 or 3
- Power Supply
- microSD card with NOOBS installed
- USB microphone
- Speaker
- Ethernet/Wi-Fi connection
Connect peripherals to your Pi for initial setup and use the NOOBS image on your SD card to install a clean version of Raspbian.
After setting up Internet access and a new Raspbian installation on the Pi, you can move on to set up the audio devices.
Audio
Connect your USB microphone and speaker, and test to see whether the devices are working properly.
Start up the Terminal application on your Pi. All setup procedures will be done through this command line interface.
Check to see if your speaker is working by inputting the following into the terminal:
speaker-test -t wav
To check if your microphone is working properly, input the following to record a short clip:
arecord –format=S16_LE –duration=5 –rate=16000 –file-type=raw out.raw
And then input the following to play back the recording:
aplay –format=S16_LE –rate=16000 out.raw
If you have an HDMI display connected to your Pi, you can also choose to play audio out to the monitor it is connected to.
Developer Project
To install the Google Assistant SDK, you will need to set up a Google Developer Project.
Follow the steps below to set up a Developer Project.
- Open a web browser on any device and log in to your Google Account.
- Head to the Google Cloud Platform and select the option to create a new project.
- Name and create your project, then select the Google Assistant API and enable it for your project.
- Click on the OAuth consent screen tab and give your product a name, then press Save.
- Create an OAuth ID.
- Select the Other option and give your client ID a name.
- Select Create and close the dialog that appears.
- Click on the Download JSON button to the right of the OAuth ID.
This JSON file authorises a device to use the Google Assistant SDK. Move this file to your Raspberry Pi’s local storage under “/home/pi”.
To enable all the Google Assistant, you will need to share the activity data of your Google account you want to use with the Assistant SDK.
Open your account’s Activity Controls and ensure the following options are enabled.
- Web & App Activity
- Include Chrome browsing history and activity from websites and apps that use Google services
- Device Information
- Voice & Audio Activity
After your account has been set up, you can move back to your Pi terminal and prepare to install the Assistant SDK.
SDK Setup
Open a terminal on the Pi and run the below commands in order:
git clone https://github.com/google/aiyprojects-raspbian.git ~/voice-recognizer-raspi
cd ~/voice-recognizer-raspi
scripts/install-deps.sh
sudo scripts/install-services.sh
cp src/assistant_library_with_local_commands_demo.py src/main.py
sudo systemctl enable voice-recognizer.service
Google Assistant SDK should now be installed on your system and will run automatically when the Pi boots up.
To enable wake word detection and voice recognition, run the following commands in order:
cd ~/voice-recognizer-raspi
source env/bin/activate
python3 src/main.py
Now that Google Assistant is set up on your device, you should be able to address by simply saying “OK Google” and issuing it commands.
Developers can build on the above project by programming their own custom voice skills and smart home functions using Google Assistant’s voice recognition as input.
If the device is still connected to a monitor, keyboard, and mouse, you can set it up to be accessible via SSH and run in a headless configuration using the Pi’s network options.