优化tts播放定时器处理,如果tts突然断连,就停止定时器,避免一直回调 2048/1 2048/head 2050/target/1 2051/target/1
authorluozheng <1732036298@qq.com>
Wed, 6 Aug 2025 03:53:09 +0000 (11:53 +0800)
committerluozheng <1732036298@qq.com>
Wed, 6 Aug 2025 03:53:09 +0000 (11:53 +0800)
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp

index 3f811e4..c70e520 100644 (file)
@@ -1627,6 +1627,13 @@ namespace OHOS
     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;
+        }
         // 用来判断是否需要停止发送文本
         if (AiVoiceModel::GetInstance().GetAccumulatedText().empty())
         {
@@ -1635,7 +1642,7 @@ namespace OHOS
         }
         if (get_bk_websocket_tts_tick() == 0) // 代表可以发录音文本
         {
-            if (AiVoiceModel::GetInstance().GetInit_4gai_task() && !get_ai_osal_msg_queue_is_full())
+            if (!get_ai_osal_msg_queue_is_full())
             {
                 AiVoiceModel::GetInstance().ProcessTextByPunctuation();
             }