Google Speech API RecognitionConfig没有“ speechContexts”字段错误

Jie Jenn

我正在使用最新的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,而根据该类的文档,则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 APIPython参考,以获取客户端库的完整文档和使用示例。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章