From c29ee51558bf62e6127e87fac913f8f94c474027 Mon Sep 17 00:00:00 2001 From: Xulilong Date: Wed, 15 Jul 2026 17:32:59 +0800 Subject: [PATCH] Wait for realtime ASR final result --- speakr/templates/index/src/asr/wsconnecter.js | 23 +++++++++++-------- speakr/templates/index/src/main.js | 4 ++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/speakr/templates/index/src/asr/wsconnecter.js b/speakr/templates/index/src/asr/wsconnecter.js index e9c6c7e..b5c4858 100644 --- a/speakr/templates/index/src/asr/wsconnecter.js +++ b/speakr/templates/index/src/asr/wsconnecter.js @@ -261,15 +261,20 @@ export function WebSocketConnectMethod(config) { stateHandle(1); } - function onMessage(e) { - msgHandle(e); - try { - const payload = JSON.parse(e.data); - if (payload && payload.type === "state" && payload.state === "closed") { - resolveGracefulStop(); - } - } catch (_) {} - } + function onMessage(e) { + msgHandle(e); + try { + const payload = JSON.parse(e.data); + if (payload && payload.type === "state" && payload.state === "closed") { + resolveGracefulStop(); + } else if ( + payload && + (payload.mode === "2pass-offline" || payload.mode === "offline-speaker") + ) { + resolveGracefulStop(); + } + } catch (_) {} + } function onError(e) { // info_div.innerHTML="连接"+e; diff --git a/speakr/templates/index/src/main.js b/speakr/templates/index/src/main.js index d37d597..1641592 100644 --- a/speakr/templates/index/src/main.js +++ b/speakr/templates/index/src/main.js @@ -628,7 +628,7 @@ document.addEventListener("DOMContentLoaded", async () => { return started ? 1 : 0; } - async function finishRealtimeAsrPipelines(timeoutMs = 3500) { + async function finishRealtimeAsrPipelines(timeoutMs = 20000) { const pipelines = getRealtimePipelines(); await Promise.allSettled(pipelines.map((pipeline) => pipeline.finish(timeoutMs))); syncRealtimeActiveState(); @@ -3094,7 +3094,7 @@ document.addEventListener("DOMContentLoaded", async () => { } } - await finishRealtimeAsrPipelines(3500); + await finishRealtimeAsrPipelines(20000); // Wait for MediaRecorder to emit the final blob. await new Promise(resolve => setTimeout(resolve, 500));