Python 中的 IBM Watson Speech to Text 在使用模型参数时给出 404
IBM Watson Speech to Text in Python gives 404 when using model parameter
我正在使用 Python 测试 IBM Watson Speech to Text 的使用。我能够成功地测试用英语转录音频,但是当我输入模型参数以更改我的语言的语言模型时,会出现 404 未找到错误。我已经多次查看 IBM page 解释模型参数的使用,但我不明白缺少什么。有人可以帮忙吗?
我的代码:
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,
content_type='audio/mp3',
word_alternatives_threshold=0.9,
model='fr-FR_BroadbandModel'
).get_result()
print(json.dumps(speech_recognition_results, indent=2))
我正在使用 Python 测试 IBM Watson Speech to Text 的使用。我能够成功地测试用英语转录音频,但是当我输入模型参数以更改我的语言的语言模型时,会出现 404 未找到错误。我已经多次查看 IBM page 解释模型参数的使用,但我不明白缺少什么。有人可以帮忙吗?
我的代码:
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,
content_type='audio/mp3',
word_alternatives_threshold=0.9,
model='fr-FR_BroadbandModel'
).get_result()
print(json.dumps(speech_recognition_results, indent=2))