Giter Site home page Giter Site logo

janvda / balena-google-assistant Goto Github PK

View Code? Open in Web Editor NEW
15.0 3.0 5.0 36 KB

Docker build files for deploying the "google assistant" client on a raspberry pi 3 with Balena

License: Eclipse Public License 2.0

Shell 100.00%
balena balena-application balenacloud raspberry-pi balena-google-assistant google-assistant google-assistant-sdk

balena-google-assistant's Introduction

balena-google-assistant

Introduction

Runs the google assistant ("OK Google") on a raspberry pi.

In other words it turns your raspberry pi into a "google home" device

Hardware requirements

  1. speaker (or headphone) that is connected to the audio jack of the raspberry pi
  2. USB microphone (or webcam with microphone) that is connected to one of the USB ports of the raspberry pi.

STEP 1: Configure Google Project and Register Device Model

This repository is based on the instructions specified at: https://developers.google.com/assistant/sdk/guides/library/python/

So first you need to perform the following steps of these instructions:

  1. Configure a Developer Project and Account Settings. Write down the Project ID generated by google as you need it in STEP 2.
  2. Register the Device Model - you don't need to transfer the downloaded client secret to the raspberry pi. You will need it for setting the service variable "GOOGLE_ASSISTANT_CLIENT_SECRET" in the next step. Also write down the device model ID generated by google as you will also need this in next step.

STEP 2: deploy this balena application.

  1. Follow the standard instructions to create and deploy a balena application = amongst others: (fork and) clone this github repository, create the git remote for this balena application and then do a git push balena master (or similar command)
  2. As you have not set any service variables you will see errors in the log files.
  3. Set the following service variables using the balena dashboard.
Service Name Description
google_assistant GOOGLE_ASSISTANT_PROJECT_ID The project ID generated by google in previous step. Don't confuse this with the project name that you have specified.
google_assistant GOOGLE_ASSISTANT_DEVICE_MODEL_ID The device model id generated by google in previous step
google_assistant GOOGLE_ASSISTANT_CLIENT_SECRET The complete client secret (= json string) retrieved in previous step
  1. When the GOOGLE_ASSISTANT service is restarted you should see something like the following in the balena Logs (this also means that you can continue with the next step):
24.06.19 17:56:33 (+0200) Starting service 'google_assistant sha256:c392950370c392295ee322780bd29f97aead2dc2e1d739977b2f401b172d3c8d'
24.06.19 17:56:34 (+0200)  google_assistant  The credentials (/root/.config/google-oauthlib-tool/credentials.json) are not set !
24.06.19 17:56:34 (+0200)  google_assistant  ... Creating /client_secret.json based on the contents of device service variables GOOGLE_ASSISTANT_CLIENT_SECRET...
24.06.19 17:56:34 (+0200)  google_assistant  **********************************************************************
24.06.19 17:56:34 (+0200)  google_assistant  * You can now create the google credentials by launching the script: *
24.06.19 17:56:34 (+0200)  google_assistant  *                 /create_credentials.sh                             *
24.06.19 17:56:34 (+0200)  google_assistant  * in a balena terminal for the service 'google_assistant'.           *
24.06.19 17:56:34 (+0200)  google_assistant  **********************************************************************
24.06.19 17:56:34 (+0200) Started service 'google_assistant sha256:c392950370c392295ee322780bd29f97aead2dc2e1d739977b2f401b172d3c8d'

STEP 3: Create the (google assistant) credentials

  1. In Balena dashboard open a Terminal for the service "GOOGLE_ASSISTANT" and enter the command /create_credentials.sh You should see something like (I partially masked it):
root@f0bc010:/# /create_credentials.sh
Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=3983XXXXXXX84fb.apps.googleusercontent.com&redirect_uri=urn%3AietXXXXXXXh%3A2.0%3Aoob&scope=https%3A%2XXXXXXXapis.com%2Fauth%2Fassistant-sdk-prototype+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgcm&state=d720mXXXXXXXXXXXXXXXXXXXXXXXXXX&code_challenge=GXXXXXXXJs&code_challenge_method=SXXXXXXX6&prompt=consent&access_type=offline
Enter the authorization code:
  1. Copy paste above URL in a browser and follow the instructions as outlined in step 3. of Generate Credentials.
  2. copy paste the authorization code in the balena terminal window and you should get something like:
...
Enter the authorization code: 4/cgElC5XXXXXXXXXXXXXXXXXXXXXXXXXXXXXDe3iQ4U
credentials saved: /root/.config/google-oauthlib-tool/credentials.json
The credentials =
{"scopes": ["https://www.googleapis.com/auth/assistant-sdk-prototype", "https://www.googleapis.com/auth/gcm"], "client_id": "3983XXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com", "token_uri": "https://accounts.google.com/o/oauth2/token", "client_secret": "KiXXXXXXXXXXXXXXXXXXXc7", "refresh_token": "1/oohXXXXXXXXXXXXXXXXXXXXXX4s"}
You should now restart the google_assistant service.
root@f0bc010:/# 
  1. That is it. You can now restart the google_assistant service within the balena dashboard and you should see something like:
17.06.19 00:25:25 (+0200) Starting service 'google_assistant sha256:47e2a96dfd306851d3c4934cdf05eae46ab5d21b89c14303b44d37d5fd1c99a1'
17.06.19 00:25:26 (+0200)  google_assistant  Creating the /root/.config/google-oauthlib-tool/credentials.json using device service variable GOOGLE_ASSISTANT_CREDENTIALS ...
17.06.19 00:25:26 (+0200)  google_assistant  Starting googlesamples-assistant-hotword ...
17.06.19 00:25:26 (+0200) Started service 'google_assistant sha256:47e2a96dfd306851d3c4934cdf05eae46ab5d21b89c14303b44d37d5fd1c99a1'
17.06.19 00:25:31 (+0200)  google_assistant  device_model_id: pi3thrXXXXXXXXXXXXX44
17.06.19 00:25:31 (+0200)  google_assistant  device_id: B12XXXXXXXXXXXXX64E3
17.06.19 00:25:31 (+0200)  google_assistant  
17.06.19 00:25:36 (+0200)  google_assistant  Registering...Done.
17.06.19 00:25:36 (+0200)  google_assistant  
17.06.19 00:25:36 (+0200)  google_assistant  ON_MUTED_CHANGED:
17.06.19 00:25:36 (+0200)  google_assistant   {"is_muted": false}
17.06.19 00:25:36 (+0200)  google_assistant  ON_START_FINISHED
17.06.19 00:25:36 (+0200)  google_assistant  ON_MEDIA_STATE_IDLE

ALTERNATIVE STEP 3: Set google credentials through device service variable.

It is also possible to set the google credentials through the device service variable GOOGLE_ASSISTANT_CREDENTIALS. Of course in that case you must know the google credentials. This step is mainly there to be backwards compatible with version v1.0.0

Service Name Description
google_assistant GOOGLE_ASSISTANT_CREDENTIALS The complete credentials (= json string). If this environment variable is set then the google assistant at startup will first overwrite the contents of the file /root/.config/google-oauthlib-tool/credentials.json with the contents of this variable.

Troubleshooting & Issues

See also issues reported in this github repository (feel free to add your own issues)

1. (Very) Noisy audio

If the audio jack is not plugged correctly you will hear a lot of noise. In that case move the audio jack a bit more in or out until the noise is gone.

2. ERROR "google_assistant [FATAL:audio_input_stream.cc(47)] Input device could not be opened: default"

This indicates that the default audio input stream (= microphone) is not properly configured on your raspberry pi.

Miscellaneous

Testing the audio

You can test the speakers (audio) by running the following command in a terminal for the service "GOOGLE_ASSISTANT":

speaker-test -c2 -t wav

You can change the volume by running the command:

 alsamixer

balena-google-assistant's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

balena-google-assistant's Issues

make it easier to create the credentials

The step to create the credentials is rather cumbersome.
It requires manual copy pasting the created credentials json string into the device variable.

The idea is to eliminate this manual copy paste step.

Instead the created credentials will be stored on a volume (so it persists between restarts)
and at start will be copied to the right location (if needed).

For backwards compatibility we will still support the device variable GOOGLE_ASSISTANT_CREDENTIALSwhich will overrule any credentials stored on shared volume.

audio input setup issue

My USB mic is identified as HW:0 and my DAC as HW:1 when I create a file .asoundrc and asound.conf it i working fine to capture sound with arecord. But when I reboot the asoundrc id modified and the asound.conf is deleted.

Don't know why my config audio is reset at boot

thanks,
cheers.

error in hotword.py when launching googlesamples-assistant-hotword

log

(env) root@f0bc010:/# googlesamples-assistant-hotword --project-id pi3three-balena --device-model-id pi3three-balena-pi3three-balena-x3hx44 --credentials /credentials.json
Traceback (most recent call last):
  File "/env/bin/googlesamples-assistant-hotword", line 10, in <module>
    sys.exit(main())
  File "/env/lib/python3.5/site-packages/googlesamples/assistant/library/hotword.py", line 106, in main
    **json.load(f))
TypeError: __init__() got an unexpected keyword argument 'installed'
(env) root@f0bc010:/# 

Audio (via earphone) is silent.

The audio I hear is very silent.
It is still understandable but it would be nice if we could increase the volume.

Note that I have set sound level to maximum using alsamixer in service "GOOGLE_ASSISTANT" but this didn't make much different:

┌───────────────────────────────────────────────────────────────────────────────────────────────── AlsaMixer v1.1.3 ──────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Card: bcm2835 ALSA                                                                                                                                                                          F1:  Help               │
│ Chip: Broadcom Mixer                                                                                                                                                                        F2:  System information │
│ View: F3:[Playback] F4: Capture  F5: All                                                                                                                                                    F6:  Select sound card  │
│ Item: PCM [dB gain: 4.00]                                                                                                                                                                   Esc: Exit               │
│                                                                                                                                                                                                                     │
│                                                                                                                                                                                                                     │
│                                                                                                                                                                                                                     │
│                                                                                                                                                                                                                     │
│                                                                                                        ┌──┐                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        │▒▒│                                                                                                         │
│                                                                                                        ├──┤                                                                                                         │
│                                                                                                        │OO│                                                                                                         │
│                                                                                                        └──┘                                                                                                         │
│                                                                                                        100                                                                                                          │
│                                                                                                     <  PCM   >                                                                                                      │
│                                                                                                                                                                                                                     │

Create Credential Error

Hello,

i'm trying to get this done but always having this issue:

`root@63e465d:/# /create_credentials.sh
Traceback (most recent call last):
File "/env/bin/google-oauthlib-tool", line 8, in
sys.exit(main())
File "/env/lib/python3.5/site-packages/click/core.py", line 722, in call
return self.main(*args, **kwargs)
File "/env/lib/python3.5/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/env/lib/python3.5/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/env/lib/python3.5/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/env/lib/python3.5/site-packages/google_auth_oauthlib/tool/main.py", line 100, in main
scopes=scope
File "/env/lib/python3.5/site-packages/google_auth_oauthlib/flow.py", line 197, in from_client_secrets_file
client_config = json.load(json_file)
File "/usr/local/lib/python3.5/json/init.py", line 268, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/usr/local/lib/python3.5/json/init.py", line 319, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The credentials =
cat: /root/.config/google-oauthlib-tool/credentials.json: No such file or directory

You should now restart the google_assistant service !`

I can not find my fail.

Do you have any Idea?

starting the assistant takes a long time ... and doesn't answer anymore.

When asking any question, the assistant replies with "something went wrong, try again in a few seconds".

Here the log

22.06.19 10:50:58 (+0200) Starting service 'google_assistant sha256:1f510af2acf3b6b5c15a5a2e9a46eca062173b09981a8048afb673de137a2c78'
22.06.19 10:50:59 (+0200)  google_assistant  Creating the /root/.config/google-oauthlib-tool/credentials.json using device service variable GOOGLE_ASSISTANT_CREDENTIALS ...
22.06.19 10:50:59 (+0200)  google_assistant  Starting googlesamples-assistant-hotword ...
22.06.19 10:50:59 (+0200) Started service 'google_assistant sha256:1f510af2acf3b6b5c15a5a2e9a46eca062173b09981a8048afb673de137a2c78'
22.06.19 10:53:14 (+0200)  google_assistant  device_model_id: pi3three-balena-pi3three-balena-x3hx44
22.06.19 10:53:14 (+0200)  google_assistant  device_id: AEC9EB636CF0AB0ED212158FCDE7E682
22.06.19 10:53:14 (+0200)  google_assistant  
22.06.19 10:55:30 (+0200)  google_assistant  Registering...Done.
22.06.19 10:55:30 (+0200)  google_assistant  
22.06.19 10:55:30 (+0200)  google_assistant  ON_MUTED_CHANGED:
22.06.19 10:55:30 (+0200)  google_assistant    {"is_muted": false}
22.06.19 10:55:30 (+0200)  google_assistant  ON_MEDIA_STATE_IDLE
22.06.19 10:55:30 (+0200)  google_assistant  ON_START_FINISHED
22.06.19 10:55:30 (+0200)  google_assistant  

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.