4GAI修改,优化连不上问题
authorluozheng <1732036298@qq.com>
Fri, 22 Aug 2025 11:08:35 +0000 (19:08 +0800)
committerluozheng <1732036298@qq.com>
Fri, 22 Aug 2025 11:08:35 +0000 (19:08 +0800)
关闭uapi_get_buildversion函数中printf(str);打印

code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_ai_server.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h
code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c
code/sdk/drivers/peripheral/utils/custom_utils.c

index 077aa16..360b114 100644 (file)
@@ -683,13 +683,13 @@ namespace OHOS
         str.swap(result);
     }
 
-    static int fouce_count = 0;         //
+    static int fouce_count = 0; //
     void AiVoiceModel::ProcessTextByPunctuation()
     {
         const std::string punctuation = ",。!?;:))“”、\"\""; // 要替换的中文标点
-        const char replacement = ',';                         // 替换为英文逗号
-        const size_t MAX_SEGMENT_LENGTH = 120;                // 最大分段长度
-        const size_t MIN_SEGMENT_LENGTH = 1;                  // 最小发送长度(可调整)
+        const char replacement = ',';                              // 替换为英文逗号
+        const size_t MAX_SEGMENT_LENGTH = 120;                     // 最大分段长度
+        const size_t MIN_SEGMENT_LENGTH = 1;                       // 最小发送长度(可调整)
 
         if (accumulatedText.empty())
             return;
@@ -751,7 +751,7 @@ namespace OHOS
                     // 发送失败,等待下次发送
                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败,等待下次发送");
                     fouce_count++;
-                    if(fouce_count >= 3)
+                    if (fouce_count >= 3)
                     {
                         uapi_start_tts();
                         fouce_count = 0;
@@ -808,7 +808,7 @@ namespace OHOS
             // 发送失败,等待下次发送
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败,等待下次发送");
             fouce_count++;
-            if(fouce_count >= 3)
+            if (fouce_count >= 3)
             {
                 uapi_start_tts();
                 fouce_count = 0;
@@ -997,7 +997,7 @@ namespace OHOS
                 auto it = selectAiModelToTextId.find(GetSelectAiModel());
                 if (it != selectAiModelToTextId.end())
                 {
-                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filesize = %ld,SelectAiModel = %d", size, it->second.second);
+                    // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filesize = %ld,SelectAiModel = %d", size, it->second.second);
                     if (get_ble_interval() >= BLE_CONNECT_INTERVAL_SLOW)
                     {
                         uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_HIGH);
@@ -1006,7 +1006,7 @@ namespace OHOS
                 }
                 else
                 {
-                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetSelectAiModel fail!!", size, it->second.second);
+                    // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetSelectAiModel fail!!", size, it->second.second);
                 }
 
                 ClearQuestionAndAiAnswerStr(); // 清空上次用户问题和Ai回答字符串
@@ -1268,7 +1268,7 @@ namespace OHOS
         if (LISTENING_TIMEOUT <= 0)
         {
             // AiVoiceModel::GetInstance().StopListenAndRecordingUserQuestion(); // 停止聆听用户问题
-            AiVoiceModel::GetInstance().stop_listening_timer();               // 停止聆听定时器
+            AiVoiceModel::GetInstance().stop_listening_timer(); // 停止聆听定时器
             AiVoicePresenter *p_AiVoicePresenter = AiVoicePresenter::GetInstance();
             if (AiVoicePresenter::GetInstance() && AivoiceListeningView::GetInstance())
             {
@@ -1363,7 +1363,7 @@ namespace OHOS
                 }
             }
         }
-#if 0
+#if 1
         else
         {
             if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G)
@@ -1371,21 +1371,10 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetSelect4gorbt() == AI_SELECT_4G");
                 if (AiVoiceModel::GetInstance().GetInit_4gai_task())
                 {
-                    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "111:%d",AiVoiceModel::GetInstance().get_is_delay_start_asr());
-                    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "222:%d",get_ai_asr_service_init_flag());
-                    if (!AiVoiceModel::GetInstance().get_is_delay_start_asr())
+                    if (get_asr_is_ready_start())
                     {
-                        if (get_ai_asr_service_init_flag() == 0)
-                        {
-                            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "发送查询");
-                            uapi_UI_start_asr(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
-                            AI_IS_READY_TIMEOUT = 5;
-                            AiVoiceModel::GetInstance().set_is_delay_start_asr(true);
-                        }
-                        else
-                        {
-                            usleep(10000);
-                        }
+                        bool state = true;
+                        SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool));
                     }
                 }
             }
@@ -1482,7 +1471,7 @@ namespace OHOS
         {
             if (view_ != nullptr && p_AiVoicePresenter != nullptr)
             {
-                if(uapi_get_server_state_is_end())
+                if (uapi_get_server_state_is_end())
                 {
                     init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
                     return;
@@ -1595,7 +1584,7 @@ namespace OHOS
             AiVoiceModel::GetInstance().ProcessTextByPunctuation();
         }
 
-        #if 0
+#if 0
         // 当前回调中get_bk_websocket_tts_tick()是否为0
         bool current_tick_zero = (get_bk_websocket_tts_tick() == 0);
 
@@ -1640,7 +1629,7 @@ namespace OHOS
                 }
             }
         }
-        #endif
+#endif
         return;
     }
 
@@ -1784,7 +1773,6 @@ namespace OHOS
         }
     }
 
-
     static osTimerId_t g_uapi_stop_tts_Handle = nullptr;
     static void AI4G_UAPI_STOP_TTS_CallbackProc(int data)
     {
@@ -1830,7 +1818,7 @@ namespace OHOS
             return;
         }
     }
-    
+
     void AiVoiceModel::stop_uapi_stop_tts_timer(void)
     {
         // 检查定时器是否存在
index f4b8873..95ea087 100644 (file)
@@ -878,6 +878,12 @@ uint32_t get_bk_websocket_tts_tick(void)
 {
     return bk_websocket_tts_tick;
 }
+
+static uint8_t asr_is_ready_start = 0;
+uint8_t get_asr_is_ready_start(void)
+{
+    return asr_is_ready_start;
+}
 void asr_on_ws_packet_callback(uint8_t* data, size_t datalen, WebSocketMessageType type)
 {
     if(asr_client !=NULL && asr_client->msg_queue !=NULL)
@@ -1172,6 +1178,7 @@ void bk_websocket_demo(void *data) {
             chat_reconnect = 0;
               retry_count = 0;
             WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Reconnecting chat client...");
+            msleep(100);
             goto char_reconnet;
         }
 
@@ -1265,6 +1272,7 @@ errcode_t chat_server_init(void)
 
 
 
+
 //查询是否可以对话
 void uapi_start_asr(void)
 {
@@ -1274,7 +1282,12 @@ void uapi_start_asr(void)
       \"3fa6b9e6a30b407ea38ad7ae69e6c291\"},\"payload\":{\"format\":\"MP3\",\"sample_rate\":16000}}";
     
     if (send_websocket_message(asr_client,( uint8_t  *)jsonString,strlen(jsonString),WS_TEXT)==0)
-    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"send_websocket_message succ 0\n");
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"send_websocket_message succ 0\n");
+        AI_LOCK();
+        asr_is_ready_start = 0;
+        AI_UNLOCK();
+    }
     else
     {
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send_websocket_message  erro\n");
@@ -1437,8 +1450,11 @@ bool aer_result_analysis(char *buf)
         //     //上传文件
         // }
 
-        bool state = true;
-        SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool));
+        // bool state = true;
+        // SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool));
+        AI_LOCK();
+        asr_is_ready_start = 1;
+        AI_UNLOCK();    
 
     }
      if(strcmp(event_str,"TranscriptionCompleted")==0) //asr 结束
@@ -1718,10 +1734,7 @@ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "等待ASR WebSocket握手完成... (%d m
             
             msleep(10); // 避免过度占用CPU
         }
-        if (disconnect_server == 0) {
-            WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Reconnecting ASR client...");
-            goto ASR_SATRT;
-        }
+
         AI_LOCK();
         set_ai_asr_service_init_flag(0);
         AI_UNLOCK();
@@ -1734,8 +1747,15 @@ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "等待ASR WebSocket握手完成... (%d m
         asr_client = NULL;
         ws_queue_cleanup(&asr_msg_queue);
 
+
+        if (disconnect_server == 0) {
+            WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Reconnecting ASR client...");
+            msleep(100);
+            goto ASR_SATRT;
+        }
+
         asr_client_ping = 0;
-        msleep(1000);
+        // msleep(1000);
     }
     
 asr_cleanup_and_exit:
@@ -2348,6 +2368,7 @@ TTS_SATRT:
             retry_count = 0;
             WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Reconnecting TTS client...");
             tts_reconnect = 0;
+             msleep(100);
             goto TTS_SATRT;
         }
     }
index c70ef3e..cf2cb80 100644 (file)
@@ -60,6 +60,7 @@ void set_ai_chat_service_init_flag(uint8_t flag);
 uint8_t get_ai_tts_server_init_flag(void);
 void set_ai_tts_server_init_flag(uint8_t flag);
 uint32_t get_bk_websocket_tts_tick(void);
+uint8_t get_asr_is_ready_start(void);
 
 void uapi_start_asr_task(void);
 
index bc90505..f3ab197 100644 (file)
@@ -201,7 +201,7 @@ static void custom_fileoperate_service_check_task(void const *arg)
     }
 }
 #define CUSTOM_FILE_OPERATE_APP_BOARD_MSG_COUNT 10
-#define CUSTOM_FILE_OPERATE_APP_BOARD_TASK_SIZE 0x1000
+#define CUSTOM_FILE_OPERATE_APP_BOARD_TASK_SIZE 0x2000
 #define CUSTOM_FILE_OPERATE_BOARD_TASK_PRIO 7
 void create_custom_fileoperate_queue(void)
 {
index 9a798ca..dd891de 100644 (file)
@@ -1838,7 +1838,7 @@ errcode_t uapi_get_buildversion(uint8_t *para, uint32_t para_len)
                     get_version_string(), BUILD_TIME);
 
 #endif
-    printf(str);
+    // printf(str);
     memset(para,0,para_len);
     memcpy_s(para,para_len,str,strlen(str));