Google Speech API RecognitionConfig没有“speechContexts”字段

2024-10-03 17:22:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用最新的Google云语音API(0.36.0)。我能够成功地执行我的脚本,但是,当我添加speechContexts参数时,我一直得到“ValueError:Protocol message RecognitionConfig没有”speechContexts“字段。”错误。在

我遵循了Google文档页面上的例子,但是到目前为止我还没有取得任何进展。在

源代码:

config = types.RecognitionConfig(
            encoding = enums.RecognitionConfig.AudioEncoding.LINEAR16,
            sample_rate_hertz = 22050,
            language_code = 'en-US',
            speechContexts = [{'phrases':['installer']}]
            )

输出

^{pr2}$

Tags: 文档脚本apimessage参数源代码错误google
1条回答
网友
1楼 · 发布于 2024-10-03 17:22:28

问题是您是字段speechContexts,而根据the documentation for the ^{} 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,以获得客户机库的完整文档和使用示例。在

相关问题 更多 >