添加4GAI的Ui处理逻辑待验证 1744/3 1744/head
authorluozheng <1732036298@qq.com>
Wed, 28 May 2025 02:42:03 +0000 (10:42 +0800)
committerluozheng <1732036298@qq.com>
Wed, 28 May 2025 02:42:03 +0000 (10:42 +0800)
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h [new file with mode: 0644]

index f45155f..5317eba 100644 (file)
@@ -118,6 +118,11 @@ namespace OHOS
         void SetIsLimitDisplayed(bool value);
         bool GetIsLimitDisplayed(void);
 
+        void SetAI_4G_state(bool state);
+        bool GetAI_4G_state(void);
+        void SetAI_BT_state(bool state);
+        bool GetAI_BT_state(void);
+
     private:
         AiVoiceModel();
         ~AiVoiceModel();
@@ -145,6 +150,9 @@ namespace OHOS
         int16_t curView{0};
         bool isClickable{false};
         bool isLimitDisplayed{false};//AI答案是否显示到极限了
+
+        bool AI_4G_state{false};             //4gAI状态
+        bool AI_BT_state{false};             //蓝牙AI状态
     };
 
 }
index 41216d6..69f4233 100644 (file)
@@ -28,6 +28,7 @@
 #include <sys/stat.h>
 #include "bleService.h"
 #include <custom_save_runtime.h>
+#include "cat1_ws.h"
 namespace OHOS
 {
     // 声明定时器变量
@@ -165,7 +166,15 @@ namespace OHOS
         if (it != selectAiModelToTextId.end())
         {
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[QuerySelectedAiModelIsConnect] SelectAiModel = %d", it->second.second);
-            inquire_AI_is_ready(it->second.second);
+            if(GetAI_4G_state() == true)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[QuerySelectedAiModelIsConnect] GetAI_4G_state = true");
+                uapi_start_asr();
+            }
+            else
+            {
+                inquire_AI_is_ready(it->second.second);
+            }
         }
     }
 
@@ -625,6 +634,9 @@ namespace OHOS
         int32_t argc = 1;
         uint8_t *argv = (uint8_t *)"stop";
         AudioCaptureSample(argc, (const char **)&argv);
+        if(GetAI_4G_state() == true){
+            uapi_stop_asr();
+        }
         uapi_save_runtime_log(RUNTIME_LOG_RECORD_STOP_AI);//TOOD*
         return;
     }
@@ -1070,6 +1082,23 @@ namespace OHOS
         return ConfigModel::GetInstance()->GetSelectAiModel();
     }
 
+    void AiVoiceModel::SetAI_4G_state(bool state)
+    {
+        AI_4G_state = state;
+    }
+    bool AiVoiceModel::GetAI_4G_state(void)
+    {
+        return AI_4G_state;
+    }
+    void AiVoiceModel::SetAI_BT_state(bool state)
+    {
+        AI_BT_state = state;
+    }
+    bool AiVoiceModel::GetAI_BT_state(void)
+    {
+        return AI_BT_state;
+    }
+
     /*获取已选择的ai模型的textid*/
     int AiVoiceModel::GetAiModelTextId()
     {
index 9a8bd33..9ba9c85 100644 (file)
@@ -25,6 +25,8 @@
 #include "bleService.h"
 #include "player/include/PlayersModel.h"
 
+#include "cat1_ws.h"
+
 namespace OHOS
 {
 #define BLE_CONNECT_INTERVAL_HIGH_AI 10
@@ -380,9 +382,14 @@ namespace OHOS
             bool appBluetoothConnectState = model->GetAPPBluetoothIsConnect();
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "netWork4GState = %d,appBluetoothConnectState = %d", netWork4GState, appBluetoothConnectState);
 
+            //暂时4g可以用
+            netWork4GState = true;
+            model->SetAI_4G_state(netWork4GState);
+
             if (netWork4GState) // 1.手表4G网络正常
             {
                 // 通过4G调用大模型
+                ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODE_CONNECTING); // LOADING
             }
             else if (appBluetoothConnectState) // 3.只有与APP蓝牙连接正常
             {
index 606b4e6..e892084 100644 (file)
@@ -919,9 +919,8 @@ char asr_recv_buf[1024]={0};
 WebSocketClient *asr_client;
 
 
-//
-
-void uapi_start_asr()
+//查询是否可以对话
+void uapi_start_asr(void)
 {
     char *jsonString = "{\"header\":{\"event\":\"StartTranscription\",\"trace_id\": \
      \"3fa6b9e6a30b407ea38ad7ae69e6c291\"},\"payload\":{\"format\":\"MP3\",\"sample_rate\":16000}}";
@@ -932,7 +931,8 @@ void uapi_start_asr()
     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"send_websocket_message succ erro\n");
 }
 
-void uapi_stop_asr()
+//停止对话
+void uapi_stop_asr(void)
 {
     char *jsonString ="{\"header\":{\"event\":\"StopTranscription\",\"trace_id\":\"3fa6b9e6a30b407ea38ad7ae69e6c291\"}}";
 
@@ -977,6 +977,7 @@ void record_test(void)
     fclose(fp);
 }
 #include "audio_capture_wrapper.h"
+#include <ui_service.h>
 
 // {"status":20000000,"msg":"success","task_id":"80228c9f62821ffe3f867e1a5042d887","event":"TranscriptionStarted","result":null}
 // {"status":20000000,
@@ -1030,7 +1031,10 @@ bool aer_result_analysis(char *buf)
     }
     if(strcmp(event_str,"TranscriptionStarted")==0)
     {
-        streamingRecordAndSend_AI(0);
+        //查询结果
+        // streamingRecordAndSend_AI(0);
+        bool state = true;
+        SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool));
     }
     cJSON_Delete(root);
 
diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h
new file mode 100644 (file)
index 0000000..9c16aca
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef __CAT1_WS_H__
+#define __CAT1_WS_H__
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+void uapi_start_asr(void);
+
+void uapi_stop_asr(void);
+
+
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+#endif
\ No newline at end of file