From e43d13b729a47fde7d26fd0bb0bab637802f8214 Mon Sep 17 00:00:00 2001 From: Bifang <915779419@qq.com> Date: Thu, 8 Oct 2026 15:00:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8D=95=E4=B8=AA=E6=B0=94?= =?UTF-8?q?=E6=B3=A1=E6=9C=80=E9=95=BF=E6=97=B6=E9=97=B4=E5=9B=BA=E5=AE=9A?= =?UTF-8?q?12=E7=A7=92=E7=A1=AC=E5=88=87=E5=AF=BC=E8=87=B4=E6=95=B4?= =?UTF-8?q?=E5=8F=A5=E8=A2=AB=E5=88=87=E6=96=AD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_web/index.html | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/test_web/index.html b/test_web/index.html index 85a86e4..3ef8be3 100644 --- a/test_web/index.html +++ b/test_web/index.html @@ -4101,8 +4101,44 @@ ${transcript} renderLiveTranscript(); } + function joinLiveTranscriptText(left, right) { + const first = String(left || ""); + const second = String(right || ""); + if (!first) return second; + if (!second) return first; + if (/\s$/.test(first) || /^\s/.test(second)) return `${first}${second}`; + + // Chinese text joins directly; retain a word boundary for adjacent English segments. + return /[A-Za-z0-9]$/.test(first) && /^[A-Za-z0-9]/.test(second) + ? `${first} ${second}` + : `${first}${second}`; + } + + function groupLiveTranscriptItems(items) { + const groups = []; + items.forEach((item) => { + const speakerKey = String(item.speakerKey || ""); + const canJoinPrevious = !item.partial && !item.speakerPending && speakerKey && groups.length > 0 + && !groups[groups.length - 1].partial + && !groups[groups.length - 1].speakerPending + && groups[groups.length - 1].speakerKey === speakerKey; + + if (!canJoinPrevious) { + groups.push({ ...item }); + return; + } + + // Segment cuts are transport/recognition boundaries, not bubble boundaries. + // Keep adjacent finalized segments from the same speaker together even across silence. + const previous = groups[groups.length - 1]; + previous.text = joinLiveTranscriptText(previous.text, item.text); + previous.endTimeMs = Math.max(Number(previous.endTimeMs || 0), Number(item.endTimeMs || 0)); + }); + return groups; + } + function renderLiveTranscript() { - const items = state.liveTranscript; + const items = groupLiveTranscriptItems(state.liveTranscript); if (!items.length) { $("liveTranscript").innerHTML = `