科大讯飞 Websockets API 的问题?-灵析社区

Frank的私人司机

尝试调用科大讯飞的实时语音流式转写接口:[https://www.xfyun.cn/doc/asr/voicedictation/API.html](https://link.segmentfault.com/?enc=PLnKZAeT4Bw2UoSXMEjUFg%3D%3D.lDWn5QPVYf%2BsRedc0uyHSOBkB0%2FgTgiepBLC7YdPYYHQPT5TdPPCHVa7aUPvO60cIOQ798Beu30x8ysGs1ihkQ%3D%3D) xunfei = XunFei(APPID='...', APISecret='...', AudioFile=r'test.pcm') url = xunfei.create_url() async def hello(): async with websockets.connect(url) as websocket: cc = xunfei.read_audio() print("数据:" + json.dumps(cc)) await websocket.send(str(json.dumps(cc))) while True: message = await websocket.recv() print(f"收到消息: {json.loads(message)}") if __name__ == "__main__": asyncio.run(hello()) 但老是报错 Traceback (most recent call last): File "/var/www/QBA/config/voice.py", line 135, in asyncio.run(hello()) File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/var/www/QBA/config/voice.py", line 131, in hello message = await websocket.recv() ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 568, in recv await self.ensure_open() File "/usr/local/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 944, in ensure_open raise self.connection_closed_exc() websockets.exceptions.ConnectionClosedOK: received 1000 (OK) Websocket closed!,sid=iat000dc91f@dx18ad01d4a38a11f802!reason=server read msg timeout; then sent 1000 (OK) Websocket closed!,sid=iat000dc91f@dx18ad01d4a38a11f802!reason=server read msg timeout 不懂这是为什么,但是我发个普通的消息就会立马得到反馈

阅读量:374

点赞量:13

问AI
是我自己的问题,在发送数据的时候必须有 3 种数据包:012 分别代表起始帧、中间、结束、否则就会没响应直接结束