How to wire a button on Raspberry Pi for Google Assistant SDK

我只是一个虾纸丫 提交于 2019-12-25 13:00:07

问题


The Google Assistant SDK example requires the user to hit enter before speaking to the Google Assistant.

I was wondering is there a way to wire a button to one of the RPI GPIO pins and have it trigger G.Assistant.

 while True:
        if wait_for_user_trigger:
            click.pause(info='Press Enter to send a new request...')
        continue_conversation = assistant.converse()
        # wait for user trigger if there is no follow-up turn in
        # the conversation.
        wait_for_user_trigger = not continue_conversation

        # If we only want one conversation, break.
        if once and (not continue_conversation):
            break

I suppose this would be the area where i make the change linking up the GPIO library.

How should I go about implementing it? Im new to Python and Raspberry Pi. I do have a Java background and automation history.


回答1:


This might help:

...
import os.path
import RPi.GPIO as GPIO
...
CLOSE_MICROPHONE = embbeded_assistant_pb2.ConverseResult.CLOSE_MICROPHONE

GPIO.setmode(GPIO.BMC)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(23, GPIO.OUT)
...
while True:
    if wait_for_user_trigger:
        input_state = GPIO.input(18)
        if input_state == True:
            GPIO.output(23, False)
            continue
        else:
            GPIO.output(23, True)
            pass
        #click.pause(info='Press Enter to send a new request...')

...

Reference: https://youtu.be/ImrN404aDcc



来源:https://stackoverflow.com/questions/43865157/how-to-wire-a-button-on-raspberry-pi-for-google-assistant-sdk

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