Search code examples
pythongrpcgoogle-assistant-sdk

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


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?


Solution

  • 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/