如何从 hotword.py 代码中获取口语文本并对识别的文本执行我自己的操作,而不是 Google 对文本做出反应?
我已经在 Pi3 上安装了 GA,在 USB 麦克风/模拟音频设置出现一些初始问题并且某些 Python 文件丢失之后,我开始了: 安装 Google 助手时,出现错误“...googlesamples.assistant”是一个包和不能直接执行......” 然后我按照谷歌下一步步骤: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 将运行其他应用程序来完成这些任务。
谢谢,史蒂夫