python - Google Assistant API 停止响应“Ok google”。卡在 MEDIA_STATE_IDLE
问题描述
在过去的三天里,我一直在我的树莓派上使用 Gogle Assistant SDK。突然间,它停止了对提示的响应。我正在使用带有一些自定义代码的示例 hotword.py。
这是我在停止工作之前所做的所有事情的清单:
- 将控制灯光的代码从使用 os.system 启动程序更改为直接在程序中控制灯光。这包括:
-pip 在 env/bin/activate 源中安装 RPi.GPIO
-将该库导入谷歌的示例代码
- 从程序访问firebase的凭据
做完这些事情后,我重新启动了 pi,因为我在启动时使用这个 .sh 启动助手
#!/bin/bash
source env/bin/activate
cd assistant-sdk-python/google-assistant sdk/googlesamples/assistant/library
python hotword.py --device-model-id {model id}
它显示了这个预期的结果,但忽略了提示
ok (shown in below code)
device_model_id: {model id}
device_id: {device id}
ON_MUTED_CHANGED:
{"is_muted": false}
ON_MEDIA_STATE_IDLE
ON_START_FINISHED
我恢复了代码并安装了,但这并没有解决它。我不确定这些东西是否会引起问题,但我认为值得一提。
我还通过 export ASSISTANT_MIC_SENSITIVITY=-6 调高了麦克风灵敏度
这是一些hotword.py
# My imports
import RPi.GPIO as IO
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
#start my code --------------------------------------------------------
cred = credentials.Certificate('/path-to-certificate')
default_app = firebase_admin.initialize_app(cred, {
'databaseURL' : 'https://myproject.firebaseio.com/'
})
IO.setwarnings(False)
IO.setmode (IO.BOARD)
IO.setup(16,IO.OUT)
p = IO.PWM(16,50)
root = db.reference()
print("ok")
#end my code ----------------------------------------------------------
def process_event(event):
if event.type == EventType.ON_CONVERSATION_TURN_STARTED:
print()
print(event)
if event.type == EventType.ON_DEVICE_ACTION:
for command, params in event.actions:
print('Do command', command, 'with params', str(params))
#My code start ----------------------------------------------------------------
if command == "action.devices.commands.OnOff":
if params['on']:
print('Turning the LED on.')
currentVal = root.child('currentVal').get()
onVal = root.child('onAngle').get()
if(currentVal != onVal):
root.child('currentVal').set(onVal)
root.child('value').set(onVal)
p.ChangeDutyCycle(float(onVal))
time.sleep(0.5)
p.ChangeDutyCycle(0)
else:
#same as above different angles
#My code end ------------------------------------------------------------------
抱歉,如果代码太多,我不知道是什么导致了收听问题
该问题在 github 上仍然存在,网址为https://github.com/googlesamples/assistant-sdk-python/issues/316 人们似乎在 sdk v.1.01 而不是 v1 上遇到了问题。我的麦克风工作正常,我用记录验证了。
谢谢你的帮助。
解决方案
推荐阅读
- php - joedixon/laravel 翻译未更新
- java - 不执行通过 @query 注释对 Postgresql 的本机 sql 查询
- javascript - 如何在 django 中动态更新 html 表
- flutter - ListView.builder 和使用地图功能有什么区别
- woocommerce - 我如何更改 woocommerce PRODUCT ATTRIBUTES 位置?
- php - 如何在 Inertia Vue js 中进行多次插入
- c - 如何获取我有指针指向的数组的位置?
- .net-core - 使用 Kafka + .Net Core + MassTransit 实现请求响应模式
- node.js - 节点 html-pdf 未在 PDF 中显示编码的图像 url
- ios - 使用协调器模式中的实例化函数在视图控制器之间传递数据