2017-05-09 48 views
0

Google智能助理SDK示例要求用戶在與Google智能助理交談之前點擊輸入。如何在Google智能助理SDK上連接Raspberry Pi上的按鈕

我想知道有沒有辦法將按鈕連接到RPI GPIO引腳之一,並讓它觸發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 

我想這將是我做改變連接GPIO庫的區域。

我應該如何去實施它?我是Python和Raspberry Pi的新手。我確實有Java背景和自動化歷史。

回答

0

這可能幫助:

... 
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...') 

... 

參考:https://youtu.be/ImrN404aDcc

+1

感謝勞爾。就是這樣。也許對於Richards評論,你可以總結一下這些步驟。乾杯。 – VBaarathi

相關問題