调整单个气泡最长时间固定12秒硬切导致整句被切断问题
parent
3af8f168f6
commit
e43d13b729
|
|
@ -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 = `<div class="empty-state">点击“开始实时会议”后,这里会像 demo 一样滚动显示气泡和实时变化。</div>`;
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in New Issue