【发布时间】:2021-06-16 17:31:04
【问题描述】:
我正在尝试将音频(mp3、m4a 或 flac)导入此代码,以便访问 Watson API 并获取脚本。 我尝试过使用不同的音频文件,从视频中提取或直接由 Windows Recorder 录制。它们都具有接近 1 到 12MB 的不同大小。 但总是在下面返回这个错误。我没有在其他网站上找到类似问题的答案。
pip install ibm_watson
apikey = 'xxxx'
url = 'yyyy'
from ibm_watson import SpeechToTextV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
import subprocess
import os
authenticator = IAMAuthenticator(apikey)
stt = SpeechToTextV1(authenticator = authenticator)
stt.set_service_url(url)
f= "file_path"
res = stt.recognize(audio=f, content_type='audio/m4a', model='en-US_NarrowbandModel', continuous=True, inactivity_timeout=360).get_result()
ApiException Traceback (most recent call last)
<ipython-input-24-cfbd4e46f426> in <module>()
3 f= "file_path"
4 res = stt.recognize(audio=f, content_type='audio/m4a', model='en-US_NarrowbandModel', continuous=True,
----> 5 inactivity_timeout=360).get_result()
1 frames
/usr/local/lib/python3.7/dist-packages/ibm_cloud_sdk_core/base_service.py in send(self, request, **kwargs)
300 status_code=response.status_code)
301
--> 302 raise ApiException(response.status_code, http_response=response)
303 except requests.exceptions.SSLError:
304 logging.exception(self.ERROR_MSG_DISABLE_SSL)
ApiException: Error: Stream was 9 bytes but needs to be at least 100 bytes., Code: 400 , X-global-transaction-id: 927c7d31-c030-4d71-8998-aa544b1ae111
【问题讨论】:
-
错误显示
Stream was 9 bytes和len("file_path")给出9。可能它需要audio=open(f, 'rb').read()而不是audio=f
标签: python ibm-watson speech-to-text