修改AI 使用服务器 1907/1 1907/head 1908/target/1
authorhcj <1224667075@qq.com>
Mon, 30 Jun 2025 10:28:52 +0000 (18:28 +0800)
committerhcj <1224667075@qq.com>
Mon, 30 Jun 2025 10:28:52 +0000 (18:28 +0800)
code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h

index 02fcf6a..2a2857f 100644 (file)
@@ -742,7 +742,7 @@ WebSocketClient *init_websocket_client(const char *url, const char *headers,uint
     struct in_addr in_addr_t={0};
     ip_addr_t  ip;
     struct cat1_ws_init_t ip_sem={0};
-int opt = 1;
+    int opt = 1;
 
     err_t ret=0;
 
@@ -879,9 +879,74 @@ void lwip_close_websocket_client(WebSocketClient *client) {
     
 }
 
+
+char *asr_recv_buf=NULL;//[1024]={0};
+WebSocketClient *asr_client;
+
+int32_t uapi_tts_paly_init(void);
+
+int32_t uapi_tts_paly_stop(void);
+
+uint32_t bk_websocket_tts_tick=0;
+
+uint8_t tts_reconnect=0;
+
+uint8_t asr_need_stop=0;
+
+
 char recv_buf[1024]={0};
+
 WebSocketClient *chat_client;
 
+
+WebSocketClient *tts_client;
+
+
+errcode_t chat_server_init(void);
+
+errcode_t tts_server_init(void);
+
+void tts_server_deinit(void);
+
+
+void uapi_UI_start_asr(void)
+{
+    asr_need_stop=0;
+
+    asr_server_init();
+
+    if(chat_client==NULL)
+    {
+        chat_server_init();
+    }
+    if(tts_client==NULL)
+    {
+        tts_server_init();
+    }
+  
+
+
+    if(bk_websocket_tts_tick!=0)
+    {
+        tts_server_deinit();
+        tts_reconnect=1;
+    }
+}
+
+
+void uapi_UI_stop_start_asr_timeout(void)
+{
+    asr_need_stop=1;
+}
+
+void uapi_UI_stop_asr(void)
+{
+    stop_AudioCaptureProcess_AI();
+}
+
+
+
+
 void send_ai_txt(uint8_t type,char *msg)
 {   
     cJSON* dataJSON = cJSON_CreateObject();
@@ -1034,22 +1099,23 @@ void bk_websocket_demo(void *data) {
     /* code */
         is_bk_websocket_chat=1;
 
-        char url_buf[124]={0};
-        if(chat_ws_url_init(url_buf))
-        {
-            printf("%s\r\n",url_buf);
-        }
-        else
-        {
-            is_bk_websocket_chat=0;
-        return;
-        }
+        // char url_buf[124]={0};
+        // if(chat_ws_url_init(url_buf))
+        // {
+        //     printf("%s\r\n",url_buf);
+        // }
+        // else
+        // {
+        //     is_bk_websocket_chat=0;
+        // return;
+        // }
         uint8_t client_count=3;
 
         while (client_count)
         {
             // http://118.145.158.207:22080ws://118.145.158.207:22080/chat/ws
-            chat_client = init_websocket_client(url_buf,NULL,1);
+            // ws://amp.raisound.com/chat/ws?dt=%s&platform=chinamobiledevice&bot_type=jiutian-lan
+            chat_client = init_websocket_client("ws://118.145.158.207:22080/chat/ws?&platform=chinamobiledevice&bot_type=jiutian-lan",NULL,0);
 
             if (chat_client== NULL) {
             client_count--;
@@ -1143,35 +1209,6 @@ errcode_t chat_server_init(void)
 
 // http://118.145.158.207:22080ws://amp.raisound.com/asr/ws
 
-char *asr_recv_buf=NULL;//[1024]={0};
-WebSocketClient *asr_client;
-
-int32_t uapi_tts_paly_init(void);
-
-int32_t uapi_tts_paly_stop(void);
-
-uint32_t bk_websocket_tts_tick=0;
-
-uint8_t tts_reconnect=0;
-
-void tts_server_deinit(void);
-
-
-void uapi_UI_start_asr(void)
-{
-    asr_server_init();
-
-    if(bk_websocket_tts_tick!=0)
-    {
-        tts_server_deinit();
-        tts_reconnect=1;
-    }
-}
-
-void uapi_UI_stop_asr(void)
-{
-    stop_AudioCaptureProcess_AI();
-}
 
 
 
@@ -1469,7 +1506,7 @@ void bk_websocket_asr(void *data) {
 
         uint8_t client_count=3;
 
-        while (client_count)
+        while (client_count && asr_need_stop==0)
         {
             if (g_test_server_index == 1)
             {
@@ -1486,7 +1523,7 @@ void bk_websocket_asr(void *data) {
             if (asr_client== NULL) {
                  printf("init_websocket_client fail %d\r\n",client_count);
                 client_count--;
-bk_sleep(1000);
+                bk_sleep(1000);
             continue ;
             }
              else
@@ -1494,8 +1531,13 @@ bk_sleep(1000);
                 break;
             }
         }
+
+        asr_need_stop=0;
+
         if (asr_client== NULL){
 
+            bool state = false;
+            SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool));
             is_bk_websocket_asr=0;
             return;
         }
@@ -1616,8 +1658,6 @@ bool tts_ws_url_init(char * put_buf)
 
 
 
-WebSocketClient *tts_client;
-
 
 void uapi_start_tts(void)
 {
index 4c2dcd9..15e3ad7 100644 (file)
@@ -16,6 +16,9 @@ void uapi_UI_stop_asr(void);
 
 void uapi_start_tts_single_txt(char *buf);
 
+void uapi_UI_stop_start_asr_timeout(void);
+
+
 ////////////////////////////////////////////////////////////////////////