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)
- Download and install Etcher
- Connect the SD card to the computer, open Etcher and select the zip image and the card. Then click "Flash"
- 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
Installing Google Assistant
- Go to the Google Actions Console and create a new project
Name your project and click create
- Enable the Api (you will have to select your project)
- Go to Credentials and create new OAuth client ID
Select "Other" and name your device
- Download the ID file that you have created
Copy it to the /home/pi directory and rename it to assistant.json
- 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
- 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:,"
}
}
- 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.
- 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:
Here is how it works:
Thank you for reading. Hope this tutorial will be helpful.
Posted on Utopian.io - Rewarding Open Source Contributors