@
pursuer 我已经修改了,发现 future 一直没变化。
```
def callback_speak_by_audio(code, status, frame_id, client_id):
client_id = client_id.decode('utf-8') # 解码客户端 ID
status = json.loads(status.decode('utf-8')) # 假设 status 是 UTF-8 编码的字符串
print(f"callback_speak_by_audio=====run, {client_id in futures_speak_by_audio_stream}")
if status["data"]["FrameId"] == -1:
if code == MSDKStatus.MSDK_SUCCESS_SPEAK_BY_AUDIO_FINISH.value:
print(f"语音说话: {code}, 客户端 ID: {client_id}")
asyncio.run_coroutine_threadsafe(set_futures_status_async(client_id, futures_speak_by_audio_stream, {"code": 204, "status": status, "name": "speak_by_audio", "success": True, "client_id": client_id}), websocketAll[client_id]['main_loop'])
async def set_futures_status_async(client_id, futures_obj, data):
if client_id in futures_obj:
future = futures_obj.pop(client_id)
if not future.done():
future.set_result(data)
```
外部调用形式为:
```
if connected["audio_future"] is None:
feature = asyncio.Future()
connected["audio_future"] = feature
print("Creating sendAudioEndData task")
asyncio.create_task(sendAudioEndData(connected, feature))
async def sendAudioEndData(connected, feature):
print("发送音频结束数据")
try:
result = await feature # 等待 feature 完成
print(f"发送音频结束数据: {result}")
await connected['websocket'].send(json.dumps(result))
except Exception as e:
print(f"发送数据时发生错误: {e}")
finally:
connected["audio_future"] = None # 确保音频 future 被正确重置
```
麻烦大佬再指点一下,是哪里不对呢?从日志结果看,“语音说话:”的日志已经执行。 但是后续的 sendAudioEndData 的 print(f"发送音频结束数据: {result}")没有执行。