python - Google Speech API RecognitionConfig 没有 "speechContexts"字段错误

标签 python google-cloud-speech

我正在使用最新的 Google-Cloud-Speech API (0.36.0)。我能够成功执行我的脚本,但是,当我添加peechContexts参数时,我不断收到“ValueError:协议(protocol)消息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.

最佳答案

问题是你是字段speechContexts,而根据the documentation for the RecognitionConfig class ,该字段的正确名称是 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
            )

您可以引用Python Reference for the Cloud Speech API以获得客户端库的完整文档和使用示例。

关于python - Google Speech API RecognitionConfig 没有 "speechContexts"字段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53721461/

相关文章:

python - 如何从串口读取数据? Python

ruby-on-rails - 在ReactJs中录制音频(FLAC或WAV),并使用ruby后端从Google使用Speech2Text

speech-recognition - 如何在python中使用google cloud speech api

python - 在谷歌云语音API中使用增强模型

android - 使用 Python/(GAE) 为 Android 应用推送通知的服务器端实现

python - python : Noob IndexError

python - petl - 如何用零替换空值

python - 将 Sqlite 数据导入 Google App Engine

python - 在docker compose yml文件中设置环境变量时出现文件未找到错误

reactjs - Google Cloud 与 React Native 的演讲