IBMWatsonSpeechtoText在Python中使用模型参数时给出404



我正在用Python测试IBM Watson Speech to Text的使用。我能够成功地测试用英语转录音频,但当我输入模型参数来更改我的语言的语言模型时,出现了404未找到的错误。我已经看了几次IBM页面,其中解释了模型参数的使用,但我不明白缺少了什么。有人能帮忙吗?

我的代码:

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_corebase_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,
content_type='audio/mp3',
word_alternatives_threshold=0.9,
model='fr-FR_BroadbandModel'
).get_result()
print(json.dumps(speech_recognition_results, indent=2))

相关内容

  • 没有找到相关文章

最新更新