function speakerDisplayName(speakerLabel) {
if (!speakerLabel || speakerLabel === "PENDING") {
- return "Speaker \u2026"; // "Speaker …" while diarization is still resolving
+ return "Speaker \u2026";
}
return `Speaker ${speakerLabel}`;
}
const speakerName = speakerDisplayName(turn.speakerLabel);
- // Start a new visual group whenever the speaker changes, so consecutive
- // turns from the same speaker stay together instead of re-labeling each one.
if (speakerName !== lastSpeakerName) {
currentGroupEl = document.createElement("div");
currentGroupEl.className = "transcript-turn";
}
}
-// Handles the live "Turn" events. speaker_label starts as "PENDING" and may
-// resolve to a real label (e.g. "A") once diarization has enough context.
-// The same turn_order is sent repeatedly with growing transcript text until
-// end_of_turn is true.
function handleTurnEvent(payload) {
if (typeof payload.turn_order !== "number") {
return;
renderTranscription();
}
-// Handles "SpeakerRevision" events, which retroactively correct the speaker
-// label for one or more already-seen turns (identified by turn_order).
-// This is what lets us fix a turn that was rendered as "PENDING" or
-// mis-attributed once the diarization model is more confident.
function handleSpeakerRevisionEvent(payload) {
const revisions = Array.isArray(payload.revisions) ? payload.revisions : [];
if (revisions.length === 0) {