How to Setup an Orange Pi Zero DIY Smart Speaker with Google Assistant SDK

A preview release of Google Assistant SDK working with Raspberry Pi 3 and other ARMv7 boards was released in May, and soon after, AIY Projects Voice Kit was offered for free with Raspberry Pi Magazine in order to a complete smart speaker kit working with RPi 3. I wanted to try it on one of FriendlyELEC or Shenzhen Xunlong Allwinner board, since all we need is audio input and output, and an Internet connection. Earlier this month, I came across Orange Pi Zero Set 6 Kit that had all I needed: Orange Pi Zero ARM Linux board, an expansion board with built-in microphone and audio output jack, and a cute and small case to neatly put everything together.

Orange Pi Zero Set 6 Kit Unboxing and Assembly

Shenzhen Xunlong sent me the kit so that I can try it out.

The package includes two Orange Pi packages, the plastic case, some a bag with screws and rubber pads.

One of the package comes with Orange Pi Zero board powered by Allwinner H2+ quad core processor with 512 MB RAM, micro USB for power, 10/100M Ethernet, a USB port, a WiFi antenna, and expansion headers on the top…

Click to Enlarge

.. and a micro SD card slot on the bottom, which we’ll use to boot the operating system.

The second package is for Orange Pi Zero Interface board v1.1 with two more USB port, an IR receiver, a 3.5mm audio jack, and a built-in microphone (top right).

Click to Enlarge

The next step is just to plug the interface board into Orange Pi Zero board, bending the WiFi antenna between the two boards…

Click to Enlarge

… before pushing the board from the bottom of the enclosure, tightened the cover with the 4 screws, and adding the 4 rubber pads.

Click to Enlarge

Installing Ubuntu on Orange Pi Zero & Configuring Networking and Audio Input & Output

Google Assistant SDK requires Ubuntu or Debian operating system, so I downloaded Ubuntu server legacy image on Armbian website, since the mainline image does not support XR819 WiFi module at all. I then extracted Armbian_5.30_Orangepizero_Ubuntu_xenial_default_3.4.113.7z and flashed Armbian_5.30_Orangepizero_Ubuntu_xenial_default_3.4.113.img  with Etcher on a micro SD card using my main computer.

Once it was done, I took the micro SD card to Orange Pi Zero board, connected my own speakers to the 3.5mm audio jack and USB for power, as well as a 5V/2A USB charger to power the system.

Click to Enlarge

You may notice an extra USB dongle on the picture above, but we’ll talk about that later.

I’ll use WiFi to test Google Assistant, but I also connected an Ethernet cable to make it easier for first time setup. If you don’t have Ethernet, you could also connect the board via a USB to TTL board to access the serial console.

After looking up the IP address of the board in my router, I connected with SSH using root (password: 1234):


The very first boot it will ask your to change the root password, and create a new user. You may want to create “pi” user at this stage. We should not be able to access the command, and run the following command to configure Orange Pi Zero board:


I first changed the timezone.

Then selected WiFi – Connect to wireless access point to connect to my WiFi router.

We can quit armbian-config, and optionally disconnect the Ethernet cable, and reconnect SSH over WiFi, which I did.

Back in the command line, I tested audio recording & playback with the built-in microphone and speakers using the same commands as in ReSpeaker guide:


The first command recorded my voice, and then I pressed Ctrl+C to stop, and play it back with the second command. I worked fine for me. If you wish you can adjust the playback and recording volume with:

We’ll also need to create .asoundrc file for Google Assistant to work with ALSA. For we need to note the microphone card and device number (0,0):


as well as speaker card and device number (0,0):


If you want to use your TV as speaker, you’d use Card 1, device: 0.

If you have not created a pi or other user yet, you’ll want to add one belonging to sudoers and audio groups, and go the home directory:


Now create a ~/.asoundrc with the following match the card and device for our mic and speaker:


[Update: As we’ll see below this won’t work with the built-in microphone, but as indicated in the comments below, this can be fixed by changing pcm.mic section with:


I have not changed the rest of the post, but the built-in microphone on Orange Pi Zero does work now]

Setting Up Google Assistant on Orange Pi Zero

Now that audio and networking are both setup and working, we can carry on with the instructions to install Google Assistant SDK and demo. Those are the same for all boards, and I’ll describe them below in details.

We need to configure a Google Developer Project.

Go to the Project page in Google Platform Console, and click on Create Project.

I called it Orange Pi Zero Smart Speaker, and clicked on Create.

Next, we’ll need to enable Google Assistant API for our project. Simply click on Enable on that page. The “Orange Pi Zero Smart Speaker” project was already selected in my case.

We’re then being asked to create an OAuth Client ID. I only filled my email address, and a product name before clicking on Save.

Select Other in the next page, and give another name – I used “Linux Thingy” – before clicking on Create.

You should now see an OAuth client pop-up window with your client ID and secret. You can just click OK, no need to copy or save either.

Instead we’ll download client_secret_[your_client_id].json file on the next page by clicking on the arrow circled in red.

I then copied that file to Orange Pi Zero board using scp (change [your_client_id] with your actual client ID):


Now that we have configured most options we need in Google Cloud platform, let’s install Python 3 and dependencies:


At this stage to need to make sure “Web & App Activity” with “Include Chrome browsing history and activity from websites and apps that use Google services”  checked, Device Information and Voice & Audio Activity are enabled in the Activity Controls page. All options were already enabled for me by default.

We can now install Google Assistant SDK package including library and sample code:


and the authorization tool:


Run the authorization tool:


This should show a text reading “Please visit this URL to authorize this application: https://….”. Select the URL and open it in a web browser, and copy/paste the authorization code you see in the web browser back into the terminal.

We can now start the demo


That’s the initial output


I went to say “OK Google” and “Hey Google”, and… nothing. No answer, and no info in the terminal window either. I tried several times, and also played with:


as explained in the troubleshooting section in Google Assistant documentation, incrementing the value by 6 until I reached -60, before running the demo, and no luck. So I thought maybe my “American accent” could have been the problem, so I launched Google Translate in my phone, and make it say “OK Google”. Same disappointing result. I went to Google Cloud Console, and good see some activity, but with 100% errors.

Click to Enlarge

So I did some searching on the web, I could find one person changing the .asoundrc file, but I did not work for me with the file generating plenty of sound related errors when running the demo, and another fix a similar problem by changing the microphone. Which reminded me, I had bought a cheap USB microphone on eBay for $1.45. So I connected it to Orange Pi Zero board, and that’s the extra USB dongle in the photo with the speakers higher in this guide, and check the card and device number:


We can see the USB card 2, device 0, so I update the relevant line in pcm.mic section in .asoundrc:


and ran the demo again. Success! The device would reply to make “OK Google” request, and tell me the time, my name, the weather for tomorrow, sing a song, do some calculus and so on.

This is what the output looks like when the demo works:


Bear in mind that Google Assistant SDK is in preview mode right now, and it’s mainly aimed at developers. First, I understand you can’t do automation tasks, or play music like you can on an actual Google Home. The good news is that you can roll you own implementation, and for example, somebody made his AIY Project Voice Kit work with Google Music, something you should be able to reproduce on other boards. Google Home also includes a microphone array, which will make hot word detection more reliable even in noisy environment. Orange Pi Zero + USB microphone did a decent job though, as I could use it 5 or more meters away.

Next time you boot the board, you can login as pi user, and run the following commands to run the demo:


You could also use systemd to automatically start the demo, or your own implementation, and I did so with instructions adapted from Nordic Semi’s Google Assistant Wiki.

First, create /etc/systemd/system/google-assistant-demo.service file with the following content:


I add “Type = idle” as other the app would not run, possibly because it would start after the audio was enable. I did not find any audio specific services handled by systemd, so “type = ilde” will make sure the service starts after other are loaded.

Now we can enable the service, and start it:


The demo will run at this point, and it will start automatically each time your boot the board. I played with it for several hours and it seemed stable. Some people have however expressed concered about WiFi on Orange Pi Zero, so if you encountered some instability issues, you may want to switch to Ethernet instead, or use a WiFi USB dongle, or use another Orange Pi or NanoPi board with a time-proven WiFi module.

I’d like to thank Shenzhen Xunlong Software for sending the kit my way. If you are interested, you can purchase it for $12.95 + shipping.

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

Radxa Orion O6 Armv9 mini-ITX motherboard
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
124 Comments
oldest
newest
Boardcon CM3588 Rockchip RK3588 System-on-Module designed for AI and IoT applications