如何解决使用模型参数时,Python中的IBM Watson Speech to Text提供404
我正在测试将IBM Watson Speech to Text与Python结合使用。我能够成功测试英语的音频转录,但是当我输入模型参数来更改我的语言的语言模型时,会出现404 not found错误。我已经看过IBM page多次,解释了model参数的用法,但我不明白缺少了什么。有人可以帮忙吗?
我的代码:
from ibm_watson import SpeechToTextV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
api = IAMAuthenticator("my_credential")
speech_2_text = SpeechToTextV1(authenticator=api)
speech_2_text.set_service_url("https://api.us-south.speech-to-text.watson.cloud.ibm.com/instances/20a185d6-6953-4334-9cea-e9f5ebc2267d?model=fr-FR_broadbandModel")
with open("test.mp3","rb") as audio_file:
result = speech_2_text.recognize(
audio=audio_file,content_type="audio/mp3"
).get_result()
错误消息:
ibm_cloud_sdk_core\base_service.py",line 224,in send raise ApiException(ibm_cloud_sdk_core.api_exception.ApiException: Error: Not Found,Code: 404
解决方法
模型应作为recognize
方法的一部分传递
speech_recognition_results = speech_to_text.recognize(
audio=audio_file,content_type='audio/mp3',word_alternatives_threshold=0.9,model='fr-FR_BroadbandModel'
).get_result()
粘贴对我有用的完整代码供您参考
import json
from os.path import join,dirname
from ibm_watson import SpeechToTextV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('<API_KEY>')
speech_to_text = SpeechToTextV1(
authenticator=authenticator
)
speech_to_text.set_service_url('<URL>')
with open(join(dirname(__file__),'./.','audio-file2.mp3'),'rb') as audio_file:
speech_recognition_results = speech_to_text.recognize(
audio=audio_file,model='fr-FR_BroadbandModel'
).get_result()
print(json.dumps(speech_recognition_results,indent=2))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。