解决打断tts音频死机问题
authorluozheng <1732036298@qq.com>
Thu, 3 Jul 2025 08:46:26 +0000 (16:46 +0800)
committerluozheng <1732036298@qq.com>
Thu, 3 Jul 2025 08:46:26 +0000 (16:46 +0800)
优化tts音频播放,还需待优化

code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_ws.cpp
code/sdk/middleware/services/media/foundation/sample/wrapper/voice_call_volte_sample_wrapper.cpp

index 5d3af13..c28f2d1 100644 (file)
@@ -749,10 +749,6 @@ namespace OHOS
             if (slider)
             {
                 int value = slider->GetValue();
-                if (value >= 100 || value <= 0)
-                {
-                    return;
-                }
                 if (event.GetRotate() > 0)
                 {
                     value += 20;
@@ -769,6 +765,11 @@ namespace OHOS
                         value = 0;
                     }
                 }
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "volume:%d", value);
+                if (value >= 100 || value <= 0)
+                {
+                    return;
+                }
                 do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME, (void *)(&value), sizeof(value));
             }
         }
@@ -776,18 +777,18 @@ namespace OHOS
 
     bool AiVoicePresenter::OnRotate(UIView &view, const RotateEvent &event)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnRotateEnd");
-        ChangeVolume(view, event);
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnRotateEnd");
         return true;
     }
 
     bool AiVoicePresenter::OnRotateEnd(UIView &view, const RotateEvent &event)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnRotateEnd");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnRotateEnd");
         // if (view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)->IsVisible() == true)
         // {
         //     ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_VOLUME_VIEW);
         // }
+        ChangeVolume(view, event);
         return true;
     }
 }
\ No newline at end of file
index de29cd9..2013239 100644 (file)
@@ -438,7 +438,8 @@ namespace OHOS
             aiModelPicker->SetStyle(STYLE_BORDER_RADIUS, 150);
             aiModelPicker->SetItemHeight(40);
             aiModelPicker->SetLoopState(true);
-#ifndef AI_VOICE_JIUTIAN
+#if AI_VOICE_JIUTIAN
+#else
             aiModelPicker->SetRotateFactor(1.0);
             aiModelPicker->RequestFocus();
 #endif
@@ -1144,8 +1145,8 @@ namespace OHOS
         {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceScrollView[%d] is nullptr", showView);
         }
-        Draw();
         DestroyTempView(hideView);
+        Draw();
         AiVoiceModel::GetInstance().SetCurView(showView);
         return;
     }
index 318ac82..00dcfe2 100644 (file)
@@ -1739,7 +1739,7 @@ void uapi_start_tts_single(void)
     },\
     \"payload\": {\
         \"voice\":\"xiaoyun\",\
-        \"format\":\"pcm\",\
+        \"format\":\"mp3\",\
         \"sample_rate\":16000,\
         \"volume\":50,\
         \"speech_rate\":0,\
@@ -1860,7 +1860,7 @@ void bk_websocket_tts(void *data) {
 
         while (client_count)
         {
-            tts_client = init_websocket_client("ws://118.145.158.207:22080/tts/stream?audio_buffer_size=8192",NULL,0);
+            tts_client = init_websocket_client("ws://118.145.158.207:22080/tts/stream?audio_buffer_size=576",NULL,0);
 
             if (tts_client== NULL) 
             {
@@ -1889,7 +1889,7 @@ void bk_websocket_tts(void *data) {
 
 //    uapi_start_tts_single();
        
-        char* tts_recv_buf=(char *)malloc(1024*8);
+        char* tts_recv_buf=(char *)malloc(1024*4);
 
         set_ai_tts_server_init_flag(1);
 
@@ -1897,8 +1897,8 @@ void bk_websocket_tts(void *data) {
         {
             
             
-            memset_s(tts_recv_buf,1024*8,0,1024*8);
-            int len=receive_websocket_message(tts_client,(unsigned char *)tts_recv_buf,1024*8,&type);
+            memset_s(tts_recv_buf,1024*4,0,1024*4);
+            int len=receive_websocket_message(tts_client,(unsigned char *)tts_recv_buf,1024*4,&type);
             // if(type==WS_CONT || 
             if( type==WS_CLOSE || len==-1)//|| type==WS_CONT )
             {
index 730668c..3d58507 100755 (executable)
@@ -1159,7 +1159,7 @@ static int32_t RunVoiceCallVolteAI(VoiceCallVolteContext *context)
 
     // 16000 32000 44100 48000
     AudioRendererConfig  renderConfig = {};
-    renderConfig.audioFormat =  PCM;
+    renderConfig.audioFormat =  MP3;
     renderConfig.channelCount = 1;
     renderConfig.linkDir = AUDIO_DOWN_LINK;
     renderConfig.sampleRate = 16000;
@@ -1372,13 +1372,20 @@ void startAudioCaptureTask(void)
 
 
 
-int32_t AIStreamWrite(uint8_t *buf,uint32_t size)
+int32_t AIStreamWrite(uint8_t *buf, uint32_t size) 
 {
-    int32_t ret;
-
-    uint64_t writeLen = 0;
-    AudioRendererConfig renderConfig;
-    ret = g_stream_out_downink->StreamWrite(buf,size, writeLen, renderConfig);
+    int32_t ret = 0;
+    // 原有流写入逻辑
+    if (g_stream_out_downink) 
+    {
+        uint64_t writeLen = 0;
+        AudioRendererConfig renderConfig;
+        ret = g_stream_out_downink->StreamWrite(buf, size, writeLen, renderConfig);
+        LOS_Msleep(30);
+        if (ret < 0) {
+            MEDIA_ERR_LOG("StreamWrite failed");
+        }
+    }
 
     return ret;
 }