From: luozheng <1732036298@qq.com> Date: Wed, 6 Aug 2025 06:58:31 +0000 (+0800) Subject: tts发送文本添加重试机制,超过10次停止定时器,目前tts服务会出现发第一次文本时候tts断开导致不会播放第一次发送的文本问题 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=refs%2Fchanges%2F2050%2F1;p=mirrors%2FFD230.git tts发送文本添加重试机制,超过10次停止定时器,目前tts服务会出现发第一次文本时候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 c70e520dc..792781ad2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp @@ -1624,15 +1624,23 @@ namespace OHOS static constexpr const int8_t NUMBER_TEN = 15; static int8_t AI4G_IS_START_TTS_PLAY_CNT = NUMBER_TEN; static uint8_t tts_record_flag = 0; + // 添加一个静态变量用于跟踪连续出现0的次数 + static int s_tts_tick_zero_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()); AiVoiceModel::GetInstance().GetInit_4gai_task();//获取4gai服务状态 if (get_ai_tts_server_init_flag() == 0) //tts服务如果断开了,就停止定时器 { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tts_server disconnect..."); - AiVoiceModel::GetInstance().stop_ai4g_tts_play_timer(); - return; + s_tts_tick_zero_count++; // 增加连续0的次数 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "s_tts_tick_zero_count count: %d", s_tts_tick_zero_count); + if (s_tts_tick_zero_count >= 10) // 如果连续出现10次0,就停止定时器 + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tts_server disconnect..."); + AiVoiceModel::GetInstance().stop_ai4g_tts_play_timer(); + return; + } } // 用来判断是否需要停止发送文本 if (AiVoiceModel::GetInstance().GetAccumulatedText().empty()) @@ -1717,6 +1725,7 @@ namespace OHOS } g_ai4g_is_start_tts_play_Handle = nullptr; AI4G_IS_START_TTS_PLAY_CNT = NUMBER_TEN; + s_tts_tick_zero_count = 0; // 重置计数器 #if TTS_TEST tts_record_flag = 0; std::string filePath = "/user/aiRecord456.mp3";