DIY Google Home With Bluetooth Speaker on Raspberry Pi Zero Docking Hub


30,559

90

15

We have an instructable on DIY Amazon Echo Alexa - Alexa Voice Assistant on Raspberry Pi Zero Docking Hub. This time we want to show you how to build a DIY Google Home. In this instructable, we will show you how to install and setup Google Assistant on a Pi Zero W with MakerSpot's Raspberry Pi Zero Docking Hub and Bluetooth speaker.

Let's get started.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Get These Parts

These are the parts you need:

  1. 1x Raspberry Pi Zero W
  2. 1x Raspberry Pi Zero Docking Hub
  3. 1x HDMI monitor
  4. 1x HDMI cable (please note Pi Zero W requires a mini-HDMI connector)
  5. 1x 5v USB 1 A Power Adaptor
  6. 1x micro USB cable
  7. 1x USB keyboard
  8. 1x USB mouse
  9. 1x Mini-Microphone For Mobile Phone/Tablet
  10. 1x Bluetooth Speaker
  11. 1x 8G micro SD card
  12. PC (for flashing the SD card with Raspbian OS image)

Step 2: Prepare SD Card With the Latest Raspbian OS (Stretch)

It would be a good idea to start with a fresh Raspbian OS. There are a few ways to prepare a new Raspbian OS on an SD card. But I found that using Etcher with a full Raspbian image is efficient and less error-prone.

  1. Download and install Etcher (https://etcher.io/) for your host PC.
  2. Download the latest Raspbian (Stretch) image from http://downloads.raspberrypi.org/raspbian/images/... the SD into your PC
  3. Open Etcher, select the downloaded image, then the SD card drive, and press Flash!

Once the image is prepared, eject the card safely and get ready for next step.

Step 3: Setup the Pi and Docking Hub

You need to install your Pi Zero W on the Raspberry Pi Zero Docking Hub. There are 4 sets of screws and standoffs and it will take less than a minute to assemble.

Insert the prepared SD card into the Pi Zero W. Connect your monitor to the Pi Zero W's HDMI port (must be done before powering up the Pi), connect the USB keyboard and mouse and finally connect the microphone. We are using the neat Saramonic Mini Directional Microphone for Smart Phone.

To power up, connect the 5v USB power cable to the power port on the docking hub (NOT THE PWR PORT ON THE PI). You should see the normal Raspbian OS coming up on the monitor.

Step 4: Configure the Pi

Setup WiFi.

Left mouse click over the WiFi icon on the top bar. Choose your network to connect. You only need to do once unless the network setting has changed or need to be changed.

Disable HDMI/Analog Audio

This step is important to get the Raspberry Pi Zero Docking Hub audio to work with the Google Assistant software.

Start a terminal and edit /boot/config.txt

sudo nano /boot/config.txt

Disable the analog and hdmi audio by inserting '#' in front of the following line in the file:

#dtparam=audio=on 

Press ctrl-x, y, and enter to save.

Enable SSH/VNC (Optional)

If you don't want to use the monitor, keyboard, and mouse at next startup, enabling these options would allow you to remote access the Pi. These options are under Preference/Raspberry Pi Configuration, then go to Interfaces and checkmark the SSH and VNC options.

Reboot the Pi to take the setting in effect.

Setup Bluetooth Speaker

After reboot and the desktop screen comes back, pair with your Bluetooth speaker.

  1. Go to the Bluetooth icon on the top menu bar, turn on Bluetooth and then add a Bluetooth device.
  2. Put the Bluetooth speaker in pairing mode
  3. You should see the speaker discovered. Highlight the speaker entry and click Pair.
  4. You will get a successful pair message but the speaker is not connected yet. Go to the speaker icon on the top menu bar. Click on the Bluetooth speaker. Your speaker should produce a chime or voice notification to indicate the Bluetooth connection is successfully made.

Change Audio Setting

After the Bluetooth speaker is connected, the .asoundrc file will be generated with the Bluetooth speaker info in it. You need to modify this file to set up the built-in microphone on the docking hub.

The original ~/.asoundrc file looks like this:

pi@raspberrypi:~ $ cat ~/.asoundrc
pcm.!default {
  type plug
  slave.pcm { 
    type bluealsa device "40:00:88:00:18:0E"
    profile "a2dp" 
  }
} 
ctl.!default {
  type bluealsa
}

You need to modify it to look like below. Your copy of .asoundrc should be exactly the same as below except the Bluetooth address "40:00:88:00:18:0E", which should come from your original.

pcm.!default {
  type asym
  capture.pcm "mic"
  playback.pcm "speaker"
} 
pcm.mic {
  type plug slave { pcm "hw:1,0" }
}
pcm.speaker {
  type plug 
  slave.pcm { 
    type bluealsa device "40:00:88:00:18:0E"  
    profile "a2dp" 
  } 
}

Finally, save a copy to /etc/asound.conf and prevent being overwritten

sudo cp ~/.asoundrc /etc/asound.conf
chmod a-w ~/.asoundrc

Step 5: Install Google Assistant Software

Prepare Google Project and Account

Before you install the Google Assistant software, you need to configure a developer project and account settings. Click this link and follow the steps there. Once finished, come back here.

Setup Virtual Environment

Open a terminal and follow the steps to set up the virtual environment

sudo apt-get update
sudo apt-get install python3-dev python3-venv
python3 -m venv env
env/bin/python -m pip install pip setuptools --upgrade
source env/bin/activate

Install More Prerequisite Libraries

On the same terminal, type:

sudo apt-get install portaudio19-dev libffi-dev libssl-dev
pip install wheel

Install Google Assistant SDK

On the same terminal, install the Google Assistant SDK and the oauth tools. The last command requires the client secret file generated while preparing Google Project and account.

python -m pip install google-assistant-sdk[samples]pip install --upgrade google-auth-oauthlib[tool]
google-oauthlib-tool --client-secrets path/to/client_secret_XXXXX.json --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save --headless

Checking It Out

Google Assistant should be working at this point. You can verify it by issuing the following command.

googlesamples-assistant-pushtotalk

Next step will be installing the wake word engine - snowboy - so you don't need to press enter to activate.

Step 6: Install Snowboy Wake Word Engine

Clone the Snowboy repository as follows:

make -p ~/Development/Assistant 
cd ~/Development/Assistant
git clone https://github.com/Makerspot/snowboy.git

To make Snowboy working with Raspbian Stretch, you need to rebuild the _snowboydetect.so for python3

sudo apt-get install swig3.0 python-pyaudio python3-pyaudio soxsudo libatlas-base-dev
pip install pyaudio
sudo ln -s /usr/bin/swig3.0 /usr/local/bin/swig
cd ~/Development/Assistant/snowboy/swig/Python3
make

Now you can run the Google Assistant using the "OK Google" wake word.

cd ~/Development/Assistant/snowboy/examples/Python3
python assistant_wrapper.py resources/OK\ google.pmdl

The "OK Google" wake word model file is a personalized model which may not work well for you. If you find the wake word doesn't work well, you may consider to train your own model and replace the "OK google.pmdl" file. Go to https://snowboy.kitt.ai/ to train your own model. You can even pick your own wake word - it doesn't have to be "OK Google".

Step 7: OK Google, Sing a Song

Congratulation! Say "OK Google" (or whatever wake word you have installed), wait for the Ding prompt, then ask Google Assistant with your question.

If you have enabled SSH (or VNC server), you can restart the Pi and run the Google Assistant software headless (without the monitor/keyboard/mouse). In your PC start an SSH terminal and connect to the Pi.

First, make the Pi Bluetooth to auto connect the speaker (only need to do it once).

echo -e "connect <bt speaker mac address>" | bluetoothctl
echo -e "trust <bt speaker mac address>" | bluetoothctl 

Every time the Pi reboot, it can reconnect to the speaker, however, only when the speaker is powered off and on as well. Then follow the steps below to start Google Assistant.

source ~/env/bin/activate
cd ~/Development/Assistant/snowboy/examples/Python3
python assistant_wrapper.py resources/OK\ google.pmdl

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    15 Discussions

    None
    lukee1986

    1 year ago

    so some projects just arent worth the dollars and this being 1 of them the google mini home is $53 but just a dececnt portable speaker will send u back that much + all other coponents and time just go buy google home mini good write up though

    1 reply
    None
    Legend299lukee1986

    Reply 10 days ago

    Doe soms people yes. But for people with a speaker system / having a Bluetooth speaker laying around this is a great DIY

    None
    Mridu29

    5 weeks ago

    Can some one help me with this issue! Where I am Wrong :(
    googlesamples-assistant-pushtotalk --project-id raspi-digital-assist --display
    INFO:root:Connecting to embeddedassistant.googleapis.com
    Traceback (most recent call last):
    File "/home/pi/env/bin/googlesamples-assistant-pushtotalk", line 10, in <module>
    sys.exit(main())
    File "/home/pi/env/lib/python3.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
    File "/home/pi/env/lib/python3.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
    File "/home/pi/env/lib/python3.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
    File "/home/pi/env/lib/python3.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
    File "/home/pi/env/lib/python3.7/site-packages/googlesamples/assistant/grpc/pushtotalk.py", line 351, in main
    flush_size=audio_flush_size
    File "/home/pi/env/lib/python3.7/site-packages/googlesamples/assistant/grpc/audio_helpers.py", line 190, in __init__
    blocksize=int(block_size/2), # blocksize is in number of frames.
    File "/home/pi/env/lib/python3.7/site-packages/sounddevice.py", line 1264, in __init__
    **_remove_self(locals()))
    File "/home/pi/env/lib/python3.7/site-packages/sounddevice.py", line 780, in __init__
    'Error opening {0}'.format(self.__class__.__name__))
    File "/home/pi/env/lib/python3.7/site-packages/sounddevice.py", line 2572, in _check
    raise PortAudioError(errormsg, err)
    sounddevice.PortAudioError: Error opening RawStream: Invalid sample rate [PaErrorCode -9997]

    None
    rmadd101

    7 weeks ago

    If I'm only interested in the ability to turn a Bluetooth speaker into, essentially, a Chromecast Audio, am I ok with just the Zero W & speaker (and keyboard, mouse, HDMI, monitor, SD card, & power cord)? I've got all those items lying around collecting dust, and really just want to be able to add an additional speaker to a Speaker Group I have without trying to track down a Chromecast Audio for a reasonable price, but it also appears to me that, given my desire, the Docking Hub seems unnecessary (as well as the mic, of course).

    None
    Arumugam Kumar

    7 months ago on Step 6

    I have installed Google assistant on raspberry pi 3 successfully and it's working fine with the "OK Google" wake word. I want to customize it using my own wake word using Snowboy. I questions is can I follow step 6 alone to do this???

    None
    DarioP43

    1 year ago

    Any solution to this?

    Captura de pantalla (9).png
    None
    oliver832368

    1 year ago

    would this work without the PC if you had a so suitible battery pack

    None
    asimobot

    1 year ago

    Is it possible to do this without the docking hub??if i can find another way to connect audio to the pi zero??

    None
    MikeK289

    Question 1 year ago

    I have a problem with your method

    After commenting out this line #dtparam=audio=on in /boot/config.txt the desktop taskbar disappears and I can no longer follow your instructions. I cannot select the bluetooth speaker option because its not there anymore..

    If I remove the hashtag from this line #dtparam=audio=on and reboot the desktop taskbar reappears..

    Any help?

    None
    GlenMerlin

    Question 1 year ago

    Hey I am thinking of doing this but i had a quick question if plugged in a 3.5mm splitter could you have wired speakers and a wired mic? Because i have tons of wired speakers all over the house but i don't have any bluetooth ones

    None
    rrsubra

    Question 1 year ago

    Can we use the microphone available in the Bluetooth speaker instead of a separate microphone. If so what are the changes we need to do inn setup.

    None
    JonasD33

    Question 1 year ago

    On an official google home you can say e.g. "ok google, play jazz on spotify" ... is it possible to make the setup you describe do that?