问题描述
好的,首先,这里的主要想法是在到达时自动进行一些电灯开关。我住在一个会混淆 gps 的树林中,所以我对 tuya 等的到达功能不能按预期可靠地工作。它们有时确实有效,但我需要它可靠。
所以计划是安装 google 助手 sdk 并让 textinput 工作。下载并安装了所有东西,并做了谷歌云平台的事情,一切都很好。我可以在 cmd 中输入“关闭卧室灯”,卧室灯就会关闭。现在,这很好用,不要误会我的意思,我很可能可以调整它来满足我的需要。但这需要启动一个交互式控制台,然后实际输入我想问的短语。
这个问题的解决方案是,如果我可以用类似的东西来查询 textinput
py -m googlesamples.assistant.grpc.textinput --device-id "insert_device_id" --device-model-id "insert_device_model_id" --textquery "turn off the bedroom light"
这样我就不必启动交互式提示并手动退出它。我希望能够向助手发送文本,而无需与 Google 助手进行任何交互。
最终目标是使用我的电脑ping我的手机静态IP地址,并通过PC上的谷歌助手打开设备/灯。
解决方法
只是为了让您入门,这是基于 sample source code 的替代方案:
# Add along with other click.options
@click.option('--textquery',metavar='<text to send>',required=False,help=(('Text to send. If not specified,use interactive mode')))
# Next add the flag to main
def main(api_endpoint,credentials,device_model_id,device_id,lang,display,verbose,grpc_deadline,textquery,*args,**kwargs):
# Then the main loop
with SampleTextAssistant(lang,grpc_channel,grpc_deadline) as assistant:
while True:
# If textquery data set,use that as the query
if textquery:
query = textquery
else:
query = click.prompt('')
click.echo('<you> %s' % query)
response_text,response_html = assistant.assist(text_query=query)
if display and response_html:
system_browser = browser_helpers.system_browser
system_browser.display(response_html)
if response_text:
click.echo('<@assistant> %s' % response_text)
# If we're doing text,quit the loop
if textquery:
break
虽然完全未经测试,但希望您能理解!