From b6bf60ca1c2542ffbbad30fb76d7cbb9b090de19 Mon Sep 17 00:00:00 2001 From: Bifang <915779419@qq.com> Date: Sat, 10 Oct 2026 13:39:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=9C=AC=E5=9C=B0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E9=A1=B5=E7=9A=84=E5=90=88=E5=B9=B6=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=9A=E5=89=8D=E7=BC=80=E7=BB=A7=E7=BB=AD=E5=A2=9E=E9=95=BF?= =?UTF-8?q?=E6=97=B6=E6=8E=A5=E4=B8=8A=E6=96=B0=E5=86=85=E5=AE=B9=EF=BC=9B?= =?UTF-8?q?=E5=BF=AB=E7=85=A7=E6=BB=9A=E5=8A=A8=E6=97=B6=E6=8C=89=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E9=87=8D=E5=8F=A0=E6=9B=B4=E6=96=B0=E5=B0=BE=E9=83=A8?= =?UTF-8?q?=EF=BC=9B=E5=AE=9A=E7=A8=BF=E5=88=B0=E8=BE=BE=E5=90=8E=E4=BB=8D?= =?UTF-8?q?=E7=94=A8=E5=AE=9A=E7=A8=BF=E6=9B=BF=E6=8D=A2=E4=B8=B4=E6=97=B6?= =?UTF-8?q?=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_web/index.html | 60 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/test_web/index.html b/test_web/index.html index 0d57715..f0b9b96 100644 --- a/test_web/index.html +++ b/test_web/index.html @@ -4160,6 +4160,59 @@ ${transcript} return groups; } + function getLivePartialMatchView(text) { + const source = String(text || ""); + let normalized = ""; + const sourceOffsets = []; + + // Ignore punctuation while matching snapshots because partial ASR often revises it. + for (let offset = 0; offset < source.length;) { + const character = String.fromCodePoint(source.codePointAt(offset)); + if (!/[\s\p{P}\p{S}]/u.test(character)) { + normalized += character; + sourceOffsets.push(offset); + } + offset += character.length; + } + + return { normalized, sourceOffsets }; + } + + function mergeLivePartialSnapshot(currentText, nextText) { + const current = String(currentText || "").trim(); + const next = String(nextText || "").trim(); + if (!current) return next; + if (!next) return current; + + const currentView = getLivePartialMatchView(current); + const nextView = getLivePartialMatchView(next); + const currentNormalized = currentView.normalized; + const nextNormalized = nextView.normalized; + if (!currentNormalized || !nextNormalized) return next.startsWith(current) ? next : current; + + // FunASR's online model emits new chunks that its client appends. Qwen sends + // revisable rolling snapshots, so accept growth directly and merge their tail overlap. + if (nextNormalized.startsWith(currentNormalized)) return next; + if (currentNormalized.startsWith(nextNormalized)) return current; + + const maxOverlap = Math.min(currentNormalized.length, nextNormalized.length, 128); + for (let overlapLength = maxOverlap; overlapLength >= 2; overlapLength -= 1) { + const overlap = currentNormalized.slice(-overlapLength); + const nextMatchIndex = nextNormalized.lastIndexOf(overlap); + if (nextMatchIndex < 0) continue; + + const currentMatchIndex = currentNormalized.length - overlapLength; + const currentTextOffset = currentView.sourceOffsets[currentMatchIndex]; + const nextTextOffset = nextView.sourceOffsets[nextMatchIndex]; + return `${current.slice(0, currentTextOffset)}${next.slice(nextTextOffset)}`; + } + + // Without a textual overlap there is no safe way to distinguish new text from a rewrite. + // Keep the short startup hypothesis replaceable until the model has produced context. + if (currentNormalized.length <= 16) return next; + return current; + } + function renderLiveTranscript() { const items = groupLiveTranscriptItems(state.liveTranscript); if (!items.length) { @@ -4283,12 +4336,7 @@ ${transcript} if (existingPartialIndex >= 0) { const existingPartial = state.liveTranscript[existingPartialIndex]; existingPartial.label = label; - // The server sends a full, revisable partial snapshot. Only expose its - // newly appended suffix while streaming; keep the visible draft intact - // on rollback/revision, then let the final sentence replace it below. - if (safeText.startsWith(existingPartial.text)) { - existingPartial.text = safeText; - } + existingPartial.text = mergeLivePartialSnapshot(existingPartial.text, safeText); existingPartial.speaker = speaker; existingPartial.speakerPending = speakerPending; existingPartial.segmentIndex = segmentIndex;