How can I get an LED to light on Google Assistant listening?

て烟熏妆下的殇ゞ 提交于 2019-12-11 05:55:02

问题


After a long research without any results, I'm trying my luck here. I recently got the GA SDK sample to work on my Raspberry Pi 3.

Now I would like to light my connected LED when the Assistant is listening. I know how to do this, but I don't know where to add the code for the LED in the Assistant sample code. The documentation on their website says it's in the grpc code, but I don't know any more than that.

Any advice on where to add the LED code?


回答1:


Look at the hotword sample here https://github.com/googlesamples/assistant-sdk-python/blob/master/google-assistant-sdk/googlesamples/assistant/library/hotword.py

You can use the events to write your GPIO logic to turn on/off the LED. Something like this -

`def process_event(event):
    if event.type == EventType.ON_CONVERSATION_TURN_STARTED:
        print()
        GPIO.output(25,True)
    if (event.type == EventType.ON_CONVERSATION_TURN_FINISHED and
            event.args and not event.args['with_follow_on_turn']):
        print()
        GPIO.output(25,False)
    if (event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED and
            event.args and not event.args['with_follow_on_turn']):
        print()`

here's the documentation on the library- https://developers.google.com/assistant/sdk/reference/library/python/



来源:https://stackoverflow.com/questions/44219740/how-can-i-get-an-led-to-light-on-google-assistant-listening

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!