tjohnson
Posts: 28
Joined: Sat Jun 11, 2016 7:39 pm
Location: Pennsylvania, USA

GUIDE: Google Assistant on Raspbian

Thu Feb 08, 2018 12:10 pm

I know there are already a number of guides online for this, but after setting it up myself and needing to search for information across multiple sites, I thought it would be helpful to have a consolidated guide. Here it is.

To set up Google Assistant on Raspbian, the only things you need are a Pi 2 or 3, a speaker, and a microphone. You can optionally wire an LED to GPIO pin 25 to add a visual status indicator.

NOTE: As of 2018-08-03, these instructions no longer work because Google has changed the installation process for the Assistant SDK. I have created a GitHub repo with new instructions, please try them instead: https://github.com/t1m0thyj/AssistantPi

  1. Follow these steps to add a Google Assistant device to your Google account:
    https://developers.google.com/assistant ... nd-account
    Step 4 is confusing and can be ignored (step 2 below replaces it).
  2. The JSON file that you downloaded needs to be copied to your Pi. Copy it to the /home/pi directory and rename it to assistant.json.
  3. Open a terminal on the Pi and run these commands:

    Code: Select all

    git clone https://github.com/google/aiyprojects-raspbian.git ~/AIY-projects-python
    cd ~/AIY-projects-python
    wget https://raw.githubusercontent.com/google/aiyprojects-raspbian/voicekit/scripts/install-deps.sh -nc -P scripts
    chmod +x scripts/install-deps.sh
    scripts/install-deps.sh
    sudo scripts/install-services.sh
    echo "$HOME/AIY-projects-python/src" > $HOME/AIY-projects-python/env/lib/python3.5/site-packages/aiy.pth
    ln -s examples/voice/assistant_library_with_local_commands_demo.py src/main.py
    sudo systemctl enable voice-recognizer.service
    
    The last two commands set up the voice recognizer service, which runs Assistant when the Pi boots.
  4. If you are using a USB microphone, some audio settings on the Pi must be changed for it to work with Assistant. Follow steps 2 and 3 here to fix it:
    https://developers.google.com/assistant ... ware/audio
    The (card number, device number) values that you want will likely be 1,0 for the mic and 0,0 for the speaker.
  5. Open a terminal window and run these commands:

    Code: Select all

    cd ~/AIY-projects-python
    source env/bin/activate
    python3 src/main.py
    
    If there is a web link in the terminal, click it to grant the necessary permissions to your Google account.
  6. You should now be able to say "OK Google" and have a conversation with your Pi. Try rebooting your Pi (saying "OK Google reboot" should do this), and test that Assistant still works after booting without having to start it manually.
  7. If you want to code custom actions for Google Assistant, they can easily be added in the Python script src/main.py. Details about how to do this can be found in Google's Maker's Guide for this project: https://aiyprojects.withgoogle.com/voice#makers-guide
Resources How to Update
To update the Assistant API on Raspbian to a newer version, run these commands:

Code: Select all

cd ~/AIY-projects-python
git checkout aiyprojects
git pull origin aiyprojects
rm -rf ~/AIY-projects-python/env
scripts/install-deps.sh
sudo systemctl restart voice-recognizer.service
Last edited by tjohnson on Mon Aug 13, 2018 11:22 am, edited 8 times in total.

Neavvy
Posts: 2
Joined: Wed Dec 13, 2017 7:50 pm

Re: GUIDE: Google Assistant on Raspbian

Wed Feb 21, 2018 3:02 pm

https://drive.google.com/file/d/1tyTla5 ... sp=sharing

I got error as you can see at the photo. What am I doing wrong?

tjohnson
Posts: 28
Joined: Sat Jun 11, 2016 7:39 pm
Location: Pennsylvania, USA

Re: GUIDE: Google Assistant on Raspbian

Wed Feb 21, 2018 6:23 pm

Neavvy wrote:
Wed Feb 21, 2018 3:02 pm
https://drive.google.com/file/d/1tyTla5 ... sp=sharing

I got error as you can see at the photo. What am I doing wrong?
Based on the error, it seems like the Assistant SDK is not finding valid credentials in the file /home/pi/assistant.json. Have you created an OAuth Client ID as explained here, downloaded the client secret JSON file to your Pi, and renamed it to "assistant.json"?

Also, it looks like you're running Ubuntu with GNOME on your Pi. I've considered doing that too, I'm curious how resource intensive it is. Does it run fast?

Neavvy
Posts: 2
Joined: Wed Dec 13, 2017 7:50 pm

Re: GUIDE: Google Assistant on Raspbian

Sat Feb 24, 2018 9:20 am

Thanks for your reply, I solved my problem.

Yes, this works fast.

loefkvist
Posts: 2
Joined: Mon Mar 05, 2018 10:53 pm

Re: GUIDE: Google Assistant on Raspbian

Mon Mar 05, 2018 11:02 pm

I keep getting an exception when running the install-deps.sh script:

---
Exception:
Traceback (most recent call last):
File "/home/pi/voice-recognizer-raspi/env/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 594, in urlopen
chunked=chunked)
File "/home/pi/voice-recognizer-raspi/env/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 391, in _make_request
six.raise_from(e, None)
...
---

Full exception text here:
https://docs.google.com/document/d/1Qud ... sp=sharing

Seems like it is trying to get something from a server which does not respond correctly.

Any idea how to fix this?

tjohnson
Posts: 28
Joined: Sat Jun 11, 2016 7:39 pm
Location: Pennsylvania, USA

Re: GUIDE: Google Assistant on Raspbian

Tue Mar 06, 2018 3:14 am

loefkvist wrote:
Mon Mar 05, 2018 11:02 pm
I keep getting an exception when running the install-deps.sh script:

---
Exception:
Traceback (most recent call last):
File "/home/pi/voice-recognizer-raspi/env/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 594, in urlopen
chunked=chunked)
File "/home/pi/voice-recognizer-raspi/env/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 391, in _make_request
six.raise_from(e, None)
...
---

Full exception text here:
https://docs.google.com/document/d/1Qud ... sp=sharing

Seems like it is trying to get something from a server which does not respond correctly.

Any idea how to fix this?
Judging by the full exception text, it seems like pip gets disconnected in the middle of downloading dependencies. I've experienced the same problem before, and unfortunately don't know how to fix it, I just had to keep retrying and it worked for me after a few tries. Sorry I can't be more helpful.

loefkvist
Posts: 2
Joined: Mon Mar 05, 2018 10:53 pm

Re: GUIDE: Google Assistant on Raspbian

Tue Mar 06, 2018 11:24 pm

tjohnson wrote:
Tue Mar 06, 2018 3:14 am
loefkvist wrote:
Mon Mar 05, 2018 11:02 pm
I keep getting an exception when running the install-deps.sh script:

...removed content...
Judging by the full exception text, it seems like pip gets disconnected in the middle of downloading dependencies. I've experienced the same problem before, and unfortunately don't know how to fix it, I just had to keep retrying and it worked for me after a few tries. Sorry I can't be more helpful.
Ok - after running the script a several times it finally succeded.
Thanks for the input.

Now when actually running the thing I end up with this:
--
[email protected]:~/voice-recognizer-raspi $ source env/bin/activate
(env) [email protected]:~/voice-recognizer-raspi $ python3 src/main.py
Traceback (most recent call last):
File "src/main.py", line 35, in <module>
from google.assistant.library import Assistant
ImportError: No module named 'google.assistant.library'
(env) [email protected]:~/voice-recognizer-raspi $
---

Sooo.... had to (re-)install the google.assistant.library:
$> env/bin/pip install google-assistant-library==0.0.2

Running main.py again then asks me to authorize and blah - did this and ended up with:
---
[2018-03-06 23:14:25,909] INFO:root:OAuth credentials initialized: /home/pi/.cache/voice-recognizer/assistant_credentials.json
Traceback (most recent call last):
File "src/main.py", line 101, in <module>
main()
File "src/main.py", line 95, in main
with Assistant(credentials, model_id) as assistant:
TypeError: __init__() takes 2 positional arguments but 3 were given
---

__init__() must be called from the Assistant code I guess but this is within the lib itself?

Any ideas?

tjohnson
Posts: 28
Joined: Sat Jun 11, 2016 7:39 pm
Location: Pennsylvania, USA

Re: GUIDE: Google Assistant on Raspbian

Wed Mar 07, 2018 1:03 am

loefkvist wrote:
Tue Mar 06, 2018 11:24 pm
Sooo.... had to (re-)install the google.assistant.library:
$> env/bin/pip install google-assistant-library==0.0.2

Running main.py again then asks me to authorize and blah - did this and ended up with:
---
[2018-03-06 23:14:25,909] INFO:root:OAuth credentials initialized: /home/pi/.cache/voice-recognizer/assistant_credentials.json
Traceback (most recent call last):
File "src/main.py", line 101, in <module>
main()
File "src/main.py", line 95, in main
with Assistant(credentials, model_id) as assistant:
TypeError: __init__() takes 2 positional arguments but 3 were given
---

__init__() must be called from the Assistant code I guess but this is within the lib itself?

Any ideas?
Version 0.0.2 of the Google Assistant library won't work with the latest version of the code on GitHub. Try installing a newer version:

Code: Select all

pip3 install google-assistant-library==0.1.0

EchoTecho
Posts: 4
Joined: Wed Feb 21, 2018 7:41 pm
Location: Moncton, NB, Canada

Re: GUIDE: Google Assistant on Raspbian

Wed Mar 07, 2018 8:11 pm

Currently getting this error running python3 src/main.py

Traceback (most recent call last):
File "src/main.py", line 31, in <module>
import aiy.assistant.auth_helpers
File "/home/UserNameIsNotPi/voice-recognizer-raspi/src/aiy/assistant/auth_helpers.py", line 24, in <module>
import google_auth_oauthlib.flow
ImportError: No module named 'google_auth_oauthlib'

Currently trying this on Ubuntu Mate 16.04.4 on Raspberry Pi 3 Model B

Anyone know how to fix this?

tjohnson
Posts: 28
Joined: Sat Jun 11, 2016 7:39 pm
Location: Pennsylvania, USA

Re: GUIDE: Google Assistant on Raspbian

Thu Mar 08, 2018 12:15 pm

EchoTecho wrote:
Wed Mar 07, 2018 8:11 pm
Currently getting this error running python3 src/main.py

Traceback (most recent call last):
File "src/main.py", line 31, in <module>
import aiy.assistant.auth_helpers
File "/home/UserNameIsNotPi/voice-recognizer-raspi/src/aiy/assistant/auth_helpers.py", line 24, in <module>
import google_auth_oauthlib.flow
ImportError: No module named 'google_auth_oauthlib'

Currently trying this on Ubuntu Mate 16.04.4 on Raspberry Pi 3 Model B

Anyone know how to fix this?
The Assistant SDK needs to be run in a virtual environment in order to find the Google libraries. Try running:

Code: Select all

source env/bin/activate
in the terminal before launching the Python script. This enables the virtual environment that has the Google packages installed, so every time you want to run the Python script it needs to be activated first.

User avatar
DougieLawson
Posts: 35347
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: GUIDE: Google Assistant on Raspbian

Thu Mar 08, 2018 2:18 pm

You need to install the pre-requisites for Google assistant.
See https://github.com/google/aiyprojects-raspbian
Specifically: https://github.com/google/aiyprojects-r ... ements.txt
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

EchoTecho
Posts: 4
Joined: Wed Feb 21, 2018 7:41 pm
Location: Moncton, NB, Canada

Re: GUIDE: Google Assistant on Raspbian

Thu Mar 08, 2018 3:09 pm

DougieLawson wrote:
Thu Mar 08, 2018 2:18 pm
You need to install the pre-requisites for Google assistant.
See https://github.com/google/aiyprojects-raspbian
Specifically: https://github.com/google/aiyprojects-r ... ements.txt
After installing those, the script worked and I authorized the application.

Thanks!

chaosjester
Posts: 2
Joined: Sat Mar 24, 2018 8:57 am

Re: GUIDE: Google Assistant on Raspbian

Sat Mar 24, 2018 8:59 am

I have followed this guide and have everything working, however I have 2 issues.

1 is that the reply volume is really low, lower than my system settings and lower than any other applications that make noise.

2 is that when I say OK Google, my screen connected via GPIO pins goes white and stays white.

Does anyone have any ideas what I can do?

TIA

tjohnson
Posts: 28
Joined: Sat Jun 11, 2016 7:39 pm
Location: Pennsylvania, USA

Re: GUIDE: Google Assistant on Raspbian

Sat Mar 24, 2018 3:47 pm

chaosjester wrote:
Sat Mar 24, 2018 8:59 am
I have followed this guide and have everything working, however I have 2 issues.

1 is that the reply volume is really low, lower than my system settings and lower than any other applications that make noise.

2 is that when I say OK Google, my screen connected via GPIO pins goes white and stays white.

Does anyone have any ideas what I can do?

TIA
Regarding the volume, unfortunately Google Assistant doesn't seem to be controlled by system volume on the Pi. Try saying "OK Google, set volume to max" and that should fix it.

Regarding the screen, what GPIO pin(s) is it connected to? The Assistant SDK uses pin 25 by default to flash an LED when you say "OK Google". Perhaps that's messing with your screen, I don't know what to suggest otherwise.

chaosjester
Posts: 2
Joined: Sat Mar 24, 2018 8:57 am

Re: GUIDE: Google Assistant on Raspbian

Sun Mar 25, 2018 3:50 am

tjohnson wrote:
Sat Mar 24, 2018 3:47 pm
Regarding the volume, unfortunately Google Assistant doesn't seem to be controlled by system volume on the Pi. Try saying "OK Google, set volume to max" and that should fix it.

Regarding the screen, what GPIO pin(s) is it connected to? The Assistant SDK uses pin 25 by default to flash an LED when you say "OK Google". Perhaps that's messing with your screen, I don't know what to suggest otherwise.
Thanks, the volume command did the trick.

My LCD is connected to pin 25, have checked if there is any way to disable the LED, but so far nothing has done the job, will keep investigating that though, thank you :)

tjohnson
Posts: 28
Joined: Sat Jun 11, 2016 7:39 pm
Location: Pennsylvania, USA

Re: GUIDE: Google Assistant on Raspbian

Sun Mar 25, 2018 4:26 am

chaosjester wrote:
Sun Mar 25, 2018 3:50 am
My LCD is connected to pin 25, have checked if there is any way to disable the LED, but so far nothing has done the job, will keep investigating that though, thank you :)
If changing the GPIO pin used by the LED is sufficient, I think it should be possible to do so by changing the _GPIO_LED constant at the top of /src/aiy/voicehat.py. If you need to disable the LED completely, that would be significantly more difficult as you mentioned.

DrJohnW
Posts: 2
Joined: Fri Oct 20, 2017 12:46 am

Re: GUIDE: Google Assistant on Raspbian

Sat Mar 31, 2018 2:55 pm

When it comes to registering a device, it asks for a device type. I did not see "computer", but saw other devices like Vacuum, Thermostat, Scene, Camera and the like. I tried selecting "Scene", but when it comes to running the code, I get:
Traceback (most recent call last):
File "src/main.py", line 101, in <module>
main()
File "src/main.py", line 94, in main
model_id, device_id = aiy.assistant.device_helpers.get_ids(credentials)
File "/home/pi/voice-recognizer-raspi/src/aiy/assistant/device_helpers.py", line 98, in get_ids
model_id = model_id or _get_model_id(credentials, session, project_id)
File "/home/pi/voice-recognizer-raspi/src/aiy/assistant/device_helpers.py", line 79, in _get_model_id
r.raise_for_status()
File "/home/pi/voice-recognizer-raspi/env/lib/python3.5/site-packages/requests/models.py", line 928, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://embeddedassistant.googleapis.co ... viceModels

Is there a different device type I should select or is there a way around selecting a device type? Thanks in advance!

tjohnson
Posts: 28
Joined: Sat Jun 11, 2016 7:39 pm
Location: Pennsylvania, USA

Re: GUIDE: Google Assistant on Raspbian

Tue Apr 10, 2018 2:26 pm

DrJohnW wrote:
Sat Mar 31, 2018 2:55 pm
When it comes to registering a device, it asks for a device type. I did not see "computer", but saw other devices like Vacuum, Thermostat, Scene, Camera and the like. I tried selecting "Scene", but when it comes to running the code, I get:
Traceback (most recent call last):
File "src/main.py", line 101, in <module>
main()
File "src/main.py", line 94, in main
model_id, device_id = aiy.assistant.device_helpers.get_ids(credentials)
File "/home/pi/voice-recognizer-raspi/src/aiy/assistant/device_helpers.py", line 98, in get_ids
model_id = model_id or _get_model_id(credentials, session, project_id)
File "/home/pi/voice-recognizer-raspi/src/aiy/assistant/device_helpers.py", line 79, in _get_model_id
r.raise_for_status()
File "/home/pi/voice-recognizer-raspi/env/lib/python3.5/site-packages/requests/models.py", line 928, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://embeddedassistant.googleapis.co ... viceModels

Is there a different device type I should select or is there a way around selecting a device type? Thanks in advance!
Sorry for the delay in replying, I've been extremely busy with school recently. It's been a while since I've registered my device, so I might be wrong about this, but I don't think it should be necessary to select a device type following these instructions: https://aiyprojects.withgoogle.com/voic ... d-platform
If it still requires selecting a device type I would suggest trying Light, but I believe the Assistant SDK should automatically handle the device type.

Ryan780
Posts: 7
Joined: Wed Sep 06, 2017 2:12 pm

Re: GUIDE: Google Assistant on Raspbian

Sat Apr 14, 2018 4:04 pm

I was wondering if this version of the Assistant supported the new Broadcasts feature because I can't seem to get it to receive broadcasts that other home devices are receiving.

Alimismail30
Posts: 1
Joined: Sun Apr 15, 2018 2:34 pm

Re: GUIDE: Google Assistant on Raspbian

Sun Apr 15, 2018 2:39 pm

Good day.
I ran into a issue which I can’t seem to fix.
When I paste source env/bin/activate
It say “bash: env/bin/activate: No Such File or Directory”

Could you please help me. Thanks :oops:

brunoholanda
Posts: 1
Joined: Sat May 05, 2018 7:58 pm

Re: GUIDE: Google Assistant on Raspbian

Sat May 05, 2018 8:00 pm

Neavvy wrote:
Wed Feb 21, 2018 3:02 pm
https://drive.google.com/file/d/1tyTla5 ... sp=sharing

I got error as you can see at the photo. What am I doing wrong?
How did you solve this problem?

oss001
Posts: 10
Joined: Tue Mar 05, 2013 9:07 pm

Re: GUIDE: Google Assistant on Raspbian

Fri May 11, 2018 4:27 am

When running install-deps.sh I am getting the following error output...
google-api-core 0.1.4 has requirement requests<3.0.0dev,>=2.18.0, but you'll have requests 2.14.2 which is incompatible.
Anyone know what I can do to resolve?

WINNPC
Posts: 2
Joined: Wed May 16, 2018 9:23 am

Re: GUIDE: Google Assistant on Raspbian

Wed May 16, 2018 9:31 am

EchoTecho wrote:
Thu Mar 08, 2018 3:09 pm
DougieLawson wrote:
Thu Mar 08, 2018 2:18 pm
You need to install the pre-requisites for Google assistant.
See https://github.com/google/aiyprojects-raspbian
Specifically: https://github.com/google/aiyprojects-r ... ements.txt
After installing those, the script worked and I authorized the application.

Thanks!
Dear friend , i have the same problem with you. Could you kindly help me how to fix its step by step . Many thanks in advance .

WINNPC
Posts: 2
Joined: Wed May 16, 2018 9:23 am

Re: GUIDE: Google Assistant on Raspbian

Wed May 16, 2018 3:45 pm

Traceback (most recent call last):
File "src/main.py", line 101, in <module>
main()
File "src/main.py", line 94, in main
model_id, device_id = aiy.assistant.device_helpers.get_ids(credentials)
File "/home/pi/voice-recognizer-raspi/src/aiy/assistant/device_helpers.py", line 98, in get_ids
model_id = model_id or _get_model_id(credentials, session, project_id)
File "/home/pi/voice-recognizer-raspi/src/aiy/assistant/device_helpers.py", line 79, in _get_model_id
r.raise_for_status()
File "/home/pi/voice-recognizer-raspi/env/lib/python3.5/site-packages/requests/models.py", line 928, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url: https://embeddedassistant.googleapis.co ... viceModels

Dear friend , I got this error --- how can I fix its. Many thanks in advance @EchoTecho @DrJohnW

tjohnson
Posts: 28
Joined: Sat Jun 11, 2016 7:39 pm
Location: Pennsylvania, USA

Re: GUIDE: Google Assistant on Raspbian

Sun May 20, 2018 12:42 am

Alimismail30 wrote:
Sun Apr 15, 2018 2:39 pm
Good day.
I ran into a issue which I can’t seem to fix.
When I paste source env/bin/activate
It say “bash: env/bin/activate: No Such File or Directory”

Could you please help me. Thanks :oops:
Make sure that in your terminal the current directory is ~/voice-recognizer-raspi (if not you can cd to it). If you ran all the commands in step 3 and they completed without errors, then the env/bin/activate file should exist.

Return to “General discussion”