1

如何让 google-assistant-demo 在启动时运行?

我可以手动运行它

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

但我想在启动时以 CLI 模式或 GUI 模式运行它。我希望它在其虚拟环境(venv)中运行。所有这些都在后台进行,不会干扰任何终端或 SSH 会话。

4

2 回答 2

1

以此为基础:https ://youtu.be/ohUszBxuQA4?t= 774 – 感谢 Eric Parisot

但是有一些变化。

您需要下载他使用的 src 文件并将其内容提取到/home/pi/src/

我没有像他在视频中那样跑gassist.shsudo因为它给了我以下错误:

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}

修复:不要运行为sudo

如果gassist.sh出现错误RPi.GPIO(作者的脚本在助手监听时激活 GPIO 引脚 25,因此需要环境中安装 RPi.GPIO),您需要执行https://youtu.be/ohUszBxuQA4?t=580

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

然后我做了sudo nano /etc/profile并将其附加到最后:

#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

这会检查助手是否已经在运行,如果没有则启动它。请注意,如果您的启动脚本被称为其他东西,gassist.sh您将不得不编辑上面的代码

现在它可以在虚拟环境中完美运行,并且可以启动到 CLI 模式!:)

于 2017-06-24T23:26:29.033 回答
0

这就是我在 Raspberry Pi Model B 上实现无显示器启动(我认为有些人称之为无头?)的方法。希望这会有所帮助!

  1. 使用 arecord 录制声音文件

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

  1. 在 /home/pi/config/lxsession/LXDE-pi/autostart 添加

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

像这样的东西

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

googlehome.sh 是在启动时运行 Google Assistant 演示的脚本。

  1. 在 googlehome.sh 中让它播放声音文件然后运行演示

    #!/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
    

由于我不确定开机时 Google 助理何时准备就绪,我让它播放声音文件 googlehomeready.raw。一旦我听到它,我就知道 Google Assistant 演示正在运行。

哦,确保将模式类型更改为 googlehome.sh 的可执行文件。

于 2017-07-06T16:41:09.543 回答