From 84e42105d3d13d1a55cbfb06b85a4bf02c963603 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Sun, 2 Nov 2025 19:49:14 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E5=9B=9E=E5=A4=8D=E7=A1=AE?= =?utf8?q?=E8=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../zhihui/leiniao/imsl_ln/ln_api_websocket.c | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c index 41a7673b6..82b71a9fb 100644 --- a/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c +++ b/code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c @@ -144,6 +144,7 @@ typedef struct { char chat_id[64]; // 聊天ID uint32_t message_counter; // 消息计数器 bool is_active; // 是否活跃 + bool is_reply; // 是否回复 } audio_chat_context_t; // 全局音频聊天上下文 @@ -532,6 +533,7 @@ int ln_ws_send_audio_data(const uint8_t *audio_data, uint32_t audio_size, bool f generate_chat_id(g_audio_chat_ctx.chat_id, sizeof(g_audio_chat_ctx.chat_id)); g_audio_chat_ctx.message_counter = 0; g_audio_chat_ctx.is_active = true; + g_audio_chat_ctx.is_reply = false; // 重置对话ID匹配标志 reset_chat_id_match(); LN_WS_DEBUG("New chat started: %s\n", g_audio_chat_ctx.chat_id); @@ -682,6 +684,7 @@ int ln_ws_start_audio_chat(ln_audio_chat_command_t command_type) generate_chat_id(g_audio_chat_ctx.chat_id, sizeof(g_audio_chat_ctx.chat_id)); g_audio_chat_ctx.message_counter = 0; g_audio_chat_ctx.is_active = true; + g_audio_chat_ctx.is_reply = false; // 清空音频时长数组,避免不同对话间的数据混淆 clear_audio_duration_buffer(); @@ -793,6 +796,7 @@ static void AIVoiceDataCallback_ln(const uint8_t* data, uint32_t size, void* use // 发送结束消息 ln_ws_send_audio_data(data, size, true); + // AI_SendAudioDataToQueue(data, size); // AI_SendAudioDataToQueue(data, size); // 重置聊天上下文和结束标志 g_audio_chat_ctx.is_active = false; @@ -818,6 +822,7 @@ static void AIVoiceDataCallback_ln(const uint8_t* data, uint32_t size, void* use // 使用新的音频发送接口 ln_ws_send_audio_data(data, size, false); + // AI_SendAudioDataToQueue(data, size); // AI_SendAudioDataToQueue(data, size); } } @@ -1423,7 +1428,7 @@ int ln_ws_send_voice_chat_interrupt(const char *reason) if (ret == 0) { LN_WS_DEBUG("VoiceChatInterrupt sent successfully\n"); - if (need_reconnect) { + if (need_reconnect || g_audio_chat_ctx.is_reply==false) { // 如果检测到频繁数据接收,直接重连 LN_WS_INFO("Triggering reconnection due to frequent binary data reception\n"); if (ln_ws_reconnect() != 0) { @@ -1702,6 +1707,11 @@ static int ln_ws_parse_data_message(const char *json_str, ws_data_msg_t *data_ms if (ln_ws_check_chat_id_match(data_msg->chat_id, root) != 0) { return -1; // 不匹配,已清理JSON } + // 对话ID匹配成功,标记为已回复(仅当对话活跃时) + { + g_audio_chat_ctx.is_reply = true; + LN_WS_DEBUG("VoiceChatResponse matched current chat, set is_reply=true\n"); + } } // 解析data.data字段 @@ -1755,6 +1765,11 @@ static int ln_ws_parse_data_message(const char *json_str, ws_data_msg_t *data_ms if (ln_ws_check_chat_id_match(data_msg->chat_id, root) != 0) { return -1; // 不匹配,已清理JSON } + // 对话ID匹配成功,标记为已回复(仅当对话活跃时) + { + g_audio_chat_ctx.is_reply = true; + LN_WS_DEBUG("ChooseStoryResponse matched current chat, set is_reply=true\n"); + } } // 解析data.data字段 @@ -1807,6 +1822,11 @@ static int ln_ws_parse_data_message(const char *json_str, ws_data_msg_t *data_ms if (ln_ws_check_chat_id_match(data_msg->chat_id, root) != 0) { return -1; // 不匹配,已清理JSON } + // 对话ID匹配成功,标记为已回复(仅当对话活跃时) + { + g_audio_chat_ctx.is_reply = true; + LN_WS_DEBUG("RandomStoryResponse matched current chat, set is_reply=true\n"); + } } // 解析data.data字段 @@ -2696,6 +2716,7 @@ static int ln_ws_send_audio_data_direct(const uint8_t *audio_data, uint32_t audi generate_chat_id(g_audio_chat_ctx.chat_id, sizeof(g_audio_chat_ctx.chat_id)); g_audio_chat_ctx.message_counter = 0; g_audio_chat_ctx.is_active = true; + g_audio_chat_ctx.is_reply = false; // 重置对话ID匹配标志 reset_chat_id_match(); LN_WS_DEBUG("New chat started: %s\n", g_audio_chat_ctx.chat_id); -- 2.17.1