AI语音优化,添加日志打印
authorluozheng <1732036298@qq.com>
Mon, 28 Oct 2024 03:31:49 +0000 (11:31 +0800)
committerluozheng <1732036298@qq.com>
Mon, 28 Oct 2024 03:31:49 +0000 (11:31 +0800)
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceThinkingView.cpp

index 35c847d..6adb6e0 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 15:14:50
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-10-23 14:19:17
+ * @LastEditTime: 2024-10-28 11:02:51
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
  */
 #include "aivoice/include/AiVoiceModel.h"
@@ -546,7 +546,7 @@ namespace OHOS
     // 停止聆听用户问题
     void AiVoiceModel::StopListenAndRecordingUserQuestion(void)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::StopListenAndRecordingUserQuestion");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::StopListenAndRecordingUserQuestion");
         int32_t argc = 1;
         uint8_t *argv = (uint8_t *)"stop";
         AudioCaptureSample(argc, (const char **)&argv);
@@ -714,7 +714,7 @@ namespace OHOS
 
     // 声明定时器变量
     static osTimerId_t g_screen60s_timer = nullptr;
-    static uint16_t SCREEN_60S_TIME = 60; // 60s
+    static int8_t SCREEN_60S_TIME = 60; // 60s
 
     static void ai_start_screen60s_timer_callbackProc(int data)
     {
@@ -796,7 +796,7 @@ namespace OHOS
     }
 
     static osTimerId_t g_listeningEndHandle = nullptr;
-    static uint8_t LISTENING_TIMEOUT = 10; // 10s钟无操作关闭该视图
+    static int8_t LISTENING_TIMEOUT = 10; // 10s钟无操作关闭该视图
     static void AIListeningCallbackProc(int data)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AIListeningCallbackProc %d", LISTENING_TIMEOUT);
@@ -880,7 +880,7 @@ namespace OHOS
     }
 
     static osTimerId_t g_ai_is_ready_Handle = nullptr; // 处理查询AI是否就绪定时器
-    static uint8_t AI_IS_READY_TIMEOUT = 5;            // 5s钟超时
+    static int8_t AI_IS_READY_TIMEOUT = 5;            // 5s钟超时
     static void AI_IS_READY_CallbackProc(int data)
     {
         if (AI_IS_READY_TIMEOUT <= 0) // 模型连接失败有5秒超时
index df62d02..ef2258f 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-05-07 11:25:58
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-10-17 10:39:36
+ * @LastEditTime: 2024-10-28 11:14:56
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceView.cpp
  */
 #include "aivoice/include/AiVoicePresenter.h"
@@ -530,7 +530,14 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
                 return false;
             }
-            AiVoiceScrollView[thisView] = p_AiVoiceBluetoothFailedStartView->CreateAiVoiceBluetoothFailedStartView();
+            // AiVoiceScrollView[thisView] = p_AiVoiceBluetoothFailedStartView->CreateAiVoiceBluetoothFailedStartView();
+            UIScrollView *scrollview = p_AiVoiceBluetoothFailedStartView->CreateAiVoiceBluetoothFailedStartView();
+            if (scrollview == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
+                return false;
+            }
+            AiVoiceScrollView[thisView] = scrollview;
             container_->Add(AiVoiceScrollView[thisView]);
         }
         return true;
@@ -548,7 +555,14 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
                 return false;
             }
-            AiVoiceScrollView[thisView] = p_AivoiceMobileDataFailedStartView->CreateAivoiceMobileDataFailedStartView();
+            // AiVoiceScrollView[thisView] = p_AivoiceMobileDataFailedStartView->CreateAivoiceMobileDataFailedStartView();
+            UIScrollView *scrollview = p_AivoiceMobileDataFailedStartView->CreateAivoiceMobileDataFailedStartView();
+            if (scrollview == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
+                return false;
+            }
+            AiVoiceScrollView[thisView] = scrollview;
             container_->Add(AiVoiceScrollView[thisView]);
         }
         return true;
@@ -566,7 +580,14 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
                 return false;
             }
-            AiVoiceScrollView[thisView] = p_AivoiceConnectTimeoutView->CreateAivoiceConnectTimeoutView();
+            // AiVoiceScrollView[thisView] = p_AivoiceConnectTimeoutView->CreateAivoiceConnectTimeoutView();
+            UIScrollView *scrollview = p_AivoiceConnectTimeoutView->CreateAivoiceConnectTimeoutView();
+            if (scrollview == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
+                return false;
+            }
+            AiVoiceScrollView[thisView] = scrollview;
             container_->Add(AiVoiceScrollView[thisView]);
         }
 
@@ -585,10 +606,17 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
                 return false;
             }
-            AiVoiceScrollView[thisView] = p_AivoiceListeningView->CreateAivoiceListeningView();
+            // AiVoiceScrollView[thisView] = p_AivoiceListeningView->CreateAivoiceListeningView();
+            UIScrollView *scrollview = p_AivoiceListeningView->CreateAivoiceListeningView();
+            if (scrollview == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
+                return false;
+            }
+            AiVoiceScrollView[thisView] = scrollview;
             container_->Add(AiVoiceScrollView[thisView]);
         }
-        if(p_AivoiceListeningView)
+        if (p_AivoiceListeningView)
         {
             p_AivoiceListeningView->GetShowtimeoutLabel()->SetText("10");
             p_AivoiceListeningView->GetShowtimeoutLabel()->Invalidate();
@@ -609,7 +637,14 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
                 return false;
             }
-            AiVoiceScrollView[thisView] = p_AivoiceThinkingView->CreateAivoiceThinkingView();
+            // AiVoiceScrollView[thisView] = p_AivoiceThinkingView->CreateAivoiceThinkingView();
+            UIScrollView *scrollview = p_AivoiceThinkingView->CreateAivoiceThinkingView();
+            if (scrollview == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
+                return false;
+            }
+            AiVoiceScrollView[thisView] = scrollview;
             container_->Add(AiVoiceScrollView[thisView]);
         }
         return true;
@@ -627,7 +662,14 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
                 return false;
             }
-            AiVoiceScrollView[thisView] = p_AivoiceReturnResultTextView->CreateAivoiceReturnResultTextView();
+            // AiVoiceScrollView[thisView] = p_AivoiceReturnResultTextView->CreateAivoiceReturnResultTextView();
+            UIScrollView *scrollview = p_AivoiceReturnResultTextView->CreateAivoiceReturnResultTextView();
+            if (scrollview == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
+                return false;
+            }
+            AiVoiceScrollView[thisView] = scrollview;
             container_->Add(AiVoiceScrollView[thisView]);
         }
         return true;
@@ -645,7 +687,14 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
                 return false;
             }
-            AiVoiceScrollView[thisView] = p_SetApiKeysView->CreateSetApiKeysView();
+            // AiVoiceScrollView[thisView] = p_SetApiKeysView->CreateSetApiKeysView();
+            UIScrollView *scrollview = p_SetApiKeysView->CreateSetApiKeysView();
+            if (scrollview == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
+                return false;
+            }
+            AiVoiceScrollView[thisView] = scrollview;
             container_->Add(AiVoiceScrollView[thisView]);
         }
         return true;
@@ -663,7 +712,14 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
                 return false;
             }
-            AiVoiceScrollView[thisView] = p_NotSetApiKeysView->CreateNotSetApiKeysView();
+            // AiVoiceScrollView[thisView] = p_NotSetApiKeysView->CreateNotSetApiKeysView();
+            UIScrollView *scrollview = p_NotSetApiKeysView->CreateNotSetApiKeysView();
+            if (scrollview == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
+                return false;
+            }
+            AiVoiceScrollView[thisView] = scrollview;
             container_->Add(AiVoiceScrollView[thisView]);
         }
         return true;
@@ -681,7 +737,14 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
                 return false;
             }
-            AiVoiceScrollView[thisView] = p_ApiKeysDeleteView->CreateApiKeysDeleteView();
+            // AiVoiceScrollView[thisView] = p_ApiKeysDeleteView->CreateApiKeysDeleteView();
+            UIScrollView *scrollview = p_ApiKeysDeleteView->CreateApiKeysDeleteView();
+            if (scrollview == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
+                return false;
+            }
+            AiVoiceScrollView[thisView] = scrollview;
             container_->Add(AiVoiceScrollView[thisView]);
         }
         return true;
@@ -699,7 +762,14 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
                 return false;
             }
-            AiVoiceScrollView[thisView] = p_AiVoiceConnectingView->CreateAiVoiceConnectingView();
+            // AiVoiceScrollView[thisView] = p_AiVoiceConnectingView->CreateAiVoiceConnectingView();
+            UIScrollView *scrollview = p_AiVoiceConnectingView->CreateAiVoiceConnectingView();
+            if (scrollview == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView);
+                return false;
+            }
+            AiVoiceScrollView[thisView] = scrollview;
             container_->Add(AiVoiceScrollView[thisView]);
         }
         return true;
@@ -736,6 +806,7 @@ namespace OHOS
                 bool jug = (this->*(ViewMapper[i].func))(interface);
                 if (jug == false)
                 {
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ClickFunc err.");
                     return false;
                 }
                 return true;
@@ -772,8 +843,11 @@ namespace OHOS
         {
             if (hideView == AiVoiceDestroyMapper[i])
             {
-                container_->Remove(AiVoiceScrollView[hideView]);
-                AiVoiceScrollView[hideView] = nullptr;
+                if (AiVoiceScrollView[hideView] != nullptr)
+                {
+                    container_->Remove(AiVoiceScrollView[hideView]);
+                    AiVoiceScrollView[hideView] = nullptr;
+                }
                 break;
             }
         }
@@ -802,6 +876,14 @@ namespace OHOS
         AiVoiceScrollView[hideView]->SetVisible(false);
         ClickFunc(showView);
         AiVoiceScrollView[showView]->SetVisible(true);
+        if (AiVoiceScrollView[showView] != nullptr)
+        {
+            AiVoiceScrollView[showView]->SetVisible(true);
+        }
+        else
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceScrollView[%d] is nullptr", showView);
+        }
         Draw();
         DestroyTempView(hideView);
         AiVoiceModel::GetInstance().SetCurView(showView);
index 0d224e6..e50d3a0 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-05-07 11:25:58
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-10-15 10:14:37
+ * @LastEditTime: 2024-10-28 11:12:52
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceThinkingView.cpp
  */
 #include "aivoice/include/AiVoicePresenter.h"
@@ -264,7 +264,7 @@ namespace OHOS
 
     UIScrollView *AivoiceThinkingView::CreateAivoiceThinkingView(void)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::CreateAivoiceThinkingView");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::CreateAivoiceThinkingView");
 #if 0
         if (scrollView == nullptr)
         {
@@ -316,6 +316,7 @@ namespace OHOS
             {
                 scrollView->Add(cancelThink);
             }
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::CreateAivoiceThinkingView success!!");
             return scrollView;
         }
         else