/gmusicaiy

Google Music action for Google AIY Voice Kit

Primary LanguagePython

gmusicaiy

Google Music action for Google AIY Voice Kit

Command your Google AIY Voice Kit to play playlists from your Google Music account using play <playlist>.

See it in action here:

Google AIY Music

Installation

Requires VLC for Raspbian: sudo apt-get install vlc

Requires gmusicapi and a Google Music account.

The code is setup to output text to an I2C display called Scroll pHAT, make sure to comment/replace those lines as needed.

Make sure that playscroll.py and vlc.py are located in /home/pi/voice-recognizer-raspi/src or that the system path is updated to point at their folder location.

Add an action to action.py as follows:

# The system path needs updating if playscroll.py and vlc.py are not in same folder as action.py
#import sys 
#sys.path.append('/home/pi/Python/gmusicaiy')
from playscroll import Player
import time
import RPi.GPIO

class PlayAction(object):

    """Plays the provided playlist."""

    def __init__(self, say):
        self.player = Player('email', 'password', 'device_id')
        self.say = say
        
    def run(self, voice_command):
        playlist = voice_command.replace("play","").strip()
        if self.player.load_playlist(playlist) is not None:
            self.say("Playing " + playlist)
            self.player.start_playlist()

            RPi.GPIO.setmode(RPi.GPIO.BCM)
            RPi.GPIO.setup(23, RPi.GPIO.IN)

            # Wait for button press to stop
            while self.player.playing and RPi.GPIO.input(23):
                time.sleep(1)

            self.player.stop()

def make_actor(say):
    # add this after other keywords/setup
    actor.add_keyword(_('play'), PlayAction(say)) 

Account Details

Make sure to provide your own account email address and password. If you don't know your device ID, an error will be raised and a list of your valid IDs displayed in the terminal window. Make sure to copy one of these into the script.

Note: If you're using two-factor authentication you'll need to replace the account password with the device specific password.

Stored Data

The code stores two local files containing song and playlist data. If you add songs or playlists, make sure to delete these so that the local data is regenerated.