From ac136d980ff07e0f3e73ce1015633552b3329a9b Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Mon, 25 Aug 2025 10:28:25 +0800 Subject: [PATCH] =?utf8?q?4Gai=E6=96=87=E6=9C=AC=E5=8F=91=E9=80=81?= =?utf8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=201.uapi=5Fstart=5Ftts=E6=B7=BB?= =?utf8?q?=E5=8A=A0=E8=BF=94=E5=9B=9E=E5=80=BC=202.=E5=A6=82=E6=9E=9Ctts?= =?utf8?q?=E8=AF=AD=E9=9F=B3=E7=AA=81=E7=84=B6=E4=B8=8D=E6=92=AD=E6=94=BE?= =?utf8?q?=EF=BC=8C=E4=BC=9A=E5=8F=91=E9=80=81uapi=5Fstart=5Ftts=E8=AE=A9?= =?utf8?q?=E5=85=B6=E6=81=A2=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/aivoice/include/AiVoiceModel.h | 3 +- .../nativeui/aivoice/src/AiVoiceModel.cpp | 77 +++++-------------- .../slip/cat1Service/cat1_ai_server.cpp | 5 +- .../slip/cat1Service/cat1_at_cmd.cpp | 2 +- .../peripheral/slip/cat1Service/cat1_ws.h | 2 +- 5 files changed, 27 insertions(+), 62 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 e8591aa35..33c74ecf8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h @@ -129,7 +129,7 @@ namespace OHOS void start_update_ai_answer_timer(uint32_t interval = 300); void stop_update_ai_answer_timer(void); - void start_uapi_stop_tts_timer(uint32_t interval = 1500); + void start_uapi_stop_tts_timer(uint32_t interval = 2000); void stop_uapi_stop_tts_timer(void); void SetSelectAiModel(int index); @@ -206,6 +206,7 @@ namespace OHOS bool is_delay_start_asr{false}; bool isFirstReceive{true}; //静态变量标记是否是首次接收 + bool hasTtsStartSucceeded{false}; // uapi_start_tts 成功后置位,仅允许发送一次 }; } 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 0393e1ebd..1de568269 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp @@ -751,11 +751,15 @@ namespace OHOS // 发送失败,等待下次发送 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败,等待下次发送,fouce_count:%d",fouce_count); fouce_count++; - if (fouce_count >= 3) + if (fouce_count >= 3 && !hasTtsStartSucceeded) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败准备发送:uapi_start_tts"); - uapi_start_tts(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败准备发送:uapi_start_tts有且只发一次"); + bool startOk = uapi_start_tts(); fouce_count = 0; + if (startOk) + { + hasTtsStartSucceeded = true; + } } } } @@ -809,11 +813,15 @@ namespace OHOS // 发送失败,等待下次发送 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败,等待下次发送,fouce_count:%d",fouce_count); fouce_count++; - if (fouce_count >= 3) + if (fouce_count >= 3 && !hasTtsStartSucceeded) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败准备发送:uapi_start_tts"); - uapi_start_tts(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败准备发送:uapi_start_tts有且只发一次"); + bool startOk = uapi_start_tts(); fouce_count = 0; + if (startOk) + { + hasTtsStartSucceeded = true; + } } } } @@ -1557,7 +1565,6 @@ 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 void AI4G_IS_START_TTS_CallbackProc(int data) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AI4G_IS_START_TTS_CallbackProc:%s", AiVoiceModel::GetInstance().GetAccumulatedText().c_str()); @@ -1577,6 +1584,7 @@ namespace OHOS // 无文本时停止定时器 if (AiVoiceModel::GetInstance().GetAccumulatedText().empty()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "没有文本了准备发送:stop_ai4g_tts_play_timer"); AiVoiceModel::GetInstance().stop_ai4g_tts_play_timer(); return; } @@ -1585,53 +1593,6 @@ namespace OHOS { AiVoiceModel::GetInstance().ProcessTextByPunctuation(); } - -#if 0 - // 当前回调中get_bk_websocket_tts_tick()是否为0 - bool current_tick_zero = (get_bk_websocket_tts_tick() == 0); - - // 更新连续为0的次数 - if (current_tick_zero) - { - continue_zero_count++; // 本次为0,计数+1 - } - else - { - continue_zero_count = 0; // 本次不为0,计数重置为0 - } - - // 核心逻辑:连续0中,奇数次(1、3、5...)发送,偶数次(2、4、6...)跳过 - if (current_tick_zero) - { - if (continue_zero_count % 2 == 1) // 奇数次(第1、3、5...次):发送 - { - if (!get_ai_osal_msg_queue_is_full()) - { - AiVoiceModel::GetInstance().ProcessTextByPunctuation(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送TTS文本(连续第%d次为0,奇数次)", continue_zero_count); - fouce_count = 0; - } - } - else // 偶数次(第2、4、6...次):跳过 - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "连续第%d次为0,偶数次,本次不发送", continue_zero_count); - } - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "get_bk_websocket_tts_tick:%d(不满足发送条件)", get_bk_websocket_tts_tick()); - fouce_count++; - if (fouce_count >= 20) - { - if (!get_ai_osal_msg_queue_is_full()) - { - AiVoiceModel::GetInstance().ProcessTextByPunctuation(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "强行发送fouce_count:%d", fouce_count); - fouce_count = 0; - } - } - } -#endif return; } @@ -1693,7 +1654,6 @@ 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; // 重置静态变量 fouce_count = 0; start_uapi_stop_tts_timer(); @@ -1835,8 +1795,11 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); } g_uapi_stop_tts_Handle = nullptr; - uapi_stop_tts(); - // uapi_UI_start_asr(1); + if (g_ai4g_is_start_tts_play_Handle == nullptr) + { + hasTtsStartSucceeded = false; + uapi_stop_tts(); + } } } diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ai_server.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ai_server.cpp index 95ea08763..bc31cc2c5 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ai_server.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ai_server.cpp @@ -1837,7 +1837,7 @@ bool tts_ws_url_init(char * put_buf) char tts_task_id_buf[128]={0}; uint8_t tts_is_ready=0; -void uapi_start_tts(void) +bool uapi_start_tts(void) { char *jsonString = "{\"header\": \ @@ -1859,8 +1859,9 @@ void uapi_start_tts(void) memset_s(tts_task_id_buf,128,0,128); tts_is_ready=0; WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"send_websocket_message succ 0\n"); + return true; } - + return false; } diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp index 1423e58b8..ccc1077bd 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp @@ -504,7 +504,7 @@ static uint32_t start_record(uint8_t *para, uint32_t paraLen, char *strCommonCmd return 0; } -extern void uapi_start_tts(void) ; +extern bool uapi_start_tts(void) ; static uint32_t starttts(uint8_t *para, uint32_t paraLen, char *strCommonCmd) { UNUSED(strCommonCmd); diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h index cf2cb8095..170296965 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.h @@ -14,7 +14,7 @@ void uapi_UI_start_asr(uint8_t type); void uapi_UI_stop_asr(void); -void uapi_start_tts(void); +bool uapi_start_tts(void); void uapi_stop_tts(void); -- 2.17.1