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 = `
点击“开始实时会议”后,这里会像 demo 一样滚动显示气泡和实时变化。
`; return;