问题描述
我在尝试使用 IBM Watson 时收到此错误。也许有人有同样的问题 - 甚至更好 - 一个解决方案?
Traceback (most recent call last): File "MY FILE.py",line 27,in service.recognize( File "C:\Users\...\lib\site-packages\ibm_watson\speech_to_text_v1.py",line 566,in recognize response = self.send(request) File "C:\Users\....\lib\site-packages\ibm_cloud_sdk_core\base_service.py",line 308,in send raise ApiException(response.status_code,http_response=response) ibm_cloud_sdk_core.api_exception.ApiException: Error: Internal Server Error Internal Server Error - Write The server encountered an internal error or misconfiguration and was unable to complete your request.Reference #4.a54a0760.1627114991.5298a594,Code: 503
这是我正在使用的代码
# Accepts only .mp3 Format of Audio # File import json from os.path import join,dirname from ibm_watson import SpeechToTextV1 from ibm_watson.websocket import RecognizeCallback,AudioSource from ibm_cloud_sdk_core.authenticators import IAMAuthenticator # Insert API Key in place of # YOUR UNIQUE API KEY - I replaced this text with my API KEY in actual code authenticator = IAMAuthenticator('YOUR UNIQUE API KEY') service = SpeechToTextV1(authenticator = authenticator) #Insert URL in place of API_URL - below is actual I am using service.set_service_url('https://api.us-east.speech-to-text.watson.cloud.ibm.com') # Insert local mp3 file path in # place of LOCAL FILE PATH - I am using my C drive and replaced actual file path ending with open(join(dirname('__file__'),r'C:/Users/LOCAL FILE PATH.mp3'),'rb') as audio_file: dic = json.loads( json.dumps( service.recognize( audio=audio_file,content_type='audio/flac',model='en-US_NarrowbandModel',continuous=True).get_result(),indent=2)) # Stores the transcribed text str = "" while bool(dic.get('results')): str = dic.get('results').pop().get('alternatives').pop().get('transcript')+str[:] print(str)
解决方法
IBM 工程师提供的解决方案有效; “您的代码正在使用我们美国东部数据中心的 URL,建议在 URL 中包含您的实例 ID。” 添加 URL .../instance/MY ID 问题解决!