YouTube Music Streaming for Google Assistant on Raspberry Pi

GassistPi ā€” Google Assistant for all Raspberry Pi Boards

Pi Zero ā€“ forked and modified from warchildmd's repo (https://github.com/warchildmd/google-assistant-hotword-raspi)

Features:

  • Headless auto start on boot with multiple custom wakeword activation triggers.
  • Voice control of GPIOs without IFTTT, api.ai, Actions SDK.
  • Voice control of servo connected to RPi GPIO.
  • Safe shutdown RPi using voice command.
  • Stream Music from YouTube.
  • Indicator lights for assistant listening and speaking events.
  • Startup audio and audio feedback for wakeword detection.

This is implemented in Python2 so your existing Google Assistant may not work. So please start by making a fresh copy of latest Raspbian Stretch.

Step 1: Clone the project on to Pi

git clone https://github.com/shivasiddharth/GassistPi

Install audio config files

  • Update OS and Kernel
sudo apt-get update  
sudo apt-get install raspberrypi-kernel  
  • Restart Pi
  • Choose the audio configuration according to your setup. (Run the commands till you get .bak notification in the terminal)

3.1. USB DAC or USB Sound CARD users:

sudo chmod +x /home/pi/GassistPi/audio-drivers/USB-DAC/scripts/install-usb-dac.sh  
sudo /home/pi/GassistPi/audio-drivers/USB-DAC/scripts/install-usb-dac.sh 

3.2. AIY-HAT users:

sudo chmod +x /home/pi/GassistPi/audio-drivers/AIY-HAT/scripts/configure-driver.sh  
sudo /home/pi/GassistPi/audio-drivers/AIY-HAT/scripts/configure-driver.sh  
sudo chmod +x /home/pi/GassistPi/audio-drivers/AIY-HAT/scripts/install-alsa-config.sh 
sudo /home/pi/GassistPi/audio-drivers/AIY-HAT/scripts/install-alsa-config.sh 

3.3. USB MIC AND HDMI users:

sudo chmod +x /home/pi/GassistPi/audio-drivers/USB-MIC-HDMI/scripts/install-usb-mic-hdmi.sh  
sudo /home/pi/GassistPi/audio-drivers/USB-MIC-HDMI/scripts/install-usb-mic-hdmi.sh 

3.4. USB MIC AND AUDIO JACK users:

sudo chmod +x /home/pi/GassistPi/audio-drivers/USB-MIC-JACK/scripts/usb-mic-onboard-jack.sh  
sudo /home/pi/GassistPi/audio-drivers/USB-MIC-JACK/scripts/usb-mic-onboard-jack.sh

3.5. CUSTOM VOICE HAT users:

sudo chmod +x /home/pi/GassistPi/audio-drivers/CUSTOM-VOICE-HAT/scripts/custom-voice-hat.sh  
sudo /home/pi/GassistPi/audio-drivers/CUSTOM-VOICE-HAT/scripts/custom-voice-hat.sh  
sudo chmod +x /home/pi/GassistPi/audio-drivers/CUSTOM-VOICE-HAT/scripts/install-i2s.sh
sudo /home/pi/GassistPi/audio-drivers/CUSTOM-VOICE-HAT/scripts/install-i2s.sh 

Those Using HDMI/Onboard Jack, make sure to force the audio:

sudo raspi-config  

Select advanced options, then audio and choose to force audio. Those using any other DACs or HATs install the cards as per the manufacturer's guide and then you can try using the USB-DAC config file after changing the hardware IDs:

  • Restart Pi
  • Check the speaker using the following command:
speaker-test -t wav  

CONTINUE after SETTING UP AUDIO

  • Download credentialsā€”>.json file (refer to this doc for creating credentials https://developers.google.com/assistant/sdk/develop/python/config-dev-project-and-account)
  • Place the .json file in/home/pi directory DO NOT RENAME
  • Use the one-line installer for installing Google Assistant Pi3 and Armv7 users use the ā€œgassist-installer-pi3.shā€ installer and Pi Zero, Pi A and Pi 1 B+ users use the ā€œgassist-installer-pi-zero.shā€ installer. 4.1 Make the installers Executable
sudo chmod +x /home/pi/GassistPi/scripts/gassist-installer-pi3.sh 
sudo chmod +x /home/pi/GassistPi/scripts/gassist-installer-pi-zero.sh  

4.2 Execute the installers Pi3 and Armv7 users use the ā€œgassist-installer-pi3.shā€ installer and Pi Zero, Pi A and Pi 1 B+ users use the ā€œgassist-installer-pi-zero.shā€ installer. When Prompted, enter your Google Cloud console Project-Id, A name for your Assistant and the Full Name of your credentials file, including the json extension.

sudo  /home/pi/GassistPi/scripts/gassist-installer-pi3.sh   
sudo  /home/pi/GassistPi/scripts/gassist-installer-pi-zero.sh  
  • Copy the google assistant authentication link from terminal and authorize using your google account
  • Copy the authorization code from browser onto the terminal and press enter
  • After successful authentication, the Google Assistant Demo test will automatically start. At the start, the volume might be low, the assistant volume is independent of the Pi volume, so increase the volume by using ā€œVolume Upā€ command.
  • After verifying the working of assistant, close and exit the terminal

HEADLESS AUTOSTART on BOOT SERVICE SETUP

  • Open the service files in the /home/pi/GassistPi/systemd/ directory and add your project and model ids in the indicated places and save the file.
  • Make the service installer executable
sudo chmod +x /home/pi/GassistPi/scripts/service-installer.sh
  • Run the service installer
sudo /home/pi/GassistPi/scripts/service-installer.sh   
  • Enable the services ā€“ Pi3 and Armv7 users, enable the ā€œgassistpi-ok-ggogle.serviceā€ and Pi Zero, Pi A and Pi 1 B+ users, enable ā€œgassistpi-push-button.serviceā€ To stop music playback using a pushbutton connected to GPIO 23 enable stopbutton.service
sudo systemctl enable gassistpi-ok-google.service  
sudo systemctl enable gassistpi-push-button.service
sudo systemctl enable stopbutton.service  
  • Start the service ā€“ Pi3 and Armv7 users, start the ā€œgassistpi-ok-ggogle.serviceā€ and Pi Zero, Pi A and Pi 1 B+ users, start ā€œgassistpi-push-button.serviceā€ To stop music playback using a pushbutton connected to GPIO 23 start stopbutton.service
sudo systemctl start gassistpi-ok-google.service  
sudo systemctl start gassistpi-push-button.service
sudo systemctl start stopbutton.service  

RESTART and ENJOY

Indicators for Google Assisant's listening and speaking events

Connect LEDs with colours of your choice to GPIO05 for Listening and GPIO06 for Speaking Events.

Voice control of GPIOs, servo and Pi shutdown

  • The default GPIO and shutdown trigger word is trigger. It should be used for controlling the GPIOs, servo and for safe shutdown of Pi.
  • It has been intentionally included to prevent control actions due to false positive commands. If you wish to change the trigger word, you can replace the ā€˜triggerā€˜in the main.py and assistant.py code with your desired trigger word.
  • The default keyword for servo motor is servo. For example, the command trigger servo 90 will rotate the servo by 90 degrees.
  • If you wish to change the keyword, you can replace the ā€˜servo' in the action.py script with your desired keyword for the motor.
  • For safe shutdown of the pi, command is: trigger shutdown
  • You can define your own custom actions in the actions.py script. THE ACTIONS SCRIPT OF THIS PROJECT IS DIFFERENT FROM AIY KIT's SCRIPT, COPY PASTING THE COMMANDS FROM AIY's ACTION SCRIPT WILL NOT WORK HERE. FOR A BETTER UNDERSTANDING OF THE ACTIONS FILE, FOLLOW THE YOUTUBE VIDEO.
  • Default keyword for playing music from YouTube is Stream. For example, Stream I got you command will fetch Bebe Rexha's I Got You from YouTube.

Due to the Pi Zero's limitations, users are advised to not use the Music streaming fueature. Music streaming will send the CPU usage of Pi Zero into the orbit.

For Neopixel indicator

  • Change the Pin numbers in the given sketch according to your board and upload it.
  • Follow the circuit diagram given.

Now you have your Google Home Like Indicator!

Source: YouTube Music Streaming for Google Assistant on Raspberry Pi


About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top