【发布时间】:2018-03-01 18:02:23
【问题描述】:
如何从 hotword.py 代码中获取语音文本并对识别的文本执行我自己的操作,而不是让 Google 对文本做出反应?
我已经在 Pi3 上安装了 GA,在出现一些 USB 麦克风/模拟音频设置的初始问题以及缺少某些 Python 文件之后,我开始了: When installing Google Assistant, I an error "...googlesamples.assistant' is a package and cannot be directly executed..." 然后我按照 Google 下一步的步骤:https://developers.google.com/assistant/sdk/prototype/getting-started-pi-python/run-sample 并创建了一个新项目“myga/”,其中包含一个 hotword.py 文件:
def process_event(event):
"""Pretty prints events.
Prints all events that occur with two spaces between each new
conversation and a single space between turns of a conversation.
Args:
event(event.Event): The current event to process.
"""
if event.type == EventType.ON_CONVERSATION_TURN_STARTED:
print()
#GPIO.output(25,True) see https://stackoverflow.com/questions/44219740/how-can-i-get-an-led-to-light-on-google-assistant-listening
if event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED:
print("got some work to do here with the phrase or text spoken!")
print(event)
if (event.type == EventType.ON_CONVERSATION_TURN_FINISHED and
event.args and not event.args['with_follow_on_turn']):
print()
#GPIO.output(25,False) or also see https://blog.arevindh.com/2017/05/20/voice-activated-google-assistant-on-raspberry-pi-with-visual-feedback/
我希望代码对我认为的 ON_RECOGNIZING_SPEECH_FINISHED 事件做出反应,并且可以通过匹配简单的请求来执行我自己的操作,或者如果该短语不在我的列表中,则让 Google 处理它。我该怎么做?
最终我会问“OK Google,打开 BBC1”或“OK Google,播放我的播放列表”或“OK Google,显示流量”,hotword.py 会运行其他应用程序来完成这些任务。
谢谢,史蒂夫
【问题讨论】:
-
来自developers.google.com/assistant/sdk/reference/library/python,它可能涉及调用 stop_conversation() 以停止进一步处理。
标签: extract google-assistant-sdk