Ai语音修改,连接超时添加右滑退出到一级界面 512/1
authorluozheng <1732036298@qq.com>
Fri, 12 Jul 2024 03:33:53 +0000 (11:33 +0800)
committerluozheng <1732036298@qq.com>
Fri, 12 Jul 2024 03:33:53 +0000 (11:33 +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/application/wearable/fd230app/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp

index 724b735..839e5e2 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 15:14:43
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-11 14:35:27
+ * @LastEditTime: 2024-07-12 11:00:22
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h
  */
 #ifndef AI_VOICE_MODEL_H
@@ -13,6 +13,8 @@
 #include "iostream"
 #include "string"
 #include "ChatContentItem.h"
+
+#define IS_AIAUDIO_TYPE_PCM 1 /*AI录音文件是否是pcm格式*/
 namespace OHOS
 {
 
@@ -71,15 +73,19 @@ namespace OHOS
         AiVoiceModel(const AiVoiceModel &) = delete;
         AiVoiceModel &operator=(const AiVoiceModel &) = delete;
 
-        // 私有成员变量
+// 私有成员变量
+#if IS_AIAUDIO_TYPE_PCM
         std::string AIAIAudioPath = "/user/userdata/AiRecording/AIAudio.pcm"; // AI录音的文件路径
-        std::string userQuestionStr;                                          // 用户提出的问题
-        std::string aiAnswerStr;                                              // AI回答的问题
-        bool entryTimeoutFlag{false};                                         // 进入超时界面标志
-        uint8_t ChatContentListCount{0};                                      // 列表数量
-        static const uint16_t MaxChatContentListCount = 2;                    // 对话列表最大数量
-        ChatContentItem chatTtems[MaxChatContentListCount] = {0, "", false};  // 对话项数组
-        bool entryTextViewState{false};                                       // 进入返回结果界面的标志 
+#else
+        std::string AIAIAudioPath = "/user/userdata/AiRecording/AIAudio.sbc"; // AI录音的文件路径
+#endif
+        std::string userQuestionStr;                                         // 用户提出的问题
+        std::string aiAnswerStr;                                             // AI回答的问题
+        bool entryTimeoutFlag{false};                                        // 进入超时界面标志
+        uint8_t ChatContentListCount{0};                                     // 列表数量
+        static const uint16_t MaxChatContentListCount = 2;                   // 对话列表最大数量
+        ChatContentItem chatTtems[MaxChatContentListCount] = {0, "", false}; // 对话项数组
+        bool entryTextViewState{false};                                      // 进入返回结果界面的标志
     };
 
 }
index 711ffe4..6e9e881 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-07-11 14:36:14
+ * @LastEditTime: 2024-07-12 10:59:18
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
  */
 #include "aivoice/include/AiVoiceModel.h"
@@ -412,7 +412,11 @@ namespace OHOS
             {
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_delete_files fail!!");
             }
+#if IS_AIAUDIO_TYPE_PCM
             const char *defaultArgs[6] = {"01", "pcm", "16000", "1", "16", audioPath.c_str()};
+#else
+            const char *defaultArgs[6] = {"01", "sbc", "16000", "1", "16", audioPath.c_str()};
+#endif
             AudioCaptureSample(6, (const char **)defaultArgs);
         }
         return;
index ff12fa1..a726b03 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 15:11:17
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-09 18:27:33
+ * @LastEditTime: 2024-07-12 10:49:59
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
  */
 #include "AppViewIDs.h"
@@ -224,7 +224,7 @@ namespace OHOS
             if (showView == AIVOICE_THINKING_VIEWID) // 聆听中->思考中界面
             {
                 // osal_msleep(500);
-                //model->CheckFileAndSendAIIsReady();
+                // model->CheckFileAndSendAIIsReady();
                 model->AIVoice_StartTimer();
             }
             else if (showView == AIVOICE_STARTCHAT_VIEWID) // 聆听中->开始对话界面:(右滑不想录音了)
@@ -374,6 +374,11 @@ namespace OHOS
                 // view_->ChangeView(AIVOICE_THINKING_VIEWID, AIVOICE_STARTCHAT_VIEWID); // 思考中->开始对话界面
                 ChangeViewAndLogicOperator(AIVOICE_THINKING_VIEWID, AIVOICE_STARTCHAT_VIEWID);
             }
+            else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_CONNECT_TIMEOUT_VIEWID))
+            {
+                // view_->ChangeView(AIVOICE_THINKING_VIEWID, AIVOICE_STARTCHAT_VIEWID); // 连接超时->开始对话界面
+                ChangeViewAndLogicOperator(AIVOICE_CONNECT_TIMEOUT_VIEWID, AIVOICE_STARTCHAT_VIEWID);
+            }
             AiVoicePresenter::X_DRAG_FLAG = false;
         }
         return true;
index d014caa..04c5919 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-07-03 09:34:11
+ * @LastEditTime: 2024-07-12 11:18:00
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceConnectTimeoutView.cpp
  */
 #include "aivoice/include/AiVoicePresenter.h"
@@ -12,6 +12,7 @@
 #include <UiConfig.h>
 namespace OHOS
 {
+    static constexpr const int16_t LABEL_ROLL_SPEED = 70;
 
     static AivoiceConnectTimeoutView *g_pAivoiceConnectTimeoutView{nullptr};
 
@@ -57,7 +58,7 @@ namespace OHOS
                 if (label[i] != nullptr)
                 {
                     delete label[i];
-                    label[i];
+                    label[i] = nullptr;
                 }
             }
 
@@ -92,6 +93,7 @@ namespace OHOS
         label->SetLineBreakMode(labelconfig.lineBreakMode);
         label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
         label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize);
+        label->SetRollSpeed(LABEL_ROLL_SPEED);
         return label;
     }
 
@@ -131,6 +133,13 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::scrollView new fail!");
             return false;
         }
+        UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(AiVoicePresenter::GetInstance());
+        if (dragListener == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::dragListener new fail!");
+            return false;
+        }
+        scrollView->SetOnDragListener(dragListener);
         scrollView->SetPosition(0, 0, 466, 466);
         scrollView->SetTouchable(true);
         scrollView->SetDraggable(true);
@@ -149,7 +158,7 @@ namespace OHOS
             .fontSize = 30,
             .lineHeigh = 35,
             .textId = STR_AI_INTELLIGENT_ASSISTANT,
-            .lineBreakMode = UILabel::LINE_BREAK_MARQUEE,
+            .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION,
         };
         title = AivoiceConnectTimeoutLabelInit(labelconfig);
         if (title == nullptr)
@@ -161,7 +170,7 @@ namespace OHOS
         labelconfig.left = 53;
         labelconfig.width = 360;
         int textId[] = {STR_CONNECT_TIMEOUT, STR_PLEASE_RESTART_CHAT};
-        for (int i = 0; i < sizeof(textId) / sizeof(textId[0]); i++)
+        for (int i = 0; i < 2; i++)
         {
             labelconfig.top = 222 + i * labelconfig.height;
             labelconfig.textId = textId[i];
index ed940e5..f6831e9 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-07-05 20:24:47
+ * @LastEditTime: 2024-07-12 11:14:36
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceReturnResultTextView.cpp
  */
 #include "aivoice/include/AiVoicePresenter.h"
@@ -46,6 +46,8 @@ namespace OHOS
 
     static constexpr const int16_t ONE_HALF_NUM = 2;
 
+    static constexpr const int16_t LABEL_ROLL_SPEED = 70;
+
     static AivoiceReturnResultTextView *g_pAivoiceReturnResultTextView{nullptr};
 
     AivoiceReturnResultTextView::AivoiceReturnResultTextView()
@@ -128,6 +130,7 @@ namespace OHOS
         label->SetLineBreakMode(labelconfig.lineBreakMode);
         label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
         label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize);
+        label->SetRollSpeed(LABEL_ROLL_SPEED);
         return label;
     }
 
@@ -187,7 +190,7 @@ namespace OHOS
             .fontSize = 30,
             .lineHeight = 35,
             .textId = STR_AI_INTELLIGENT_ASSISTANT,
-            .lineBreakMode = UILabel::LINE_BREAK_MARQUEE,
+            .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION,
         };
         title = AivoiceReturnResultTextLabelInit(labelconfig);
         if (title == nullptr)
@@ -204,7 +207,7 @@ namespace OHOS
             .fontSize = 30,
             .lineHeight = 35,
             .textId = STR_CONTINUE_CHAT,
-            .lineBreakMode = UILabel::LINE_BREAK_MARQUEE,
+            .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION,
         };
         continueChat = AivoiceReturnResultTextLabelInit(labelconfig);
         if (continueChat == nullptr)