python - Google Speech API RecognitionConfig 没有“speechContexts”字段错误
问题描述
我正在使用最新的 Google-Cloud-Speech API (0.36.0)。我能够成功执行我的脚本,但是,当我添加 SpeechContexts 参数时,我不断收到“ValueError:协议消息 RecognitionConfig 没有“speechContexts”字段。” 错误。
我已经按照 Google 文档页面上的示例进行了操作,但到目前为止我还没有取得任何进展。
源代码:
config = types.RecognitionConfig(
encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz = 22050,
language_code = 'en-US',
speechContexts = [{'phrases':['installer']}]
)
输出
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
ValueError: Protocol message RecognitionConfig has no "speechContexts" field.
解决方案
问题是您是 field speechContexts
,而根据class的文档,RecognitionConfig
该字段的正确名称是speech_contexts
。
您只需要将上面的代码更改为以下代码:
config = types.RecognitionConfig(
encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz = 22050,
language_code = 'en-US',
speech_contexts = [{'phrases':['installer']}] #Note the change in the field
)
您可以参考Cloud Speech API 的 Python 参考,以获得客户端库的完整文档和使用示例。
推荐阅读
- streaming - 以编程方式将视频从内置 wifi ip 摄像头流式传输到 android 设备
- mongodb - 如何为 mongodb 编写相关的 $lookup 查询?
- google-sheets - 谷歌数据工作室案例当两组标准
- c++ - 如何将迭代器指向向量中大于或等于目标数的元素
- javascript - 如何使用 JavaScript 更改滑块表单旁边的文本
- amazon-web-services - 如何通过消息处理一一实现 Amazon SQS (fifo)-lambda
- image - 动画启动画面中图像资源的大小不变
- bash - bash 中的基本计算
- python - 检索元 BS4 元素的内容
- smtp - 使用 office365 AUTH 修复