【问题标题】:SpeechContext has no "boost" fieldSpeechContext 没有“提升”字段
【发布时间】:2019-07-01 15:37:40
【问题描述】:

我正在使用 google cloud api 进行语音转文本,我想添加一些上下文短语。根据谷歌文档,语音上下文也有一个我无法设置的提升字段。

我把导入的speech_v1p1beta1改成了speech_v1,编码如下:

    config = speech.RecognitionConfig(
    encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,

    sample_rate_hertz=8000,
    language_code=first_lang,
    #alternative_language_codes=[second_lang],
    audio_channel_count=1,
    enable_separate_recognition_per_channel=False,
    #metadata=metadata,
    max_alternatives=5,
    # enable_word_confidence=True,

    speech_contexts=[{'phrases':['sfs'],'boost':15}]


    # speech_contexts=[speech.SpeechContext(
    #         phrases=['life insurance'],boost=15            
    #         )
    #         ]
    )

我收到以下错误:

  File "convert-wav-beta.py", line 165, in <module>
    transcript , confidence = google_transcribe(audio_file_name)
  File "convert-wav-beta.py", line 106, in google_transcribe
    speech_contexts=[{'phrases':['sfs'],'boost':15}]
  File "/env/lib/python3.5/site-packages/google/protobuf/internal/python_message.py", line 528, in init
    copy.add(**val)
  File "/env/lib/python3.5/site-packages/google/protobuf/internal/containers.py", line 376, in add
    new_element = self._message_descriptor._concrete_class(**kwargs)
  File "/env/lib/python3.5/site-packages/google/protobuf/internal/python_message.py", line 509, in init
    field = _GetFieldByName(message_descriptor, field_name)
  File "/env/lib/python3.5/site-packages/google/protobuf/internal/python_message.py", line 573, in _GetFieldByName
    (message_descriptor.name, field_name))
ValueError: Protocol message SpeechContext has no "boost" field.```

【问题讨论】:

  • 我的代码中的初始化部分 client = speech.SpeechClient(),错过了“client =”,我不知道如何得到同样的错误。

标签: google-cloud-platform speech-to-text google-speech-api


【解决方案1】:

我通过更新系统中的 beta 库解决了这个问题。我是通过谷歌从 github 代码中复制代码来做到这一点的。

【讨论】:

【解决方案2】:

您似乎正在使用包“speech”的 RecognitionConfig,而不是“speech_v1p1beta1”。如果使用 beta 功能,还应该从 Speech_v1p1beta1 包中导入类型和枚举。您的导入语句应如下所示:

from google.cloud import speech_v1p1beta1
from google.cloud.speech_v1p1beta1 import enums
from google.cloud.speech_v1p1beta1 import types

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-05
    • 2013-07-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多