In this article, I will show you how to setup your own Google Home on your Raspberry Pi or any other Linux computer.
Further, I will teach you how can create own triggers and hotwords for your assistant.
Hardware
Before we start, make sure you have connected a microphone and speakers to your device. A regular USB webcam will also do the trick.
To check if the devices are actually connected we use the command:
to check the microphone and
for the speakers.
At this point, it is important that you remember the card number and device number of the microphone and speaker you have chosen to use.
This gained numbers we now have to write in our configuration file under ~/.asoundrc:
Where the two numbers after hw: are the card number followed by the device number and should be replaced by your own values
More information about the ALSA sound configuration can be found here
Now you should be able to record sound with:
and hear your own voice with:
Google Assistant
Google API Registration
First, if you don’t have a Google account already, create one. After you are logged in to the google developer console, create a new project. Now we have to enable the Assistant API. Next, to create our OAuth ClientID we have to go here. Select “Other” and when you finished download the json file, you can transfer it to your Raspberry Pi with:
Install Google Assistant Library
To download and install the libarary in a python3 enviroment we use the folling script:
Authentification with google cloud
Before we can use the assistant we first have to authorize our application. To do this we call:
We will receive a code on a website that we have to enter in the terminal.
Run the sample
Once you authorized your application, you can now run the sample from google.
You now have built a regular google home and can trigger your running assistant with “OK, Google” or “Hey, Google”.
Custom Trigger
Since we are building our Google Home on our own, we are open to customization. So we will create our own Trigger. While others use a button to trigger there Assistant, I still want to use voice. I just wasn’t so happy with the hotword, so I replaced it with something more sympathetic to me: “Samantha”, but you can choose anything you like.
Snowboy
To create our own personal trained model for hotword detection we use the Snowboy Engine
Create Hotword
Once you are logged in you have the option to choose a existing hotword or create your own.
In any case, you will receive the model as the file to download. After downloading you also need to transfer this file to your Raspberry Pi.
Python3 Support
Unfortunately, Snowboy just delivers executable binaries for Python 2. To work with our Python 3 Google Assistant Library we need to build the binary on our own. To do this we first clone the Snowboy GitHub repository:
First, we have to make the snowboydetect.py file with swig in the directory /swig/python3/
You need to have swig v3.0.10 or higher – if you are stuck read the comments of the Makefile
After successful build you should be able to run the Snowboy sample under examples/Python3/ with:
python demo.py your-trained-model.pmdl
Trigger Google Assistant with Snowboy
The Last step is to connect Snowboy with the Google Assistant. That means when Snowboy detects your hotword, it will activate the Google Assistant, so he starts listening immediately. You don’t need to say “OK, Google” anymore.
First, we change the snowboy demo.py file to call the google library:
After that, we modify the google library file at the end in you python environment under /env/lib/python3.5/site-packages/googlesamples/assistant/grpc/pushtotalk.py and replace following code at the end of the file
with
Now you should be able to trigger you assistant with your own hotword by running the Snowboy demo.py.
Conclusion
I hope you got some inspiration for further experiments with the Google Assistant. Another interesting point is, for example, to jump straight into your own google voice app.
If you want to know how to build a google voice application, check out my other post here
Thanks for reading through my post. For feedback or questions feel free to contact me.
Leave a Reply
You must be logged in to post a comment.