xfyun asr update one bubble

This commit is contained in:
Xin Wang
2026-05-21 17:05:20 +08:00
parent b09ca18cb9
commit 6a59df3dbd
3 changed files with 29 additions and 3 deletions

View File

@@ -538,9 +538,14 @@ function handleUserTranscript(text) {
body.textContent = text;
state.currentUserBubble.classList.remove("bubble--interim");
} else {
addBubble("user", text);
state.currentUserBubble = addBubble("user", text);
}
state.currentUserBubble = null;
// Intentionally keep `state.currentUserBubble` set. Streaming ASRs (e.g.
// xfyun) can emit multiple interim/final cycles within a single dialog
// turn — for example when the user pauses mid-sentence or the upstream
// service segments the utterance. Keeping the bubble open until the
// assistant starts replying (see `handleAssistantStarted` /
// `response.audio.started`) collapses those cycles into one bubble.
}
function handleUserTranscriptInterim(text) {
@@ -590,6 +595,11 @@ function handleAssistantDelta(text) {
function handleAssistantStarted() {
state.currentAssistantBubble = null;
// Close the in-flight user bubble so the next user turn starts a fresh
// one. We do this here (and on `response.audio.started`) rather than on
// every `input.transcript.final`, because streaming ASRs may emit
// several finals within a single dialog turn.
state.currentUserBubble = null;
}
function handleAssistantFinal(text, interrupted) {
@@ -633,6 +643,7 @@ function handleEvent(event) {
break;
case "response.audio.started":
setBotIndicator(true);
state.currentUserBubble = null;
break;
case "response.audio.stopped":
finalizeAssistantBubble();