28th-Jan-2018 Update: GassistPi updated with Chromecast-ing Feature and Media Volume Control Features
https://github.com/shivasiddharth/GassistPi/blob/update-script/GassistPi-Update-Script.sh
1. Headless auto start on boot.
2. Voice control of GPIOs without IFTTT, api.ai, Actions SDK.
3. Voice control of NodeMCU without IFTTT and MQTT.
4. Radio streaming.
5. Voice control of servo connected to RPi GPIO.
6. Safe shutdown RPi using voice command.
7. Stream Music from YouTube.
8. Indicator lights for assistant listening and speaking events.
9. Startup audio and audio feedback for wakeword detection.
10. Pushbutton service to stop Music or Radio playback.
11. Parcel tracking using Aftership API.
12. RSS Feed streaming.
13. Control of Kodi or Kodi Integration.
14. Streaming music from Google Play Music.
15. Casting of YouTube Videos to Chromecast and Chromecast media control by voice.
16. Voice control of Radio/YouTube/Google Music volume levels.
The Project has adopted the new Google Assistant SDK features released on 20th Dec 2017. Old installations will not work. So kindly Reformat your SD Card and start fresh
CLI or Raspbian Lite or Google's AIY image does not support all features. So please use the Standard Raspbian Desktop image- Link https://www.raspberrypi.org/downloads/raspbian/
- Open the terminal and execute the following
git clone https://github.com/shivasiddharth/GassistPi
- Update OS and Kernel
sudo apt-get update
sudo apt-get install raspberrypi-kernel
-
Restart Pi
-
Choose the audio configuration according to your setup.
The speaker-test command is used to initialize alsa, so please do not skip that.
AIY-HAT and CUSTOM-HAT users, please reboot the Pi at places mentioned, else it will lead to audio and taskbar issues.
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
speaker-test
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 reboot
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
speaker-test
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
speaker-test
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
speaker-test
3.5. CUSTOM VOICE HAT users,
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
sudo reboot
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
speaker-test
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
-
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 Executablesudo 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
-
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
Connect LEDs with colours of your choice to GPIO05 for Listening and GPIO06 for Speaking Events.
Connect a pushbutton between GPIO23 and Ground. Using this pushbutton, now you can stop the music or radio playback.
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 FOLLOWING YOUTUBE VIDEO.
Download the Arduino IDE code for Nodemcu from here: https://github.com/shivasiddharth/iotwemos/blob/master/Google-Home-NodeMCU.ino
Add the wifi credentials, make the desired changes and upload the Arduino code onto the NodeMCU and get the IP address from the serial monitor.
Add the NodeMCU's IP address in the actions.py file.
FOR GUIDELINES ON MODIFYING THE ARDUINO CODE AND ACTIONS.PY FILE, FOLLOW THE FOLLOWING YOUTUBE VIDEO.
Default command for casting YouTube videos is Play Desired Video on Chromecast, with Chromecast as the trigger word. Example: Hey Google, Play MasterChef Season 1 Episode 1 on Chromecast casts the MasterChef YouTube Video.
Note: YouTube casting to Chromecast using third party scripts has been blocked, so I have taken a roundabout approach and as a result, you may not find the usual YouTube interface on Chromecast.
First, add the IP-Address of your Chromecast in the actions.py script, in the indicated location.
Following are the default commands for controlling Chromecast with Chromecast as the trigger word.
Pausing:
Hey Google, Pause Chromecast
Resuming:
Hey Google, Resume Chromecast
Stopping: Hey Google, End Chromecast
Change volume up/down:
Hey Google, Chromecast Volume Up/Down
You can change volume and pause or resume the Radio/YouTube/Google Music by voice.
Pausing:
Hey Google, Pause Music (Entire phrase Pause Music is the trigger)
Resuming:
Hey Google, Resume Music (Entire phrase Resume Music is the trigger)
Volume Control (Music Volume is the trigger)
Increase/Decrease Volume:
Hey Google, Increase/(Decrease or Reduce) Music Volume by ( a number between 0 and 100)
If you do not specify a number, by default the volume will be increased or decreased by 10 units.
Set Volume:
Hey Google, Set/change Music Volume to ( a number between 0 and 100)
Set volume to Maximum/Minimum:
Hey Google, Set/change Music Volume to maximum/minimum
The updated music streaming features autoplaying of YouTube suggestions. This makes use of the YouTube Data API v3.
- Go to the projects page on your Google Cloud Console-> https://console.cloud.google.com/project
- Select your project from the list.
- On the left top corner, click on the hamburger icon or three horizontal stacked lines.
- Move your mouse pointer over "API and services" and choose "credentials".
- Click on create credentials and select API Key and choose close. Make a note of the created API Key and enter it in the actions.py script at the indicated location.
- "From the API and services" option, select library and in the search bar type youtube, select "YouTube Data API v3" API and click on "ENABLE".
- In the API window, click on "All API Credentials" and in the drop down, make sure to have a tick (check mark) against the API Key that you just generated.
Music streaming has been enabled for both OK-Google and Custom hotwords/wakewords.
Default keyword for playing music from YouTube without autoplay is Stream. For example, Stream I got you command will fetch Bebe Rexha's I Got You from YouTube.
Default keyword for playing music from YouTube with autoplay is Autoplay and Stream. For example, Autoplay and Stream I got you command will play the requested I Got You and after the end of the track will autoplay susequent tracks. The number of autoplay tracks has been limited to a maximum of 10. this can be changed the under the YouTube_Autoplay function in the actions.py script.
Due to the Pi Zero's limitations, users are advised to not use the Music streaming feature. Music streaming will send the CPU usage of Pi Zero into the orbit.
The music streaming from Google Music uses Gmusicapi.
Enter your Google userid and password in the actions.py file in the line "logged_in = api.login('YOUR_GMAIL_ID', 'YOUR_GMAIL_PASSWORD', Mobileclient.FROM_MAC_ADDRESS)". If you are using a two-step authentication or two-factor authentication, generate and use an app specific password.
Refer to this page on google help - https://support.google.com/accounts/answer/185833?hl=en
Play all your songs in loop using the syntax: "Hey Google, Play all the songs from Google Music"
Play songs added to the user created playlist (does not include: most played playlist, thumsup playlist, etc) using the syntax: "Hey Google, Play songs from the first playlist in Google Music" Playlists are sorted by date created, if you have multiple playlists, use a similar syntax replacing first with second, third etc. Also you need to make suitable changes in the main.py (It has been commented in the script to help)
Play songs by a particular artist using the syntax: "Hey Google, Play songs by artist YOUR_ARTIST_NAME from Google Music"
Play songs from particular album using the syntax: "Hey Google, Play songs from album YOUR_ALBUM_NAME from Google Music"
Change tracks Shuffle tracks Repeat tracks
Due to the Pi Zero's limitations, and computationally intensive nature of the Google Music streaming feature, this action has not been enabled for Pi Zero.
Default keyword for streaming radio is tune into. For example, tune into Radio 2 command will open the corresponding radio stream listed in the actions.py file.
Radio streaming has been enabled for both OK-Google and Custom hotwords/wakewords.
Useful links for obtaining radio streaming links:
http://www.radiosure.com/stations/
http://www.live-radio.net/worldwide.shtml
Due to the Pi Zero's limitations, users are advised to not use the Radio streaming feature. Radio streaming will send the CPU usage of Pi Zero into next galaxy.
The default keyword for tracking parcel is parcel. For example, you can say where is my parcel or track my parcel.
Regsiter for a free account with Aftership at https://www.aftership.com gnereate an API number and add parcels to the tracking list. The generated API number should be added to the actions.py script at the indicated location. For a better understanding follow the attached youtube video.
Default keywords for playing RSS feeds is feed or news or quote. Example usage, top tech news will play the top technology news, top world news will play top news related to different countires, top sports news will play the top sports related news and quote of the day will give some quotes.
Do not mix the commands with Play as that has been associated with music streaming from YouTube.
numfeeds variable within the feed function in actions.py file is the feed limit. Certain RSS feeds can have upto 60 items and numfeeds variable limits the number of items to stream. The default value has been set to 10, which if you want can change.
The Kodi integration uses YouTube Data API v3 for getting video links. First step is to add the API to the project and create an API KEY.
- Go to the projects page on your Google Cloud Console-> https://console.cloud.google.com/project
- Select your project from the list.
- On the left top corner, click on the hamburger icon or three horizontal stacked lines.
- Move your mouse pointer over "API and services" and choose "credentials".
- Click on create credentials and select API Key and choose close. Make a note of the created API Key and enter it in the actions.py script at the indicated location.
- "From the API and services" option, select library and in the search bar type youtube, select "YouTube Data API v3" API and click on "ENABLE".
- In the API window, click on "All API Credentials" and in the drop down, make sure to have a tick (check mark) against the API Key that you just generated.
The webserver is disabled by default and has to be manually enabled by the user.
- This can be done in Settings โ Services โ Control โ Allow remote control via HTTP.
- Set the port number to 8080, username to kodi and password to kodi
(username and password should be in lowercase).
For Kodi to play the YouTube video, you need to add and enable the YouTube Plugin on Kodi.
Note that "on Kodi" should be used in all the commands. If you want to use it exclusively, for Kodi Control, replace the given main.py and assistants.py file with the ones provieded in the extras/Kodi Intergration/ folder. In that, "on kodi" has been programatically added and other functions have been disabled,even genral queries like time and weather will not work. It is to be used only for the following Kodi commands.
Command Syntax | What it does |
---|---|
Hey Google, Shuffle my songs on kodi | Shuffles all the songs added to the kodi library |
Hey Google, Play songs from Album name on kodi | Plays all the songs under the mentioned Album name |
Hey Google, Play songs by, Artist name on kodi | Plays all the songs rendered by the mentioned artist |
Hey Google, Play Song name song on kodi | Plays the requested song, if it has been added to the library |
Hey Google, Play Movie name movie on kodi | Plays the requested movie, if it has been added to the library |
Hey Google, From YouTube, Play Youtube Video on kodi | Fetches the YouTube video and plays it on Kodi |
Hey Google, What is playing? on kodi | Tells you by voice as to what is currently playing |
Hey Google, Repeat this or Repeat one on kodi | Repeats the current track playing |
Hey Google, Repeat all on kodi | Changes repeat mode to all |
Hey Google, Repeat off on kodi | Turns off Repeat |
Hey Google, Turn Shuffle On on kodi | Turns on shuffle mode |
Hey Google, Turn Shuffle Off on kodi | Turns off shuffle mode |
Hey Google, Play Next on kodi | Plays the next track |
Hey Google, Play Previous on kodi | Plays the previous track |
Hey Google, Scroll a bit forward on kodi | Fast forwards a movie/music by a small amount |
Hey Google, Scroll forward on kodi | Fast forwards a movie/track by a large margin |
Hey Google, Scroll a biy backward on kodi | |
Hey Google, Scroll backward on kodi | Rewinds a movie/track by a large margin |
Hey Google, Set volume Vol level number between 0 and 100 on kodi | Sets the volume to the mentioned number |
Hey Google, Get volume on kodi | Tells you the current volume level by voice |
Hey Google, Toggle mute on kodi | Either mutes or unmutes, depending on mute status |
Hey Google, Pause on kodi | Pauses the current video/track |
Hey Google, Resume on kodi | Resumes playing the video/track |
Hey Google, Stop on kodi | Stops playing and closes the player |
Hey Goolge, goto Home on kodi | Opens the appropriate menu or window mentioned |
Hey Goolge, goto Settings on kodi | Opens the settings menu or window |
Hey Goolge, goto Videos on kodi | Opens the videos menu or window |
Hey Goolge, goto Weather on kodi | Opens the weather menu or window |
Hey Google, goto Music on kodi | Opens the music menu or window |
Hey Google, Move Up on kodi | Moves selection pointer up |
Hey Google, Move Down on kodi | Moves selection pointer down |
Hey Google, Move Left on kodi | Moves selection pointer left |
Hey Google, Move Right on kodi | Moves selection pointer right |
Hey Google, Move Back on kodi | Goes back, equivalent to esc key |
Hey Google, Move Select on kodi | Makes a sletion, equivalent to enter key |
-
Change the Pin numbers in the given sketch according to your board and upload it.
-
Follow the circuit diagram given.
GPIO Number (BCM) | Purpose |
---|---|
25 | Assistant activity indicator for AIY Kits |
23 | Pushbutton to stop music/radio AIY and others |
05 and 06 | Google assistant listening and responding |
22 | Pushbutton trigger for gRPC API. Connect a pushbutton between GPIO 22 and GRND for manually triggering |
12,13,24 | Voice control of devices connected to GPIO |
27 | Voice control of servo |
Note: some HATS may use GPIOs 18, 19, 20, 21 for I2S audio please refer to the manufacturer's pinouts