In this tutorial, we will learn how to build your own smart speaker using Google Assistant and ReSpeaker Core v2.0. Notably, this is a continuation of the part 1 tutorial. Also, we will embed the Google Assistant and build our own Google Home/Google mini like smart speaker.
The Google Assistant Library for Python is a turnkey solution for anyone who wants to quickly integrate the Assistant into a project. Further, the library is written in Python and is supported on popular hardware like Raspberry Pi 3, etc.
Please refer to the previous tutorial and complete all the steps before you proceed on to the next steps.
Firstly, Use a Python virtual environment to isolate the SDK and its dependencies from the system Python packages. So, open the QTerminal and run the following commands one after the other.
For Python 3:
The Google Assistant SDK package contains all the code required to get the Google Assistant running on the device, including the sample code. So, execute the scripts below one by one.
Since we did all the groundwork from the previous tutorial and the remaining steps here, we can go ahead and run our sample code.
Change the command googlesamples-assistant-hotword --project-id <my-dev-project> --device-model-id <my-model> with your own IDs.
So, for the command above, change <my-dev-project> into your project-id and change <my-model> into your Model ID.
For this demo, it should be like
You can also run the same program by using the following command.
Finally, you can trigger the Google Assistant by using the hotword Ok Google/Hey Google.
Try asking the following
Ok Google, Tell me a joke.
Ok Google, Beam me up, Scotty.
Now that we have the sample app running, we do need to run it all the time and also start automatically on bootup. In order for us to do that, we need to configure a few things. Let's get started.
By default, our device doesn't do anything when it boots up; you must manually execute a program. But you can make this program (or any other program of your choice) run automatically upon bootup by creating a systemd service.
All you need is a .service configuration file. This file accepts a long list of configuration options.
In the QTerminal, enter the following command.
Copy-paste the following code into assistant-on-start.service file. Make sure to replace the project id and device-model-id with yours.
To put this file into action, you need to put it into the /lib/systemd/system/ directory. But instead of actually moving this file there, you can create a symbolic link (a "symlink") in this directory that points to the file that already exists. You can do this as follows:
Now we need to tell the system to run this service on bootup:
All set! You can try rebooting now to see it work.
Or manually run it with this command:
Note: Even after the prompt returns from this command, it takes a few moments for the program to start.
If you want to stop the service from running on bootup, disable it with this command:
And to manually stop it once it's running, use this command:
You can check the status of your service with this command:
If you need to check the logs for debug information regarding this service. You can check using the following command.
To conclude, we have successfully embedded the Google Assistant into our smart speaker. We have also automatically set it to run all the time and also automatically start on boot. So we now have a Google Home/Google mini like device of our own which does voice recognition using ReSpeaker Core v2.0 featuring a 6 array mic and speech algorithms. In the next upcoming tutorials, we will be extending the device to do more like connecting to a Bluetooth speaker, making it portable, etc. Until then, check out my other tutorials.