简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM