X
    Categories: Projects

Voice Activated Google Assistant for Raspberry Pi

How to install voice activated google assistant for raspberry pi, also known as google home. this is a early adoption of integrating google home to our raspberry pi, more tutorials will follow soon. thanks for the view!!

Equipment List

USB Microphone ► http://amzn.to/2qCx4zY

Raspberry Pi 3 ► Amazon | Ebay

Websites

developer console

https://console.cloud.google.com/project

google assistant tutorial

https://developers.google.com/assistant/sdk/prototype/getting-started-pi-python/config-dev-project-and-account

command line:

sudo apt-get install python3-dev python3-venv
python3 -m venv env
env/bin/python -m pip install --upgrade pip setuptools --upgrade
source env/bin/activate

Downloading libs for google assistant

python -m pip install --upgrade https://github.com/googlesamples/assistant-sdk-python/releases/download/0.3.0/google_assistant_library-0.0.2-py2.py3-none-linux_armv7l.whl

oauth tool

python -m pip install --upgrade google-auth-oauthlib[tool]

obtaining oauth key. replace idxxx with your client id file

google-oauthlib-tool --client-secrets /home/pi/Downloads/client_secret_client-idxxx.json --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save --headless

to run google assistant

google-assistant-demo
novaspirit: Avid Thinker, Computer Programmer, Web evangelist, Hacking / Breaking expert, Problem Solver, Technology Obsessed, Gamer, 3D printing, Coffee lover!

View Comments (80)

  • Great one thanks all setup and working, however I would like to use this in headless mode - do you know how I would make this autostart at boot?

    Thanks again, great, and easy to follow!!! :D

  • How do I get it to automatically start when rebooting? I'm not too familiar with Linux, but right now for me to start it immediately after logging in with the pi account, I type ~/env/bin/google-assistant-demo and hit enter and it starts.

    Thanks in advance!

    • I wrote a bash script with the invocation instruction and made a launch daemon call it at startup. See here for the launch daemon:
      https://pastebin.com/7T19cw5t

      This is the actual start.sh script:
      #!/bin/sh
      /home/pi/git/GoogleHome/env/bin/google-assistant-demo

      you can test the launcher daemon by entering:
      sudo /etc/init.d/launch-at-startup start
      and
      sudo /etc/init.d/launch-at-startup stop

      • I am new to this so can u please explain it how to setup this in step by step. Thanks in advance.

        • I got it working thanks to Fraks comment! So here's what I had to do.

          sudo nano /etc/init.d/launch-at-startup
          then paste in all of the RAW Paste lines (I first tried the regular section from his link and it errored out with numerous line errors so I deleted the contents of the launch-at-startup and replaced them with the RAW Paste data) and hit ctrl+x then y to save the file.

          Next to make that script executable type sudo chmod +x /etc/init.d/launch-at-startup

          Next cd over to /home/pi and type nano start.sh and then paste in these two lines, keeping in mind the 2nd line should be the actual command that will start your google-assistant-demo.

          #!/bin/sh
          /home/pi/env/bin/google-assistant-demo
          and save those two lines

          Again I ran the chmod +x /home/pi/start.sh to make the script executable.

          Now to test things up to this point you can try to check the status of it and it should be stopped by running "sudo /etc/init.d/launch-at-startup status" and it should return it's status and no error messages or anything. You can also try to change status to start and see if it starts up and runs! At this point it actually ran for me by running "sudo /etc/init.d/launch-at-startup start"

          You can also test just the start.sh script by running "sudo ./home/pi/start.sh" if this doesn't launch and work then you need to figure out what your path is to start the google assistant and replace that 2nd line in the start.sh file with the correct path and stuff.

          If you have everything working right up to here, the next step you'll need to do in order to make it automatically start after boot is to run this line
          "sudo update-rc.d launch-at-startup defaults" and you should now have an automatically starting Google Assistant!

          Thanks again to Frak for helping out with this startup script! I'm pretty novice at Linux and this was a challenge to get setup but it's working fine now! I wish I knew how we could get stuff like Pandora and other things like that working on here now.

          • I followed everything but for some reason it gives me following error:

            sudo ./home/pi/start.sh
            sudo: ./home/pi/start.sh: command not found

            this is what i have in start.sh

            #!/bin/sh
            /home/pi/env/bin/google-assistant-demo

            and i do see google-assistant-demo in that location. i tried right clicking that demo file and executing in terminal and it works. but for some reason that start.sh is not working

          • ok here are my results:

            when i run sudo /etc/init.d/launch-at-startup start google starts in the back ground and it works.

            then i ran sudo update-rc.d launch-at-startup defaults and restarted the raspberry pi. it loaded the desktop and i asked questions starting hey google and i got no answers. so i am assumed its not running in back ground . I waited 2 minutes but same result.

            can you please help me figure out what is going wrong. i am new to raspberry pi

          • hello, I am getting every day a little further!

            Since I am totally new to this ans since I had suddenly sound problems, I did format my sd card and reinstall the hole thing from scratch! I think it is maybe the best way to learn!

            Still having problems with the auto start post following your post

            "... You can also test just the start.sh script by running “sudo ./home/pi/start.sh” if this doesn’t launch and work then you need to figure out what your path is to start the google assistant and replace that 2nd line in the start.sh file with the correct path and stuff."

            Until there I managed so far every thing but when typing

            pi@raspberrypi:~ $ sudo /home/pi/start.sh
            I get:
            usage: google-assistant-demo [-h] [--credentials OAUTH2_CREDENTIALS_FILE]
            google-assistant-demo: error: argument --credentials: No such file or directory: "/root/.config/google-oauthlib-tool/credentials.json"

            Google assistant is working, so what can I do?

            Thank you for you help,

            Best Nora

  • is there any way for this to work on raspberry pi 2? it doesnt have armv7.1, so it seems to work only in raspberry pi 3. any ideas?

    • Is there a way to have it automatically start this up? I just want to be able to reboot the Pi and have the Google-Assistant-Demo process kick off and start automatically and not quit! I'm having a nightmare of a time trying to figure out how to use init.d with this to make it start!! Can you point me in the direction to get this Pi setup so it'll automatically run the assistant?

  • Hi Don,
    I am following your guide and have a problem with the following command:
    env/bin/python -m pip install –upgrade pip setuptools –upgrade

    I get an exception:
    Traceback (most recent call last):
    File "/home/pi/env/lib/python3.4/site-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
    File "/home/pi/env/lib/python3.4/site-packages/pip/commands/install.py", line 269, in run
    InstallRequirement.from_line(name, None))
    File "/home/pi/env/lib/python3.4/site-packages/pip/req.py", line 173, in from_line
    return cls(req, comes_from, url=url, prereleases=prereleases)
    File "/home/pi/env/lib/python3.4/site-packages/pip/req.py", line 71, in __init__
    req = pkg_resources.Requirement.parse(req)
    File "/home/pi/env/lib/python-wheels/setuptools-5.5.1-py2.py3-none-any.whl/pkg_resources.py", line 2793, in parse
    reqs = list(parse_requirements(s))
    File "/home/pi/env/lib/python-wheels/setuptools-5.5.1-py2.py3-none-any.whl/pkg_resources.py", line 2708, in parse_requirements
    raise ValueError("Missing distribution spec", line)
    ValueError: ('Missing distribution spec', '–upgrade')

    Total Noob here, any help would be appreciated.

    • Try to use double dashes in front of one or both of the upgrade switches. --upgrade. I think that's where my problem was.

      • See if you can find the commands on the actual Google assistant sdk walkthrough, it has the correct dashes that I had to use.

        • Try write the command by yourself. I had some trouble because of the font used here on the site. The "-" was not interpreted correctly.
          Also in the next command (the long one), notice that its an "l" like in L in the end and NOT number one! (if you type it by yourself it's easy to be mistaken).

  • Hi Don,
    When I run this
    google-oauthlib-tool --client-secrets /home/pi/Downloads/client_secret_myid.json --scope https://www.googleapis.com/auth/assistant-sdk-prototype --save --headless

    I get the below error
    Traceback (most recent call last):
    File "/home/pi/env/bin/google-oauthlib-tool", line 11, in
    sys.exit(main())
    File "/home/pi/env/lib/python3.4/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
    File "/home/pi/env/lib/python3.4/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
    File "/home/pi/env/lib/python3.4/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
    File "/home/pi/env/lib/python3.4/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
    File "/home/pi/env/lib/python3.4/site-packages/google_auth_oauthlib/tool/__main__.py", line 100, in main
    scopes=scope
    File "/home/pi/env/lib/python3.4/site-packages/google_auth_oauthlib/flow.py", line 165, in from_client_secrets_file
    client_config = json.load(json_file)
    File "/usr/lib/python3.4/json/__init__.py", line 268, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
    File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
    return _default_decoder.decode(s)
    File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    File "/usr/lib/python3.4/json/decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
    ValueError: Expecting value: line 1 column 2 (char 1).

    Kindly help me,
    Thanks in advance.

  • I'm trying to obtain my oauth key but I'm getting an error says: Missing option "--client-secrets".
    Any help?

    • you probally forgot to change the big dash to 2 little ones in front of client.

  • I worked on this for 3 hours and still can't get it working. If you want people to use your instructions please fix your lines of code. I don't know lenux so this was very hard to trubsht.

    • You probably hit the same problems I did with the --upgrade and stuff like that, the instructions showed single dashes in a lot of places I ended up needing the double dashes. If that's where your problems are, check this site here and specifically look at the #4 link on the bottom: https://developers.google.com/assistant/sdk/prototype/getting-started-pi-python/

      The commands there are exact I believe. I'm happy to help, I've got it working a few different times after wiping and restarting.

Related Post