Google Assistant on Raspberry | Part 1: Installation process

Words
513
Reading
3 min
Listen
Play
8y

google assistant.jpg

What Will I Learn?

  • How to install Google Assistant on Raspberry
  • How to configure USB microphone and speakers on Raspberry
  • How to install Raspbian on an SD card

Requirements

  • Raspberry Pi 3
  • USB microphone
  • Speakers
  • Power source
  • Micro SD card with adapter
  • Led diode (optional)

Difficulty

Intermediate

Installing Raspbian

  • Download latest Raspbian with desktop (zip version)
    raspbian.png
  • Download and install Etcher
    download etcher.png
  • Connect the SD card to the computer, open Etcher and select the zip image and the card. Then click "Flash"
    ether 1.png
  • When flash is complete, you can disconnect the SD card from the computer and connect it to the Raspberry. Next, connect the mouse, keyboard, monitor and power source to the Raspberry (you can do the whole process via ssh as well)
  • Set up internet connection on your Raspberry. You can configure it in the upper right corner
    2018-04-02-091128_1824x984_scrot.png

Installing Google Assistant

  • Go to the Google Actions Console and create a new project
    add.png
    Name your project and click create
    create.png
  • Enable the Api (you will have to select your project)
    enable.png
  • Go to Credentials and create new OAuth client ID
    credentials.png
    oauth.png
    Select "Other" and name your device
    device.png
  • Download the ID file that you have created
    download json.png
    Copy it to the /home/pi directory and rename it to assistant.json
    2018-04-02-090048_1824x984_scrot.png
  • Open new terminal window and clone required Github repository
git clone -b voicekit https://github.com/google/aiyprojects-raspbian.git ~/voice-recognizer-raspi
  • Go into the Assistant folder
cd ~/voice-recognizer-raspi
  • Follow these commands one by one to install required software (this may take a while)
scripts/install-deps.sh
sudo scripts/install-services.sh
  • Copy Assistant demo file into new “main” file
cp src/assistant_library_with_local_commands_demo.py src/main.py
  • Make assistant starting automatically during system startup
sudo systemctl enable voice-recognizer.service

Microphone and speakers configuration

  • Open new terminal window and locate your USB microphone. You will need card number and device number
arecord -1
  • Locate your speakers. You will need card number and device number
aplay -1

2018-04-02-191123_1824x984_scrot.png

  • Create new file named .asoundrc in /home/pi directory
cd /home/pi/.asoundrc

and fill it with below configuration but replace card number and device number for mic and speaker with numbers you got in previous steps. Save and quit file by pressing Ctrl+O and then Ctrl+X

pcm.!default {
  type asym
  capture.pcm "mic"
  playback.pcm "speaker"
}
pcm.mic {
  type plug
  slave {
    pcm "hw:,"
  }
}
pcm.speaker {
  type plug
  slave {
    pcm "hw:,"
  }
}

2018-04-02-191540_1824x984_scrot.png

  • Adjust playback and recording volume
alsamixer
  • Check if speakers work properly. To exit the test press Ctrl+C
speaker-test -t wav
  • Record audio clip to check if microphone works properly
arecord --format=S16_LE --duration=5 --rate=16000 --file-type=raw out.raw
  • Replay your recording
aplay --format=S16_LE --rate=16000 out.raw

If you don’t hear anything make sure you used right card number and device number in .asoundrc file and sound level has been configured properly in alsamixer

Running Google Assistant

  • Open new terminal window and go into the Assistant folder
cd ~/voice-recognizer-raspi
  • Activate Virtual Python Environment
source env/bin/activate
  • Run the Assistant
python3 src/main.py

You should get web link in terminal, click it to grant necessary permissions to the Assistant.
2018-04-02-192142_1824x984_scrot.png
2018-04-02-192212_1824x984_scrot.png

  • Now, you should be able to say “Ok Google” and start a conversation. There is possibility that the volume of the Assistant will be very low. Say "Ok Google, set volume to max" to fix it
  • Try "Ok Google, reboot" to check if Assistant is still working after reboot

Connecting led indicator diode

You may additionally connect a led diode to GPIO25 to show Assistant status. Here is a circuit diagram:led.png
circuit2.JPG

Here is how it works:

Thank you for reading. Hope this tutorial will be helpful.



Posted on Utopian.io - Rewarding Open Source Contributors

Google Assistant on Raspberry | Part 1: Installation process | Ecency