From: luozheng <1732036298@qq.com> Date: Mon, 18 Aug 2025 11:40:26 +0000 (+0800) Subject: 4GAi tts文本发送优化,如果发送到协议栈失败,就会等待下次发送文本不裁剪 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=refs%2Fchanges%2F2098%2Fhead;p=mirrors%2FFD230.git 4GAi tts文本发送优化,如果发送到协议栈失败,就会等待下次发送文本不裁剪 --- 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 749b2b2b8..7142de8ee 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h @@ -123,7 +123,7 @@ namespace OHOS void start_ai4g_connect_timer(uint32_t interval = 1000); void stop_ai4g_connect_timer(void); - void start_ai4g_tts_play_timer(uint32_t interval = 600); + void start_ai4g_tts_play_timer(uint32_t interval = 800); void stop_ai4g_tts_play_timer(void); void start_update_ai_answer_timer(uint32_t interval = 300); 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 30f7a0b8d..49750f3ad 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp @@ -737,11 +737,18 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "强制发送文本: %s (长度: %zu)", segment.c_str(), segment.length()); - uapi_start_tts_single_txt((char *)segment.c_str()); - // LOS_Msleep(100); - - // 发送后清空累积文本 - accumulatedText.clear(); + bool sendret = uapi_start_tts_single_txt((char *)segment.c_str()); + // 如果为true发送成功,如果发送失败等待下次发送不清空文本 + if (sendret) + { + // 发送后清空累积文本 + accumulatedText.clear(); + } + else + { + // 发送失败,等待下次发送 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败,等待下次发送"); + } } else { @@ -767,22 +774,30 @@ namespace OHOS segment.end()); // 发送到TTS播放 + bool ret = false; if (!segment.empty()) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "按标点发送分段: %s (长度: %zu)", segment.c_str(), segment.length()); - uapi_start_tts_single_txt((char *)segment.c_str()); - // LOS_Msleep(100); + ret = uapi_start_tts_single_txt((char *)segment.c_str()); } - // 更新累积文本 - if (pos + 1 < text.length()) + if (ret) { - accumulatedText = text.substr(pos + 1); + // 更新累积文本 + if (pos + 1 < text.length()) + { + accumulatedText = text.substr(pos + 1); + } + else + { + accumulatedText.clear(); + } } else { - accumulatedText.clear(); + // 发送失败,等待下次发送 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败,等待下次发送"); } } @@ -937,7 +952,7 @@ namespace OHOS { // uapi_stop_asr(); // stop_AudioCaptureProcess_AI(); - uapi_UI_stop_asr(); + // uapi_UI_stop_asr(); } else if (GetSelect4gorbt() == AI_SELECT_BT) { @@ -1242,6 +1257,7 @@ namespace OHOS AiVoicePresenter *p_AiVoicePresenter = AiVoicePresenter::GetInstance(); if (AiVoicePresenter::GetInstance() && AivoiceListeningView::GetInstance()) { + uapi_UI_stop_asr(); AiVoicePresenter::GetInstance()->ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID); // 切换到思考中界面 } } @@ -1530,7 +1546,7 @@ namespace OHOS // 添加一个静态变量用于跟踪连续出现0的次数 static int s_tts_tick_zero_count = 0; static int continue_zero_count = 0; // 静态变量:记录连续为0的次数(初始化为0) - static int fouce_count = 0; // + static int fouce_count = 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()); @@ -1588,7 +1604,7 @@ namespace OHOS { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "get_bk_websocket_tts_tick:%d(不满足发送条件)", get_bk_websocket_tts_tick()); fouce_count++; - if(fouce_count >= 20) + if (fouce_count >= 20) { if (!get_ai_osal_msg_queue_is_full()) {