From 1c4d644dd7f804201c8fbf01dbd023fc8c7ff564 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Fri, 12 Jul 2024 11:33:53 +0800 Subject: [PATCH] =?utf8?q?Ai=E8=AF=AD=E9=9F=B3=E4=BF=AE=E6=94=B9=EF=BC=8C?= =?utf8?q?=E8=BF=9E=E6=8E=A5=E8=B6=85=E6=97=B6=E6=B7=BB=E5=8A=A0=E5=8F=B3?= =?utf8?q?=E6=BB=91=E9=80=80=E5=87=BA=E5=88=B0=E4=B8=80=E7=BA=A7=E7=95=8C?= =?utf8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/aivoice/include/AiVoiceModel.h | 24 ++++++++++++------- .../nativeui/aivoice/src/AiVoiceModel.cpp | 6 ++++- .../nativeui/aivoice/src/AiVoicePresenter.cpp | 9 +++++-- .../aivoice/src/AivoiceConnectTimeoutView.cpp | 17 +++++++++---- .../src/AivoiceReturnResultTextView.cpp | 9 ++++--- 5 files changed, 46 insertions(+), 19 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h index 724b7356c..839e5e256 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h @@ -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}; // 进入返回结果界面的标志 }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp index 711ffe43b..6e9e881a1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp @@ -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; diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp index ff12fa1fb..a726b03bc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp @@ -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; diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp index d014caa81..04c591901 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp @@ -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 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(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]; diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp index ed940e5f8..f6831e997 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp @@ -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) -- 2.17.1