我正在尝试将音频(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=f
编辑:
{a1}的文档显示了使用
所以这意味着你可能需要
没有
.read()
文档中的完整示例:
您必须单击链接recognize()并向下滚动才能在文档中看到它
相关问题 更多 >
编程相关推荐