Harvs
Harvs

Reputation: 533

How to run Google Assistant SDK on start-up?

How do I get google-assistant-demo to run on boot?

I can run it manually with

$ source /home/pi/env/bin/activate
(env) $ google-assistant-demo

But I want to run it on start up, in CLI Mode or GUI mode. I want it to run inside its virtual environment (venv). All in the background without interfering with any terminal or SSH session.

Upvotes: 1

Views: 6387

Answers (2)

G H
G H

Reputation: 1

This is what I did to achieve startup without a monitor (I think some call it headless?) on my Raspberry Pi Model B. Hope this helps!

  1. Record a sound file using arecord

https://developers.google.com/assistant/sdk/prototype/getting-started-pi-python/configure-audio

  1. In /home/pi/config/lxsession/LXDE-pi/autostart add

    @lxterminal --command "/home/pi/googlehome.sh"

Something like this

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@lxterminal --command "/home/pi/googlehome.sh"
@xscreensaver -no-splash
@point-rpi

Where googlehome.sh is the script that runs Google Assistant demo on startup.

  1. In googlehome.sh have it play a sound file then run the demo

    #!/bin/bash
    echo Running Google Home Assistant...
    sleep 2
    aplay --format=S16_LE --rate=16k "/home/pi/googlehomeready.raw"
    
    source env/bin/activate
    google-assistant-demo
    

Since I'm not sure when Google Assistant is ready when power on, I have it play a sound file googlehomeready.raw. Once I hear it, I know Google Assistant demo is running.

Oh, make sure change the mode type to executable for googlehome.sh.

Upvotes: 0

Harvs
Harvs

Reputation: 533

Using this as a base : https://youtu.be/ohUszBxuQA4?t=774 – thanks to Eric Parisot

However with a few changes.

You will need to download the src file he uses and extract its contents into /home/pi/src/

I did not run gassist.sh as sudo as he does in the video, as it gave me the following error:

OpenAlsaHandle PcmOpen: No such file or directory
[7689:7702:ERROR:audio_input_processor.cc(756)] Input error
ON_MUTED_CHANGED:
{‘is_muted’: False}
ON_START_FINISHED
ON_ASSISTANT_ERROR:
{‘is_fatal’: True}
[7689:7704:ERROR:audio_input_processor.cc(756)] Input error
ON_ASSISTANT_ERROR:
{‘is_fatal’: True}

Fix: DO NOT run as sudo

If gassist.sh gives an error about RPi.GPIO(the author's script activates GPIO pin 25 when the assistant is listening and so requires RPi.GPIO to be installed within the environment) you need to do https://youtu.be/ohUszBxuQA4?t=580:

$ source /home/pi/env/bin/activate
(env) $ pip install RPi.GPIO
(env) $ deactivate

And then I did sudo nano /etc/profile and the appended this to the end:

#Harvs was here on 24/06/17
if pidof -x "gassist.sh" >/dev/null; then
    echo ""
    echo "/etc/profile says:"
    echo "An instance of Google Assistant is already running, will not start again"
    echo ""
else
    echo "Starting Google Assistant..."
    echo "If you are seeing this, perhaps you have SSH within seconds of reboot"
    /home/pi/src/gassist.sh &
fi

This checks if the assistant is already running and starts it if it is not. Note if your start-up script is called something other than gassist.shyou will have to edit the above code

And now it works perfectly, inside the virtual environment, and in boot to CLI mode! :)

Upvotes: 1

Related Questions