From 5293910d6e549e729003c57a66eb005a0c4a6145 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Fri, 15 Aug 2025 15:42:34 +0800 Subject: [PATCH] =?utf8?q?=E8=A7=A3=E5=86=B34GAi=E8=B1=86=E5=8C=85ai?= =?utf8?q?=E5=BC=80=E5=A4=B4=E4=BC=9A=E5=8F=91=E2=80=9C\n\n=E2=80=9D?= =?utf8?q?=E9=80=A0=E6=88=90=E7=AD=94=E6=A1=88=E5=BC=80=E5=A4=B4=E5=87=BA?= =?utf8?q?=E7=8E=B0=E7=A9=BA=E7=99=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/aivoice/include/AiVoiceModel.h | 5 +++ .../nativeui/aivoice/src/AiVoiceModel.cpp | 35 +++++++++++++++++-- 2 files changed, 37 insertions(+), 3 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 4b3a568af..749b2b2b8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h @@ -163,6 +163,10 @@ namespace OHOS bool getentryTextViewState(void); + bool get_is_first_receive(); + void set_is_first_receive(bool); + void delete_start_line_break_str(std::string &str); + private: AiVoiceModel(); ~AiVoiceModel(); @@ -198,6 +202,7 @@ namespace OHOS uint8_t select4gorbt{-1}; //0:4g 1:蓝牙 -1:未连接 bool is_delay_start_asr{false}; + bool isFirstReceive{true}; //静态变量标记是否是首次接收 }; } 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 e45606de2..65195626d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp @@ -800,6 +800,7 @@ namespace OHOS { if (!OHOS::AiVoiceModel::GetInstance().GetIsLimitDisplayed()) // 如果ai答案没有显示到极限了,就更新ai答案字符串 { + delete_start_line_break_str(str); aiAnswerStr += str; /* -------------------------------------------------------------------------- */ // 累积接收到的文本 @@ -858,6 +859,7 @@ namespace OHOS userQuestionStr = ""; aiAnswerStr = ""; accumulatedText = ""; + set_is_first_receive(true); } /*获取AI音频路径*/ @@ -1527,7 +1529,7 @@ namespace OHOS static uint8_t tts_record_flag = 0; // 添加一个静态变量用于跟踪连续出现0的次数 static int s_tts_tick_zero_count = 0; - static int continue_zero_count = 0; // 静态变量:记录连续为0的次数(初始化为0) + static int continue_zero_count = 0; // 静态变量:记录连续为0的次数(初始化为0) static void AI4G_IS_START_TTS_CallbackProc(int data) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AI4G_IS_START_TTS_CallbackProc:%s", AiVoiceModel::GetInstance().GetAccumulatedText().c_str()); @@ -1644,8 +1646,8 @@ namespace OHOS } g_ai4g_is_start_tts_play_Handle = nullptr; AI4G_IS_START_TTS_PLAY_CNT = NUMBER_TEN; - s_tts_tick_zero_count = 0; // 重置计数器 - continue_zero_count = 0; // 重置静态变量 + s_tts_tick_zero_count = 0; // 重置计数器 + continue_zero_count = 0; // 重置静态变量 } } @@ -1819,6 +1821,33 @@ namespace OHOS return entryTextViewState; } + bool AiVoiceModel::get_is_first_receive() + { + return isFirstReceive; + } + + void AiVoiceModel::set_is_first_receive(bool val) + { + isFirstReceive = val; + } + + void AiVoiceModel::delete_start_line_break_str(std::string &str) + { + if (GetSelect4gorbt() == AI_SELECT_4G && GetAiModelTextId() == STR_AIMODELS_DOUBAO) + { + if (isFirstReceive) + { + isFirstReceive = false; + // 检查是否以"\n\n"开头 + if (str.size() >= 2 && str[0] == '\n' && str[1] == '\n') + { + // 去除开头的两个换行符 + str = str.substr(2); + } + } + } + } + /*获取已选择的ai模型的textid*/ int AiVoiceModel::GetAiModelTextId() { -- 2.17.1