Page 1 of 3

GUIDE: Google Assistant on Raspbian

Posted: Thu Feb 08, 2018 12:10 pm
by tjohnson
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

Re: GUIDE: Google Assistant on Raspbian

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

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

Re: GUIDE: Google Assistant on Raspbian

Posted: Wed Feb 21, 2018 6:23 pm
by tjohnson
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?

Re: GUIDE: Google Assistant on Raspbian

Posted: Sat Feb 24, 2018 9:20 am
by Neavvy
Thanks for your reply, I solved my problem.

Yes, this works fast.

Re: GUIDE: Google Assistant on Raspbian

Posted: Mon Mar 05, 2018 11:02 pm
by loefkvist
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?

Re: GUIDE: Google Assistant on Raspbian

Posted: Tue Mar 06, 2018 3:14 am
by tjohnson
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.

Re: GUIDE: Google Assistant on Raspbian

Posted: Tue Mar 06, 2018 11:24 pm
by loefkvist
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?

Re: GUIDE: Google Assistant on Raspbian

Posted: Wed Mar 07, 2018 1:03 am
by tjohnson
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

Re: GUIDE: Google Assistant on Raspbian

Posted: Wed Mar 07, 2018 8:11 pm
by EchoTecho
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?

Re: GUIDE: Google Assistant on Raspbian

Posted: Thu Mar 08, 2018 12:15 pm
by tjohnson
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.

Re: GUIDE: Google Assistant on Raspbian

Posted: Thu Mar 08, 2018 2:18 pm
by DougieLawson
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

Re: GUIDE: Google Assistant on Raspbian

Posted: Thu Mar 08, 2018 3:09 pm
by EchoTecho
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!

Re: GUIDE: Google Assistant on Raspbian

Posted: Sat Mar 24, 2018 8:59 am
by chaosjester
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

Re: GUIDE: Google Assistant on Raspbian

Posted: Sat Mar 24, 2018 3:47 pm
by tjohnson
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.

Re: GUIDE: Google Assistant on Raspbian

Posted: Sun Mar 25, 2018 3:50 am
by chaosjester
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 :)

Re: GUIDE: Google Assistant on Raspbian

Posted: Sun Mar 25, 2018 4:26 am
by tjohnson
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.

Re: GUIDE: Google Assistant on Raspbian

Posted: Sat Mar 31, 2018 2:55 pm
by DrJohnW
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!

Re: GUIDE: Google Assistant on Raspbian

Posted: Tue Apr 10, 2018 2:26 pm
by tjohnson
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.

Re: GUIDE: Google Assistant on Raspbian

Posted: Sat Apr 14, 2018 4:04 pm
by Ryan780
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.

Re: GUIDE: Google Assistant on Raspbian

Posted: Sun Apr 15, 2018 2:39 pm
by Alimismail30
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:

Re: GUIDE: Google Assistant on Raspbian

Posted: Sat May 05, 2018 8:00 pm
by brunoholanda
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?

Re: GUIDE: Google Assistant on Raspbian

Posted: Fri May 11, 2018 4:27 am
by oss001
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?

Re: GUIDE: Google Assistant on Raspbian

Posted: Wed May 16, 2018 9:31 am
by WINNPC
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 .

Re: GUIDE: Google Assistant on Raspbian

Posted: Wed May 16, 2018 3:45 pm
by WINNPC
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

Re: GUIDE: Google Assistant on Raspbian

Posted: Sun May 20, 2018 12:42 am
by tjohnson
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.