同步272 Ai代码最新代码
authorluozheng <1732036298@qq.com>
Fri, 17 Oct 2025 07:01:11 +0000 (15:01 +0800)
committerluozheng <1732036298@qq.com>
Fri, 17 Oct 2025 07:01:11 +0000 (15:01 +0800)
code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceConnectingView.h
code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceModel.h
code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceModelC.h
code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/Aivoice4gServiceConView.h
code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceConnectingView.cpp
code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceModel.cpp
code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoicePresenter.cpp
code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceView.cpp
code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/Aivoice4gServiceConView.cpp

index 2042f7f..d044ac0 100644 (file)
@@ -63,6 +63,7 @@ namespace OHOS
         static AiVoiceConnectingView *GetInstance(void);
         UIScrollView *CreateAiVoiceConnectingView(void);
         UIScrollView *CreateAiVoiceConnectingView(uint8_t);
+        void StartOrStopAiVoiceConnectingImageAnimatorView(bool val);
 
     private:
         UIImageAnimatorView *connectingImageAnimatorInit(ImageAnimatorConfig &imageanimatorconfig);
index 529c518..6f619a1 100644 (file)
 
 #define AI_VOICE_ENABLE 0
 
+// 常量定义
+#define MAX_CHAT_CONTENT_COUNT 2
+#define DEFAULT_TIMEOUT_5S 5    //5秒
+#define DEFAULT_TIMEOUT_10S 10  //10秒
+#define DEFAULT_TIMEOUT_30S 30  //30秒
+#define DEFAULT_TIMEOUT_60S 60  //60秒
+
 // 设置当前使用的音频类型,0 表示 PCM,1 表示 SBC,2 表示 MSBC
 #define CURRENT_AIAUDIO_TYPE AIAUDIO_TYPE_SBC
 
@@ -150,8 +157,6 @@ namespace OHOS
         bool GetInit_4gai_task(void);
         void SetSelect4gorbt(int state);
         int GetSelect4gorbt(void);
-        
-        void cancel_tts_play(void);
 
         void ProcessTextByPunctuation();
         std::string GetAccumulatedText(void);
@@ -183,7 +188,7 @@ namespace OHOS
         std::string aiAnswerStr;                                             // AI回答的问题
         std::string accumulatedText;                                         // tts播放文本
         uint8_t ChatContentListCount{0};                                     // 列表数量
-        static const uint16_t MaxChatContentListCount = 2;                   // 对话列表最大数量
+        static const uint16_t MaxChatContentListCount = MAX_CHAT_CONTENT_COUNT; // 对话列表最大数量
         ChatContentItem chatTtems[MaxChatContentListCount] = {0, "", false}; // 对话项数组
         bool entryTextViewState{false};                                      // 进入返回结果界面的标志
         std::map<int, std::pair<int, int>> selectAiModelToTextId;            // pair的参数类型<模型的textid,查询模型是否可用id>
index fcaeee7..c5ea624 100644 (file)
@@ -10,9 +10,8 @@ extern "C"
 #include <stdint.h>
 
     uint8_t getselect4gorbtai(void);
-    uint8_t get_clear_queue_stream(void);
-    void set_clear_queue_stream(uint8_t);
     void ble_AI_init(void);
+    void net4g_AI_init(void);
 
 #ifdef __cplusplus
 #if __cplusplus
index 495e68a..1e451de 100644 (file)
@@ -14,6 +14,7 @@ namespace OHOS
         ~AiVoice4gServiceConView();
         static AiVoice4gServiceConView *GetInstance(void);
         UIScrollView *CreateAiVoice4gServiceConView(void);
+        void StartOrStopAiVoice4gServiceConImageAnimatorView(bool val);
 
     private:
         void ClearAll(void);
index 4f253a9..45f1401 100644 (file)
@@ -201,7 +201,7 @@ namespace OHOS
         animatorView->SetSizeFixed(true);
         // animatorView->SetAutoEnable(false);
         // animatorView->SetResizeMode(UIImageAnimatorView::FILL);
-        animatorView->Start();
+        // animatorView->Start();
 
         return animatorView;
     }
@@ -310,11 +310,22 @@ namespace OHOS
         connectingAnimatorView->SetRepeat(true);
         connectingAnimatorView->SetAutoEnable(false);
         connectingAnimatorView->SetResizeMode(UIImageView::FILL);
-        connectingAnimatorView->Start();
+        // connectingAnimatorView->Start();
 
         return true;
     }
 
+    void AiVoiceConnectingView::StartOrStopAiVoiceConnectingImageAnimatorView(bool val)
+    {
+        if (connectingAnimatorView != nullptr)
+        {
+            if (val)
+                connectingAnimatorView->Start();
+            else
+                connectingAnimatorView->Stop();
+        }
+    }
+
     bool AiVoiceConnectingView::CreateAiVoiceConnectingScrollView(void)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingScrollView");
index 7f8bde1..cdfc8d7 100644 (file)
 #include "custom_runtime.h"
 #include "voice_call_volte_sample_wrapper.h"
 #include <los_base.h>
+#include "websocket_server_manager.h"
+#include "font/ui_font.h"
+
 namespace OHOS
 {
-    // 声明定时器变量
-    static osTimerId_t g_timer = nullptr;
-    static constexpr uint16_t THIRTY_TIME = 30 / 3;
-    static int Time = THIRTY_TIME;
-    static int AiModelConnectTimeout = 5;
-
     AiVoiceModel::AiVoiceModel()
     {
         CreateDirectory("/user/userdata/AiRecording/");
@@ -183,10 +180,10 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetSelect4gorbt() == AI_SELECT_4G");
                 if (GetInit_4gai_task())
                 {
-#if AI_VOICE_ENABLE
-                    uapi_UI_start_asr(GetCurUsing4GAiModelType());
+#ifdef SUPPORT_AI_SERVICE
+                    uapi_start_AI_asr();
 #endif
-                                }
+                }
                 else
                 {
                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "init_4gai_task fail!!");
@@ -195,7 +192,7 @@ namespace OHOS
             else if (GetSelect4gorbt() == AI_SELECT_BT)
             {
 #ifdef SUPPORT_BLE_SERVICE
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "蓝牙:查询Ai是否就绪");
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "蓝牙:查询Ai是否就绪:%d",it->second.second);
                 inquire_AI_is_ready(it->second.second);
 #endif
             }
@@ -411,7 +408,7 @@ namespace OHOS
         {
             return false;
         }
-        
+
         if (!AddUserQuestionToChatItems())
         {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AddUserQuestionToChatItems fail!!");
@@ -842,18 +839,19 @@ namespace OHOS
             if (!OHOS::AiVoiceModel::GetInstance().GetIsLimitDisplayed()) // 如果ai答案没有显示到极限了,就更新ai答案字符串
             {
                 delete_start_line_break_str(str);
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "传入的str:%s", str.c_str());
                 aiAnswerStr += str;
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str());
                 /* -------------------------------------------------------------------------- */
                 // 累积接收到的文本
-                accumulatedText += str;
+                // accumulatedText += str;//tts播放的代码去除掉
                 /* -------------------------------------------------------------------------- */
-                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str());
             }
             if (view_ != nullptr)
             {
                 if (view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible())
                 {
-                    start_ai4g_tts_play_timer(); // 开启一个定时器,用于播放tts音频
+                    // start_ai4g_tts_play_timer(); // 开启一个定时器,用于播放tts音频
                     start_update_ai_answer_timer();
                 }
             }
@@ -885,7 +883,7 @@ namespace OHOS
                     if (!OHOS::AiVoiceModel::GetInstance().GetIsLimitDisplayed()) // 如果ai答案没有显示到极限了,就更新ai答案字符串
                     {
                         aiAnswerStr += str;
-                        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str());
+                        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str());
                         SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0);
                     }
                 }
@@ -942,10 +940,7 @@ namespace OHOS
             }
             else if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G)
             {
-#if AI_VOICE_ENABLE
-                LOS_Msleep(20);
-                startAudioCaptureTask();
-#endif
+                // uapi_start_asr_StartTranscription();录音同步移动到开启asr了,所有这里不调用
             }
 #else
             std::string audioPath = AiVoiceModel::GetInstance().GetAIAudioPath();
@@ -975,12 +970,11 @@ namespace OHOS
     void AiVoiceModel::StopListenAndRecordingUserQuestion(void)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "停止录音");
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "停止录音:%d", GetSelect4gorbt());
         if (GetSelect4gorbt() == AI_SELECT_4G) // 选的是4G需要关闭asr
         {
-            // uapi_stop_asr();
-            // stop_AudioCaptureProcess_AI();
-            // uapi_UI_stop_asr();
+#ifdef SUPPORT_AI_SERVICE
+            uapi_stop_AI_asr();
+#endif
         }
         else if (GetSelect4gorbt() == AI_SELECT_BT)
         {
@@ -1012,8 +1006,6 @@ namespace OHOS
     {
         ClearQuestionAndAiAnswerStr();
         StopListenAndRecordingUserQuestion();
-        Time = THIRTY_TIME;
-        AiModelConnectTimeout = 5;
         AiVoiceConnectStatus = false;
 
         for (int i = 0; i < ChatContentListCount; i++)
@@ -1033,19 +1025,29 @@ namespace OHOS
     }
 
     /* -------------------------------------------------------------------------- */
+    // 声明定时器变量
+    static osTimerId_t g_timer = nullptr;
+    static int Time = DEFAULT_TIMEOUT_10S;
     /*定时器到期时的处理*/
     static void AIVoice_TimerCallbackProc(int data)
     {
         // 等待AI思考完成的定时器
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AIVoice_TimerCallbackProc,Time = %d", Time);
-        if (Time < 0) // 如果思考时间超时30s,进入连接超时界面
+        if (Time < 0) // 如果思考时间超时10s,进入连接超时界面
         {
             AiVoiceModel::GetInstance().AIVoice_StopTimer();
             AiVoiceModel::GetInstance().SetErrnote("连接超时,请重新开始对话");
             std::string str = AiVoiceModel::GetInstance().GetErrnote();
-#if AI_VOICE_ENABLE
-            dinit_ai_task(); // 所有服务都删除重新连一下服务器
+
+            if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G)
+            {
+                // dinit_ai_task(); // 所有服务都删除重新连一下服务器
+#ifdef SUPPORT_AI_SERVICE
+                uapi_stop_all_websocket_servers();
+                uapi_destroy_all_websocket_servers();
 #endif
+            }
+
             SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length());
         }
         else
@@ -1138,19 +1140,18 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
             }
             g_timer = nullptr;
-            Time = THIRTY_TIME;
-            AiModelConnectTimeout = 5;
+            Time = DEFAULT_TIMEOUT_10S;
         }
     }
 
     // 声明定时器变量
     static osTimerId_t g_screen60s_timer = nullptr;
-    static int8_t SCREEN_60S_TIME = 60; // 60s
+    static int8_t SCREEN_60S_TIME = DEFAULT_TIMEOUT_60S; // 60s
 
     static void ai_start_screen60s_timer_callbackProc(int data)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ai_start_screen60s_timer_callbackProc,time = %d", SCREEN_60S_TIME);
-        SCREEN_60S_TIME -= 30;
+        SCREEN_60S_TIME -= DEFAULT_TIMEOUT_30S;
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ai_start_screen60s_timer_callbackProc,time = %d", SCREEN_60S_TIME);
         if (SCREEN_60S_TIME <= 0)
         {
@@ -1214,12 +1215,12 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
             }
             g_screen60s_timer = nullptr;
-            SCREEN_60S_TIME = 60;
+            SCREEN_60S_TIME = DEFAULT_TIMEOUT_60S;
         }
     }
     void AiVoiceModel::reset_ai_screen60s_timer_time()
     {
-        SCREEN_60S_TIME = 60;
+        SCREEN_60S_TIME = DEFAULT_TIMEOUT_60S;
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "reset_ai_screen60s_timer_time %d", SCREEN_60S_TIME);
         if (nullptr == g_screen60s_timer)
         {
@@ -1247,10 +1248,8 @@ namespace OHOS
             AiVoicePresenter *p_AiVoicePresenter = AiVoicePresenter::GetInstance();
             if (AiVoicePresenter::GetInstance() && AivoiceListeningView::GetInstance())
             {
-#if AI_VOICE_ENABLE
-                uapi_UI_stop_asr();
-#endif
-                            AiVoicePresenter::GetInstance()->ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID); // 切换到思考中界面
+                // uapi_UI_stop_asr();
+                AiVoicePresenter::GetInstance()->ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID); // 切换到思考中界面
             }
         }
         else
@@ -1321,8 +1320,8 @@ namespace OHOS
         }
     }
 
-    static osTimerId_t g_ai_is_ready_Handle = nullptr; // 处理查询AI是否就绪定时器
-    static int8_t AI_IS_READY_TIMEOUT = 5;             // 5s钟超时
+    static osTimerId_t g_ai_is_ready_Handle = nullptr;      // 处理查询AI是否就绪定时器
+    static int8_t AI_IS_READY_TIMEOUT = DEFAULT_TIMEOUT_5S; // 5s钟超时
     static void AI_IS_READY_CallbackProc(int data)
     {
         if (AI_IS_READY_TIMEOUT <= 0) // 模型连接失败有5秒超时
@@ -1335,9 +1334,14 @@ namespace OHOS
                 if ((view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING) != nullptr) &&
                     (view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING)->IsVisible()))
                 {
-#if AI_VOICE_ENABLE
-                    dinit_ai_task(); // 所有服务都删除重新连一下服务器
+                    if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G)
+                    {
+                        // dinit_ai_task(); // 所有服务都删除重新连一下服务器
+#ifdef SUPPORT_AI_SERVICE
+                        uapi_stop_all_websocket_servers();
+                        uapi_destroy_all_websocket_servers();
 #endif
+                    }
                     p_AiVoicePresenter->ChangeViewAndLogicOperator(AIVOICE_AIMODE_CONNECTING, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID);
                 }
             }
@@ -1350,10 +1354,9 @@ namespace OHOS
                 if (AiVoiceModel::GetInstance().GetInit_4gai_task())
                 {
                     uint8_t state = 0;
-#if AI_VOICE_ENABLE
-                    state = get_asr_is_ready_start();
-#endif
-                                        if (state)
+                    // state = get_asr_is_ready_start();
+                    state = get_asr_is_ready_start_old();
+                    if (state)
                     {
                         bool state = true;
                         SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool));
@@ -1420,7 +1423,7 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
             }
             g_ai_is_ready_Handle = nullptr;
-            AI_IS_READY_TIMEOUT = 5;
+            AI_IS_READY_TIMEOUT = DEFAULT_TIMEOUT_5S;
         }
     }
 
@@ -1440,8 +1443,10 @@ namespace OHOS
                 if ((view_->GetAiVoiceScrollView(AIVOICE_4GSERVICECON_VIEW) != nullptr) &&
                     (view_->GetAiVoiceScrollView(AIVOICE_4GSERVICECON_VIEW)->IsVisible()))
                 {
-#if AI_VOICE_ENABLE
-                    dinit_ai_task(); // 所有服务都删除重新连一下服务器
+                    // dinit_ai_task(); // 所有服务都删除重新连一下服务器
+#ifdef SUPPORT_AI_SERVICE
+                    uapi_stop_all_websocket_servers();
+                    uapi_destroy_all_websocket_servers();
 #endif
                     p_AiVoicePresenter->ChangeViewAndLogicOperator(AIVOICE_4GSERVICECON_VIEW, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID);
                 }
@@ -1451,20 +1456,12 @@ namespace OHOS
         {
             if (view_ != nullptr && p_AiVoicePresenter != nullptr)
             {
-#if AI_VOICE_ENABLE
-                if (uapi_get_server_state_is_end())
-                {
-                    init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
-                    return;
-                }
-
                 if (AiVoiceModel::GetInstance().GetInit_4gai_task())
                 {
                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "4gAi服务初始化成功");
                     AiVoiceModel::GetInstance().stop_ai4g_connect_timer();
                     p_AiVoicePresenter->ChangeViewAndLogicOperator(AIVOICE_4GSERVICECON_VIEW, AIVOICE_AIMODE_CONNECTING);
                 }
-#endif
             }
         }
         return;
@@ -1649,7 +1646,7 @@ namespace OHOS
         else
         {
             // if(AiVoiceModel::GetInstance().GetUserQuestionStr() !=)
-            // SendMsgToUIService(UI_UPDATE_USER_QUESTION_STR, 0, nullptr, 0); 
+            // SendMsgToUIService(UI_UPDATE_USER_QUESTION_STR, 0, nullptr, 0);
 
             SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0);
         }
@@ -1821,23 +1818,7 @@ namespace OHOS
     }
     bool AiVoiceModel::GetInit_4gai_task(void)
     {
-        uint8_t asr_state = 0;
-        uint8_t chat_state = 0;
-        uint8_t tts_state = 0;
-#if AI_VOICE_ENABLE
-        asr_state = get_ai_asr_service_init_flag();
-        chat_state = get_ai_chat_service_init_flag();
-        tts_state = get_ai_tts_server_init_flag();
-#endif
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "asr_state:%d,chat_state:%d,tts_state:%d", asr_state, chat_state, tts_state);
-        if ((asr_state == 1) && (chat_state == 1) && (tts_state == 1))
-        {
-            init_4gai_task = true;
-        }
-        else
-        {
-            init_4gai_task = false;
-        }
+        init_4gai_task = are_all_services_ready();
         return init_4gai_task;
     }
 
@@ -1849,13 +1830,6 @@ namespace OHOS
     {
         return select4gorbt;
     }
-    // 打断tts播放
-    void AiVoiceModel::cancel_tts_play(void)
-    {
-#if AI_VOICE_ENABLE
-        tts_server_deinit();
-#endif
-    }
 
     // 是否需要跳转到结果视图
     bool AiVoiceModel::is_need_to_jump_result_view(void)
@@ -1973,7 +1947,6 @@ namespace OHOS
 #endif
         return textId;
     }
-
 }
 
 #ifdef __cplusplus
@@ -1991,46 +1964,268 @@ extern "C"
         return 0;
     }
 
-    static uint8_t clear_queue_stream = 0;
-    uint8_t get_clear_queue_stream(void)
+#ifdef BLE_INSTRUCT
+
+    /**
+     * @brief 过滤字符串中无法显示的文字(使用GetGlyphPathData接口)
+     * @param input_str 输入字符串
+     * @param output_str 输出字符串缓冲区
+     * @param max_len 输出缓冲区最大长度
+     * @return 过滤后的字符串长度,-1表示失败
+     */
+    int32_t chat_filter_unsupported_chars(const char *input_str, char *output_str, uint32_t max_len)
     {
-        return clear_queue_stream;
+        if (input_str == NULL || output_str == NULL || max_len == 0)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Invalid parameters for asr_filter_unsupported_chars\n");
+            return -1;
+        }
+
+        // 初始化输出缓冲区
+        memset(output_str, 0, max_len);
+
+        uint32_t input_len = strlen(input_str);
+        uint32_t output_pos = 0;
+        uint32_t input_pos = 0;
+
+        while (input_pos < input_len && output_pos < max_len - 1)
+        {
+            uint32_t char_start = input_pos;
+            uint32_t char_end = input_pos;
+
+            // 获取下一个UTF-8字符
+            uint32_t unicode_char = 0;
+            bool valid_utf8 = false;
+
+            // 简单的UTF-8解码
+            if ((unsigned char)input_str[input_pos] < 0x80)
+            {
+                // ASCII字符
+                unicode_char = (unsigned char)input_str[input_pos];
+                char_end = input_pos + 1;
+                valid_utf8 = true;
+            }
+            else if ((unsigned char)input_str[input_pos] >= 0xC0 && (unsigned char)input_str[input_pos] < 0xE0)
+            {
+                // 2字节UTF-8字符
+                if (input_pos + 1 < input_len)
+                {
+                    unicode_char = ((unsigned char)input_str[input_pos] & 0x1F) << 6 |
+                                   ((unsigned char)input_str[input_pos + 1] & 0x3F);
+                    char_end = input_pos + 2;
+                    valid_utf8 = true;
+                }
+            }
+            else if ((unsigned char)input_str[input_pos] >= 0xE0 && (unsigned char)input_str[input_pos] < 0xF0)
+            {
+                // 3字节UTF-8字符
+                if (input_pos + 2 < input_len)
+                {
+                    unicode_char = ((unsigned char)input_str[input_pos] & 0x0F) << 12 |
+                                   ((unsigned char)input_str[input_pos + 1] & 0x3F) << 6 |
+                                   ((unsigned char)input_str[input_pos + 2] & 0x3F);
+                    char_end = input_pos + 3;
+                    valid_utf8 = true;
+                }
+            }
+            else if ((unsigned char)input_str[input_pos] >= 0xF0 && (unsigned char)input_str[input_pos] < 0xF8)
+            {
+                // 4字节UTF-8字符
+                if (input_pos + 3 < input_len)
+                {
+                    unicode_char = ((unsigned char)input_str[input_pos] & 0x07) << 18 |
+                                   ((unsigned char)input_str[input_pos + 1] & 0x3F) << 12 |
+                                   ((unsigned char)input_str[input_pos + 2] & 0x3F) << 6 |
+                                   ((unsigned char)input_str[input_pos + 3] & 0x3F);
+                    char_end = input_pos + 4;
+                    valid_utf8 = true;
+                }
+            }
+
+            if (!valid_utf8)
+            {
+                // 无效的UTF-8字符,跳过
+                input_pos++;
+                continue;
+            }
+
+            // 使用GetGlyphPathData接口检查字符是否可以在字体中显示
+            bool char_supported = true;
+
+            // 对于ASCII字符,直接支持
+            if (unicode_char < 0x80)
+            {
+                char_supported = true;
+            }
+            else
+            {
+                // 使用字体引擎检查字符是否支持
+                OHOS::UIFont *fontEngine = OHOS::UIFont::GetInstance();
+                if (fontEngine != NULL)
+                {
+                    // 使用GetGlyphPathData检查字符是否支持
+                    OHOS::GlyphPathData path;
+                    if (!fontEngine->GetGlyphPathData(unicode_char, 0, path))
+                    {
+                        // 字符不支持,标记为不支持
+                        char_supported = false;
+                        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Character 0x%X not supported by font engine\n", unicode_char);
+                    }
+                    else
+                    {
+                        // 字符支持
+                        char_supported = true;
+                    }
+                }
+                else
+                {
+                    // 字体引擎不可用,使用简化的字符范围检查
+                    if (unicode_char >= 0x4E00 && unicode_char <= 0x9FFF)
+                    {
+                        // 中文字符范围
+                        char_supported = true;
+                    }
+                    else if (unicode_char >= 0xAC00 && unicode_char <= 0xD7AF)
+                    {
+                        // 韩文字符范围
+                        char_supported = true;
+                    }
+                    else if (unicode_char >= 0x3040 && unicode_char <= 0x309F)
+                    {
+                        // 平假名
+                        char_supported = true;
+                    }
+                    else if (unicode_char >= 0x30A0 && unicode_char <= 0x30FF)
+                    {
+                        // 片假名
+                        char_supported = true;
+                    }
+                    else if (unicode_char >= 0x2000 && unicode_char <= 0x206F)
+                    {
+                        // 标点符号
+                        char_supported = true;
+                    }
+                    else
+                    {
+                        // 其他字符,标记为不支持
+                        char_supported = false;
+                    }
+                }
+            }
+
+            if (char_supported)
+            {
+                // 字符支持,复制到输出缓冲区
+                uint32_t char_len = char_end - char_start;
+                if (output_pos + char_len < max_len)
+                {
+                    memcpy(&output_str[output_pos], &input_str[char_start], char_len);
+                    output_pos += char_len;
+                }
+                else
+                {
+                    break; // 输出缓冲区已满
+                }
+            }
+            else
+            {
+                // 字符不支持,跳过不支持的字符
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Unsupported character: 0x%X, skipping\n", unicode_char);
+            }
+
+            input_pos = char_end;
+        }
+
+        // 确保输出字符串以null结尾
+        output_str[output_pos] = '\0';
+
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Filtered string: '%s' -> '%s' (length: %d)\n",
+                      input_str, output_str, output_pos);
+
+        return output_pos;
     }
 
-    // 清空队列中可能存在的音频数据
-    void set_clear_queue_stream(uint8_t state)
+    /**
+     * @brief 过滤chat结果中的无法显示字符
+     * @param result chat识别结果字符串
+     * @return 过滤后的字符串长度,-1表示失败
+     */
+    int32_t chat_filter_result_chars(char *result)
     {
-        clear_queue_stream = state;
-    }
+        if (result == NULL)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " result string is NULL\n");
+            return -1;
+        }
 
+        uint32_t max_len = strlen(result) + 1;
+        char *temp_buffer = (char *)malloc(max_len);
+        if (temp_buffer == NULL)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to allocate memory for temp buffer\n");
+            return -1;
+        }
 
-    #ifdef BLE_INSTRUCT
+        int32_t filtered_len = chat_filter_unsupported_chars(result, temp_buffer, max_len);
+        if (filtered_len >= 0)
+        {
+            strcpy(result, temp_buffer);
+        }
 
-    #include "bleEvent.h"
-    #include "bleInstruct.h"
+        free(temp_buffer);
+        return filtered_len;
+    }
+
+#include "bleEvent.h"
+#include "bleInstruct.h"
 
     void ble_set_ai_Question_str_(char *buf)
     {
+        printf("ble_set_ai_Question_str_ %s\n",buf);
         OHOS::AiVoiceModel::GetInstance().SetUserQuestionStr(std::string(buf));
     }
 
+    void ble_set_ai_Answer_str_(char *buf, uint8_t type)
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ble_set_ai_Answer_str_:%s,type:%d",buf,type);
+        // chat_filter_result_chars(buf);
+        OHOS::AiVoiceModel::GetInstance().SetAiAnswerStrStr(std::string(buf), type);
+    }
 
-    void ble_set_ai_Answer_str_(char *buf,uint8_t type)
+    void ble_app_reply_(bool data)
     {
-        OHOS::AiVoiceModel::GetInstance().SetAiAnswerStrStr(std::string(buf),type);
+        bool state = data;
+        printf("ble_app_reply_:%d\n",state);
+        SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool));
     }
 
     extern bleInstruct_t_ bleInstruct_t;
 
     void ble_AI_init(void)
     {
-        bleInstruct_t.ble_set_ai_Question_str= ble_set_ai_Question_str_;
+        bleInstruct_t.ble_set_ai_Question_str = ble_set_ai_Question_str_;
 
-        bleInstruct_t.ble_set_ai_Answer_str=ble_set_ai_Answer_str_;
+        bleInstruct_t.ble_set_ai_Answer_str = ble_set_ai_Answer_str_;
+        bleInstruct_t.ble_app_reply = ble_app_reply_;
     }
 
-    #endif
+    /*
+     * WebSocket 聊天结果过滤回调包装,匹配 ws_register_chat_filter_callback 的签名
+     */
+    static void ws_chat_filter_cb_wrapper(char *result)
+    {
+        /* 复用现有过滤实现,忽略返回长度 */
+        chat_filter_result_chars(result);
+    }
 
+    void net4g_AI_init(void)
+    {
+        ws_register_chat_filter_callback(ws_chat_filter_cb_wrapper);
+        ws_register_ai_question_callback(ble_set_ai_Question_str_);
+        ws_register_ai_answer_callback(ble_set_ai_Answer_str_);
+    }
+
+#endif
 
 #ifdef __cplusplus
 #if __cplusplus
index b64dcfb..8c5b800 100644 (file)
 #include "NativeRegisterManager.h"
 #include "aivoice/include/AiVoiceSelectView.h"
 #include "graphic_service.h"
+#include "websocket_server_manager.h"
+#include "custom_utils.h"
 namespace OHOS
 {
 
     REGIST_MENU_PRO(VIEW_AI_VOICE, AiVoiceView, AiVoicePresenter,
-                    PNG_APPLIST_AIVOICE_IMAGE_BIG, PNG_APPLIST_AIVOICE_IMAGE, PNG_APPLIST_AIVOICE_IMAGE, "AI全家桶", STR_AI_FAMILY_MEALS);
+                    PNG_APPLIST_AIVOICE_IMAGE_BIG, PNG_APPLIST_AIVOICE_IMAGE, PNG_APPLIST_AIVOICE_IMAGE, "星辰AI", STR_AI_FAMILY_MEALS);
 
 #ifdef __cplusplus
     extern "C"
@@ -43,7 +45,6 @@ namespace OHOS
 #include <asm/delay.h>
 #include <aivoice/include/AiVoiceModelC.h>
 #include <los_base.h>
-        extern void set_need_tts_reconnect(uint8_t flag);
 
         void remove_4GAI_vote(void)
         {
@@ -96,12 +97,12 @@ namespace OHOS
     void AiVoicePresenter::OnStart()
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStart");
-        Presenter<AiVoiceView>::OnStart();
         ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON);
         // 开启一个60s取消长亮屏timer
         model->ai_start_screen60s_timer();
         add_4GAI_vote(); // 4g投票
 
+        net4g_AI_init();
         uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_HIGH_AI);
         Audio::AudioManager::GetInstance().SetVolume(AUDIO_STREAM_VOICE_ASSISTANT, 100);
     }
@@ -110,7 +111,6 @@ namespace OHOS
     void AiVoicePresenter::OnStop(void)
     {
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStop start");
-        Presenter<AiVoiceView>::OnStop();
         ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON);
         model->StatusResume();
         model->AIVoice_StopTimer();
@@ -122,9 +122,10 @@ namespace OHOS
         model->stop_update_ai_answer_timer();
         model->stop_uapi_stop_tts_timer();
         remove_4GAI_vote(); // 移除4g投票
-#if AI_VOICE_ENABLE
-        dinit_ai_task();
-        ai_cleanup_resources();
+
+#ifdef SUPPORT_AI_SERVICE
+        uapi_stop_all_websocket_servers();
+        uapi_destroy_all_websocket_servers();
 #endif
 
         uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_SLOW);
@@ -334,7 +335,6 @@ namespace OHOS
             break;
 
         case AIVOICE_RETURN_RESULT_TEXT_VIEWID:
-            // set_need_tts_reconnect(0);                                 // 停止tts重连
             AiVoiceModel::GetInstance().ClearQuestionAndAiAnswerStr(); // 清空上次用户问题和Ai回答字符串
             AiVoiceModel::GetInstance().SetIsClickable(false);
             AiVoiceModel::GetInstance().SetIsLimitDisplayed(false);
@@ -358,10 +358,8 @@ namespace OHOS
             AiVoiceModel::GetInstance().start_ai_isready_timer();
             break;
         case AIVOICE_RETURN_RESULT_TEXT_VIEWID:
-            // set_need_tts_reconnect(1); // 开始tts重连
             break;
         case AIVOICE_LISTENING_VIEWID:
-            // set_stop_send_ai_flag(0); // 开始发送AI数据
             AiVoiceModel::GetInstance().StartListenAndRecordingUserQuestion();
             AiVoiceModel::GetInstance().start_listening_timer();
             break;
@@ -463,7 +461,11 @@ namespace OHOS
                     }
                     if (!model->GetInit_4gai_task())
                     {
-                        // init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
+// init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
+#ifdef SUPPORT_AI_SERVICE
+                        uapi_init_all_websocket_servers();
+                        uapi_start_all_websocket_servers(0); // 连接服务器
+#endif
                         model->start_ai4g_connect_timer();
                         ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_4GSERVICECON_VIEW); // LOADING
                     }
@@ -495,7 +497,13 @@ namespace OHOS
                 }
                 if (!model->GetInit_4gai_task())
                 {
+                    /* -------------------------------------------------------------------------- */
                     // init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
+#ifdef SUPPORT_AI_SERVICE
+                    uapi_init_all_websocket_servers();
+                    uapi_start_all_websocket_servers(0); // 连接服务器
+#endif
+                    /* -------------------------------------------------------------------------- */
                     model->start_ai4g_connect_timer();
                     ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_4GSERVICECON_VIEW); // LOADING
                 }
@@ -520,22 +528,7 @@ namespace OHOS
         }
         else if (viewId == FINISH_SPEAKING_BUTTON_VIEW_ID) // 如果点击的是说话完毕按钮
         {
-            if (model->GetSelect4gorbt() == AI_SELECT_4G)
-            {
-#if AI_VOICE_ENABLE
-                uapi_UI_stop_asr();
-#endif
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FINISH_SPEAKING_BUTTON_VIEW_ID:(%d,%d)", model->is_need_to_jump_result_view(), model->getentryTextViewState());
-                if (!model->is_need_to_jump_result_view() && !model->getentryTextViewState()) // 没有数据就跳转到思考中界面
-                {
-                    GraphicService::GetInstance()->PostGraphicEvent(
-                        std::bind(&OHOS::AiVoicePresenter::JumpThinkingView, OHOS::AiVoicePresenter::GetInstance()));
-                }
-            }
-            else if (model->GetSelect4gorbt() == AI_SELECT_BT)
-            {
-                ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID);
-            }
+            ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID);
             return true;
         }
         else if (viewId == AIVOICE_SELECT_VIEW_BUTTON4G_VIEW_ID) // 如果点击的是4G连接方式
@@ -550,6 +543,10 @@ namespace OHOS
             if (!model->GetInit_4gai_task())
             {
                 // init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
+#ifdef SUPPORT_AI_SERVICE
+                uapi_init_all_websocket_servers();
+                uapi_start_all_websocket_servers(0); // 连接服务器
+#endif
                 model->start_ai4g_connect_timer();
                 ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_4GSERVICECON_VIEW); // LOADING
             }
@@ -582,10 +579,6 @@ namespace OHOS
                 {
                     AiVoiceModel::GetInstance().stop_ai4g_tts_play_timer();
                     AiVoiceModel::GetInstance().stop_uapi_stop_tts_timer();
-                    // usleep(50000);
-                    set_clear_queue_stream(1);
-                    LOS_Msleep(100);
-                    // uapi_UI_start_asr(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType());
                     ChangeViewAndLogicOperator(AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_AIMODE_CONNECTING);
                     return true;
                 }
@@ -601,10 +594,9 @@ namespace OHOS
                 {
                     AiVoiceModel::GetInstance().stop_ai4g_tts_play_timer();
                     AiVoiceModel::GetInstance().stop_uapi_stop_tts_timer();
-                    set_clear_queue_stream(1);
-                    LOS_Msleep(100);
-#if AI_VOICE_ENABLE
-                    dinit_ai_task();
+#ifdef SUPPORT_AI_SERVICE
+                    uapi_stop_all_websocket_servers();
+                    uapi_destroy_all_websocket_servers();
 #endif
                 }
             }
@@ -626,10 +618,11 @@ namespace OHOS
             {
                 if (model->GetSelect4gorbt() == AI_SELECT_4G)
                 {
-#if AI_VOICE_ENABLE
-                    dinit_ai_task();
+                    // dinit_ai_task();
+#ifdef SUPPORT_AI_SERVICE
+                    uapi_stop_all_websocket_servers();
+                    uapi_destroy_all_websocket_servers();
 #endif
-                    LOS_Msleep(50);
                 }
             }
             ChangeViewAndLogicOperator(it->second.first, it->second.second);
@@ -673,7 +666,7 @@ namespace OHOS
         {
             if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID))
             {
-                //开始对话界面,右滑切换界面
+                // 开始对话界面,右滑切换界面
                 DragLeftToRightChangeAIModel();
             }
             else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID))
@@ -728,7 +721,7 @@ namespace OHOS
         }
         else if (model->GetAiModelTextId() == STR_AIMODES_CHATGPT && event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) /*上滑*/
         {
-            //如果选择的模型是在chatgpt
+            // 如果选择的模型是在chatgpt
             if (model->IsExistOpenAIAPIKeys() == true)
             {
                 ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_SETAPIKEYS); /*开始对话界面->API Keys set界面*/
index 00ffa54..a0a8fd7 100644 (file)
@@ -1,16 +1,17 @@
 /*
- * @Author: luozheng 1732036298@qq.com
- * @Date: 2024-05-07 11:25:58
- * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2025-03-06 16:07:08
- * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceView.cpp
- */
+* @Author: luozheng 1732036298@qq.com
+* @Date: 2024-05-07 11:25:58
+* @LastEditors: luozheng 1732036298@qq.com
+* @LastEditTime: 2025-03-06 16:07:08
+* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceView.cpp
+*/
 #include "aivoice/include/AiVoicePresenter.h"
 #include "aivoice/include/AiVoiceView.h"
 #include "aivoice/include/AiVoiceModel.h"
 #include "wearable_log.h"
 #include "ui_resource_string.h"
 #include "ConfigModel.h"
+#include "uiservice/include/ui_service.h"
 namespace OHOS
 {
 
@@ -486,7 +487,7 @@ namespace OHOS
             VolumeProcess->SetKnobStyle(StyleDefault::GetSliderKnobStyle());
             VolumeProcess->RequestFocus();
             VolumeProcess->SetRotateFactor(5.0);
-            // VolumeProcess->SetVisible(false);
+            VolumeProcess->SetVisible(false);
             VolumeProcess->SetOnRotateListener(presenter_);
             AddViewToRootContainer(VolumeProcess);
         }
@@ -497,7 +498,7 @@ namespace OHOS
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceView");
         if (!CreateAiVoiceScrollView() || !CreateAiVoiceViewImageView() || !CreateAiVoiceViewPicker() ||
-            !CreateAiVoiceViewLabel() || !CreateAiVoiceViewButton() || !CreateAiVoiceVoiceView())
+            !CreateAiVoiceViewLabel() || !CreateAiVoiceViewButton())
         {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceView fail!");
             return nullptr;
@@ -521,6 +522,12 @@ namespace OHOS
     void AiVoiceView::OnStart()
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::OnStart");
+        ChangeView(MAX_AIVOICE_VIEWID, AIVOICE_AIMODE_CONNECTING);
+        GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING)->SetVisible(false);
+        ChangeView(MAX_AIVOICE_VIEWID, AIVOICE_LISTENING_VIEWID);
+        GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID)->SetVisible(false);
+        ChangeView(MAX_AIVOICE_VIEWID, AIVOICE_THINKING_VIEWID);
+        GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)->SetVisible(false);
         ChangeView(MAX_AIVOICE_VIEWID, AIVOICE_STARTCHAT_VIEWID);
 #if defined(AI_VOICE_FD230) || defined(AI_VOICE_N9)
         CreateAiVoiceVoiceView();
@@ -531,8 +538,6 @@ namespace OHOS
         return;
     }
 
-
-
     /*切换到开始对话Ai界面*/
     bool AiVoiceView::ChangeAiVoiceStartChatView(int16_t thisView)
     {
@@ -721,6 +726,17 @@ namespace OHOS
             AiVoiceScrollView[thisView] = scrollview;
             AddViewToRootContainer(AiVoiceScrollView[thisView]);
         }
+        if (!AiVoiceModel::GetInstance().GetUserQuestionStr().empty())
+        {
+            SendMsgToUIService(UI_UPDATE_USER_QUESTION_STR, 0, nullptr, 0);
+        }
+        if(AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G)
+        {
+            if (VolumeProcess)
+            {
+                VolumeProcess->SetVisible(true);
+            }
+        }
         return true;
     }
 
@@ -821,6 +837,10 @@ namespace OHOS
             AiVoiceScrollView[thisView] = scrollview;
             AddViewToRootContainer(AiVoiceScrollView[thisView]);
         }
+        if(p_AiVoiceConnectingView)
+        {
+            p_AiVoiceConnectingView->StartOrStopAiVoiceConnectingImageAnimatorView(true);
+        }
         return true;
     }
 
@@ -867,6 +887,10 @@ namespace OHOS
             AiVoiceScrollView[thisView] = scrollview;
             AddViewToRootContainer(AiVoiceScrollView[thisView]);
         }
+        if(p_Aivoice4gServiceConView)
+        {
+            p_Aivoice4gServiceConView->StartOrStopAiVoice4gServiceConImageAnimatorView(true);
+        }
         return true;
     }
 
@@ -954,10 +978,10 @@ namespace OHOS
     }
 
     static const int16 AiVoiceDestroyMapper[] = {
-        AIVOICE_AIMODE_CONNECTING,
+        // AIVOICE_AIMODE_CONNECTING,
         AIVOICE_4GSERVICECON_VIEW,
-        AIVOICE_LISTENING_VIEWID,
-        AIVOICE_THINKING_VIEWID,
+        // AIVOICE_LISTENING_VIEWID,
+        // AIVOICE_THINKING_VIEWID,
         AIVOICE_SELECT_VIEW,
         AIVOICE_CONNECT_TIMEOUT_VIEWID,
         AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID,
@@ -982,13 +1006,15 @@ namespace OHOS
                 break;
             }
         }
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DestroyTempView:%d",hideView);
         switch (hideView)
         {
         case AIVOICE_AIMODE_CONNECTING:
             if (p_AiVoiceConnectingView)
             {
-                delete p_AiVoiceConnectingView;
-                p_AiVoiceConnectingView = nullptr;
+                // delete p_AiVoiceConnectingView;
+                // p_AiVoiceConnectingView = nullptr;
+                p_AiVoiceConnectingView->StartOrStopAiVoiceConnectingImageAnimatorView(false);
             }
             break;
         case AIVOICE_4GSERVICECON_VIEW:
@@ -996,25 +1022,23 @@ namespace OHOS
             {
                 delete p_Aivoice4gServiceConView;
                 p_Aivoice4gServiceConView = nullptr;
+                // p_Aivoice4gServiceConView->StartOrStopAiVoice4gServiceConImageAnimatorView(false);
             }
             break;
         case AIVOICE_LISTENING_VIEWID:
             if (p_AivoiceListeningView)
             {
-                if (p_AivoiceListeningView)
-                {
-                    delete p_AivoiceListeningView;
-                    p_AivoiceListeningView = nullptr;
-                }
-                // p_AivoiceListeningView->StartOrStopAivoiceListeningImageAnimatorView(false);
+                // delete p_AivoiceListeningView;
+                // p_AivoiceListeningView = nullptr;
+                p_AivoiceListeningView->StartOrStopAivoiceListeningImageAnimatorView(false);
             }
             break;
         case AIVOICE_THINKING_VIEWID:
             if (p_AivoiceThinkingView)
             {
-                delete p_AivoiceThinkingView;
-                p_AivoiceThinkingView = nullptr;
-                // p_AivoiceThinkingView->StartOrStopAiVoiceThinkingImageAnimatorView(false);
+                // delete p_AivoiceThinkingView;
+                // p_AivoiceThinkingView = nullptr;
+                p_AivoiceThinkingView->StartOrStopAiVoiceThinkingImageAnimatorView(false);
             }
             break;
         case AIVOICE_SELECT_VIEW:
@@ -1069,7 +1093,7 @@ namespace OHOS
 
     void AiVoiceView::ChangeView(int16_t hideView, int16_t showView)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeView hideView:%d, showView:%d", hideView, showView);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeView hideView:%d, showView:%d", hideView, showView);
         if (!CheckViewParam(hideView, showView))
         {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CheckViewParam failed.");
index f51a412..2089b30 100644 (file)
@@ -131,4 +131,15 @@ namespace OHOS
 
         return scrollView;
     }
+
+    void AiVoice4gServiceConView::StartOrStopAiVoice4gServiceConImageAnimatorView(bool val)
+    {
+        if (AI4GImageAni != nullptr)
+        {
+            if (val)
+                AI4GImageAni->Start();
+            else
+                AI4GImageAni->Stop();
+        }
+    }
 }