char chat_id[64]; // 聊天ID
uint32_t message_counter; // 消息计数器
bool is_active; // 是否活跃
+ bool is_reply; // 是否回复
} audio_chat_context_t;
// 全局音频聊天上下文
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);
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();
// 发送结束消息
ln_ws_send_audio_data(data, size, true);
+ // AI_SendAudioDataToQueue(data, size);
// AI_SendAudioDataToQueue(data, size);
// 重置聊天上下文和结束标志
g_audio_chat_ctx.is_active = false;
// 使用新的音频发送接口
ln_ws_send_audio_data(data, size, false);
+ // AI_SendAudioDataToQueue(data, size);
// AI_SendAudioDataToQueue(data, size);
}
}
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) {
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字段
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字段
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字段
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);