故事打断修改
authorhcj <1224667075@qq.com>
Fri, 21 Nov 2025 07:06:45 +0000 (15:06 +0800)
committerhcj <1224667075@qq.com>
Fri, 21 Nov 2025 07:06:45 +0000 (15:06 +0800)
code/sdk/zhihui/leiniao/imsl_ln/ln_api_websocket.c

index c5a303c..c314345 100644 (file)
@@ -1299,10 +1299,11 @@ int ln_ws_send_text(const char *text)
     return uapi_ws_send_text(text);
 }
 
-// int ln_ws_send_random_story_cache(const char *story_theme)
-// {
-
-// }
+int ln_ws_send_random_story_cache(const char *story_theme)
+{
+    memcpy(story_theme_cache,story_theme,strlen(story_theme));
+    return 0;
+}
 /* 发送随机故事请求 */
 int ln_ws_send_random_story_request(const char *story_theme)
 {
@@ -1317,23 +1318,23 @@ int ln_ws_send_random_story_request(const char *story_theme)
         return -1;
     }
     
-    if (g_ws_connected != WS_STATE_CONNECTED) {
+  
+    ln_ws_send_voice_chat_interrupt("故事请求开始");
+
+    if (g_ws_connected == WS_STATE_RECONNECTING) {
+    // 重连中,缓存音频数据
+        LN_WS_INFO("Connection reconnecting,ln_ws_send_random_story_request data (%s)\n", story_theme);
+        return ln_ws_send_random_story_cache(story_theme);
+    }
+    else if (g_ws_connected != WS_STATE_CONNECTED) {
         LN_WS_WARN("Cannot send random story request, connection state: %d\n", g_ws_connected);
         return -1;
     }
-    // ln_ws_send_voice_chat_interrupt("故事请求开始");
-
-    // if (g_ws_connected == WS_STATE_RECONNECTING) {
-    //     // 重连中,缓存音频数据
-    //     LN_WS_INFO("Connection reconnecting,ln_ws_send_random_story_request data (%s)\n", story_theme);
-    //     return ln_ws_audio_buffer_add(audio_data, audio_size, finished);
-    // } 
-
 
     
     // 生成聊天ID(使用当前对话ID)
     generate_chat_id(g_audio_chat_ctx.chat_id, sizeof(g_audio_chat_ctx.chat_id));
-    // g_audio_chat_ctx.finish_state = LN_CHAT_SENT_END_NO_REPLY;
+    g_audio_chat_ctx.finish_state = LN_CHAT_SENT_END_NO_REPLY;
 
     // 生成消息ID
     char message_id[128];
@@ -2639,7 +2640,11 @@ static void ln_ws_reconnect_success_callback(void)
     
     g_ws_connected = WS_STATE_CONNECTED;
 
-
+    if(strlen(story_theme_cache)>3)
+    {
+        ln_ws_send_random_story_request(story_theme_cache);
+        memset(story_theme_cache,0,sizeof(story_theme_cache));
+    }
     
     LN_WS_INFO("Reconnect success event triggered\n");
 }