The Google Home is a wireless smart speaker that functions as your smart assistant. The device uses speech recognition to take your orders. For the time being, Google Home is not yet available in the Netherlands, but then you build one yourself, right? In this article we create your own Google Home with a Raspberry Pi 3.
01 Supplies
The heart of your own smart speaker is the Raspberry Pi 3. You connect a speaker and a microphone to it. We plug the speaker into the analog output of the Pi. Its sound quality is not great, but for speech synthesis it is sufficient. The Pi does not have an analog input, so we connect a USB microphone. Now you only need to connect a power adapter, and you need a micro SD card to set up the operating system. We use WiFi, so an Ethernet cable is not necessary.
02 Install Raspbian
Download Raspbian Jessie from the Raspberry Pi website. Extract the zip file. We now have to write the img file that is in it to a micro-sd card. First format the card with the SD Card Formatter program. After that, start the Win32 Disk Imager program. Choose the drive letter of your micro SD card, select the Raspbian img file and click write to write the operating system to your card. With both programs, make sure you choose the correct drive letter, because the contents of the card will be completely overwritten!
03 Set up network
Insert the micro SD card into your PC, after which Windows opens the boot partition in the Explorer. Click on the menu Image and check Current display the option File name extensions at. Then right click on an empty space in the partition and click New / Text file and name the file ssh. Remove the extension .txt. Create a file in the same way wpa_supplicant.conf in the boot partition. Make sure your file has the extension .conf has, and not .txt. Open the file in notepad and add the configuration for your wifi network with rules network={, ssid="YourESSID", psk="YourWifiPassword" and }. Save the file and remove the micro SD card from the PC.
04 Basic configuration
Look up the ip address of your Pi in the dhcp leases of your router and log in with the program PuTTY. Enter as username pi in and as password raspberry. First of all, update the package lists with the command sudo apt update and then upgrade all installed programs with sudo apt upgrade. Then run the configuration program with sudo raspi-config. Change your password so that your Pi does not inadvertently become part of a botnet. And set your time zone correctly (in Localization Options). Then close the configuration program (Finish).
05 Google Cloud Platform
We want to make our Pi work with the Google Assistant API. To do this, first open the Resource Manager of the Google Cloud Platform (log in with your Google account) and click on Create project. Give the project a name (for example Google Home Pic), confirm that you have read the terms of service and click To make. When the project has been created, you will receive a notification at the top right. Click on the icon and then on the project name, after which you will see the dashboard of your project.
Your own Amazon Echo
The developers of Alexa, the voice service in the Amazon Echo, have also put code online with which you can build your own Echo. The code comes with step-by-step instructions to install Alexa on your Raspberry Pi. You first install Raspbian and then the samples for the Alexa Voice Service, which use Node.js, the Java Development Kit 8 and Maven. You will also need a speaker and microphone for this project.
06 Enable Google Assistant API
Now click on the left of the project dashboard API-management and then at the top Enable API. Type in the search field assistant and then click Google Assistant API, which appears in the search results. Click at the top Switch. You still need login details to use this API. So click on the left Credentials and then on the tab OAuth consent screen. Enter a name such as Google Home Pic, leave the rest of the fields blank and click Save.
07 Create OAuth Client ID
Now click in the tab Credentials from the API management on Create credentials and choose Client ID OAuth. Choose as application type Other, give it a name and click To make. You will now be presented with a client ID and client secret. click on OK and then click the download icon to the right of your client ID. Download the program pscp from the same website as PuTTY (see step 4) and then open a command prompt. Enter the command pscp path to json file pi@IPADDRESS: with the correct path and ip address of your Pi to copy the file to your Pi. Don't forget the : after the IP address. Enter your Pi's password.
08 Test audio
Now that the Google cloud services we use in our project are configured, it's time to tinker with the Pi. Return to the PuTTY window with your Pi's command prompt or log back into your Pi. Enter the command speaker test -t wav off to play a test sound and press Ctrl+C to stop playing. If you don't hear anything, make sure your speaker is connected properly. Then run the command arecord --format=S16_LE --duration=5 --rate=16k --file-type=raw out.raw and say something into the microphone. Check if it was recorded with aplay --format=S16_LE --rate=16k out.raw.