├── README.md ├── install-hat.sh ├── install.sh ├── uninstall.sh └── upgrade.sh /README.md: -------------------------------------------------------------------------------- 1 | # AssistantPi 2 | 3 | Scripts to automate installing, upgrading, and uninstalling Google Assistant service on Raspbian 4 | 5 | ## Installation 6 | 7 | ### Get Google Cloud credentials 8 | 9 | First make sure you are logged into Google in the web browser you are using. You can register the project on any device, but doing it on your Pi is recommended because it is most convenient. 10 | 11 | Go the [Google Cloud Console](https://console.cloud.google.com/) and follow the steps to get credentials in [Google's documentation](https://aiyprojects.withgoogle.com/voice#google-assistant--get-credentials). After completing Step 81 (Download the credentials) you can continue with the next step below. 12 | 13 | Rename the file that you downloaded to "assistant.json" and place it in the home directory of your Pi (usually `/home/pi`). If you downloaded it on a device other than your Pi, you can transfer it using a USB flash drive, or [FTP](https://www.raspberrypi.org/documentation/remote-access/ssh/sftp.md) if the device is on the same network. 14 | 15 | ### Configure USB microphone 16 | 17 | If you are using a USB microphone, you will need to configure some audio settings on your Pi to make it work with Assistant. Follow the steps in [Google's documentation](https://developers.google.com/assistant/sdk/guides/library/python/embed/audio) to configure and test the audio. The `(card number, device number)` pairs that you find in step 1 will likely be `1,0` for the mic and `0,0` for the speaker. 18 | 19 | ### Run install script 20 | 21 | There are two options for downloading and running the install script: 22 | 23 | 1. Clone this Git repo with the command `git clone https://github.com/t1m0thyj/AssistantPi.git`, then open a terminal in the "AssistantPi" directory (`cd AssistantPi`) and run `bash install.sh`. This is the recommended option because it will also download the scripts "upgrade.sh" and "uninstall.sh" which you can use later, but is not as easy as the second option. 24 | 2. Open a terminal window and run the command `curl -ssl https://raw.githubusercontent.com/t1m0thyj/AssistantPi/master/install.sh | bash`. This is easier than the first option but does not download the additional scripts. (Also this command executes a remote script, which is safe if the source is trusted but still potentially dangerous.) 25 | 26 | After the installation process finishes, a link should open automatically in Chromium (or whatever your Pi's default web browser is) asking you to sign in with your Google account. If the link doesn't automatically open, there should be a message in the terminal saying "Please visit this URL to authorize this application" with a link that you can click on. 27 | 28 | After logging in to your account, click "Allow" to grant permissions to Google Assistant. If the authorization succeeded, you should see this message: 29 | > The authentication flow has completed, you may close this window. 30 | 31 | A demo of Google Assistant should now be running in the terminal. Try talking to Assistant using the trigger phrase "OK Google" or "Hey Google", and whatever you say should show up in the terminal. After you are done with the demo, press `Ctrl+C` to quit it and the AssistantPi service should now start up in the background. 32 | 33 | Now if you reboot your Pi (you can use the voice command "OK Google reboot"), AssistantPi should start automatically after the Pi boots up again. 34 | 35 | ## FAQ 36 | 37 | ### Why not flash Google's AIY image on my Pi? 38 | 39 | Because you might not want to flash a custom image on your SD card just to use Google Assistant. With AssistantPi you can get it working in your existing Raspbian install. 40 | 41 | ### Can I add a status indicator LED? 42 | 43 | Yes, simply connect an LED between GPIO pin 25 and GND on your Pi. When Google Assistant is running, it will flash the LED every few seconds to let you know it is listening, and the light will turn solid when you start talking to it. 44 | 45 | ### Can I play podcasts and music on my Pi? 46 | 47 | No, unfortunately Google has limited the capabilities of the Assistant API on the Pi, but this may be possible in the future. 48 | 49 | ### Can I change the language used by Google Assistant? 50 | 51 | Yes, if you have the Google Assistant app on your phone, open Settings in the app and scroll down to "Devices". "Voice Kit" should be one of the devices listed, which is what AssistantPi registers itself as. From here you can change the language used by Assistant as well as some other settings. 52 | 53 | ### Can I code custom actions for Google Assistant? 54 | 55 | Yes, custom actions can easily be added by editing the Python script `~/AIY-projects-python/src/AssistantPi.py`. Details about how to do this can be found in [Google's Maker's Guide](https://aiyprojects.withgoogle.com/voice#makers-guide) for this project. 56 | -------------------------------------------------------------------------------- /install-hat.sh: -------------------------------------------------------------------------------- 1 | echo "deb https://dl.google.com/aiyprojects/deb stable main" | sudo tee -a /etc/apt/sources.list.d/aiyprojects.list > /dev/null 2 | wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add - 3 | sudo apt-get update 4 | 5 | sudo apt-get install pulseaudio 6 | mkdir -p ~/.config/pulse/ 7 | echo "default-sample-rate = 48000" > ~/.config/pulse/daemon.conf 8 | 9 | sudo apt-get install aiy-dkms aiy-voicebonnet-soundcard-dkms aiy-voicebonnet-routes 10 | 11 | echo "dtoverlay=i2s-mmap 12 | dtoverlay=googlevoicehat-soundcard" | sudo tee -a /boot/config.txt > /dev/null 13 | echo "blacklist snd_bcm2835" | sudo tee -a /etc/modprobe.d/alsa-blacklist.conf > /dev/null 14 | 15 | echo "Reboot your Pi to enable the AIY Voice HAT driver." 16 | echo "If you want to test audio after rebooting, run the Python script $HOME/AIY-projects-python/src/checkpoints/check_audio.py" 17 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | MAIN_PY=" 4 | import os.path 5 | activate_this = os.path.join(os.path.dirname(__file__), '../env/bin/activate_this.py') 6 | with open(activate_this) as f: 7 | exec(f.read(), {'__file__': activate_this}) 8 | 9 | import examples.voice.assistant_library_with_local_commands_demo as assistant 10 | assistant.main() 11 | " 12 | 13 | SERVICE="[Unit] 14 | Description=Google Assistant for Raspberry Pi 15 | After=network.target 16 | 17 | [Service] 18 | ExecStart=/usr/bin/python3 -u src/AssistantPi.py 19 | WorkingDirectory=$HOME/AIY-projects-python 20 | StandardOutput=inherit 21 | StandardError=inherit 22 | Restart=always 23 | User=$USER 24 | 25 | [Install] 26 | WantedBy=multi-user.target 27 | " 28 | 29 | if [ "$(uname -m)" = "armv6" ]; then 30 | echo -e "\e[1;31mError: AssistantPi does not work on the Pi Zero and Pi 1.\e[0m 31 | If you are using a device with an ARMv6 CPU, try this project instead: 32 | https://github.com/warchildmd/google-assistant-hotword-raspi" 33 | exec $SHELL 34 | fi 35 | 36 | if [ -f $HOME/AIY-projects-python/src/AssistantPi.py ]; then 37 | echo -e "\e[1;31mError: AssistantPi is already installed.\e[0m 38 | Try running upgrade.sh or uninstall.sh instead." 39 | exec $SHELL 40 | fi 41 | 42 | if [ ! -f $HOME/assistant.json ]; then 43 | echo -e "\e[1;31mError: You need client secrets to use the Assistant API.\e[0m 44 | Follow these instructions: 45 | https://developers.google.com/api-client-library/python/auth/installed-app#creatingcred 46 | and put the file at $HOME/assistant.json" 47 | exec $SHELL 48 | fi 49 | 50 | sudo apt-get install git libttspico-utils python3-dev python3-numpy virtualenv 51 | 52 | git clone https://github.com/google/aiyprojects-raspbian.git $HOME/AIY-projects-python 53 | cd $HOME/AIY-projects-python 54 | 55 | virtualenv --system-site-packages -p python3 env 56 | env/bin/pip install -e src 57 | env/bin/pip install google-auth-oauthlib # HACK Temporary fix for missing dependency 58 | 59 | echo "$MAIN_PY" > src/AssistantPi.py 60 | echo "$SERVICE" | sudo tee /lib/systemd/system/AssistantPi.service > /dev/null 61 | 62 | sudo systemctl daemon-reload 63 | sudo systemctl enable AssistantPi.service 64 | 65 | python3 src/AssistantPi.py 66 | 67 | echo 68 | sudo systemctl start AssistantPi.service 69 | -------------------------------------------------------------------------------- /uninstall.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | read -p "Are you sure you want to uninstall the AssistantPi service? (y/n) " -n 1 -r 4 | if [[ ! $REPLY =~ ^[Yy]$ ]] 5 | then 6 | exec $SHELL 7 | fi 8 | echo 9 | 10 | sudo systemctl stop AssistantPi.service 11 | sudo systemctl disable AssistantPi.service 12 | 13 | sudo rm /lib/systemd/system/AssistantPi.service 14 | rm -rf $HOME/AIY-projects-python 15 | rm -rf $HOME/.cache/voice-recognizer 16 | -------------------------------------------------------------------------------- /upgrade.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | cd $HOME/AIY-projects-python 4 | 5 | git pull 6 | env/bin/pip install -U -e src 7 | 8 | sudo systemctl restart AssistantPi.service 9 | --------------------------------------------------------------------------------