【发布时间】: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