问题
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