From 0d82acc0d26d9ebdc07d2ba052285565ae5ba0d4 Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Fri, 22 May 2026 09:40:16 +0800 Subject: [PATCH] Remove xfyun asr interim in frontend --- examples/webpage/app.js | 38 ++----------------------------------- examples/webpage/styles.css | 4 ---- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/examples/webpage/app.js b/examples/webpage/app.js index 4b0fcc0..1fba1e1 100644 --- a/examples/webpage/app.js +++ b/examples/webpage/app.js @@ -60,7 +60,6 @@ const state = { botUiTimer: null, // Chat state. - currentUserBubble: null, currentAssistantBubble: null, // VU meter smoothing. @@ -152,7 +151,6 @@ function scrollChatToBottom() { function clearChat() { els.chatLog.innerHTML = ""; - state.currentUserBubble = null; state.currentAssistantBubble = null; const empty = document.createElement("div"); empty.className = "chat__empty"; @@ -533,32 +531,7 @@ function resetPlaybackClock() { function handleUserTranscript(text) { if (!text) return; state.currentAssistantBubble = null; - if (state.currentUserBubble) { - const body = state.currentUserBubble.querySelector(".bubble__text"); - body.textContent = text; - state.currentUserBubble.classList.remove("bubble--interim"); - } else { - state.currentUserBubble = addBubble("user", text); - } - // 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) { - if (!text) return; - state.currentAssistantBubble = null; - if (!state.currentUserBubble) { - state.currentUserBubble = addBubble("user", text); - state.currentUserBubble.classList.add("bubble--interim"); - } else { - const body = state.currentUserBubble.querySelector(".bubble__text"); - body.textContent = text; - } - scrollChatToBottom(); + addBubble("user", text); } function sendText(text) { @@ -580,7 +553,6 @@ function sendText(text) { // reply will be created when `response.text.started` arrives. wsSend(JSON.stringify(message)); stopPlaybackQueue(); - state.currentUserBubble = null; addBubble("user", value); return true; } @@ -595,11 +567,6 @@ 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) { @@ -643,7 +610,6 @@ function handleEvent(event) { break; case "response.audio.started": setBotIndicator(true); - state.currentUserBubble = null; break; case "response.audio.stopped": finalizeAssistantBubble(); @@ -662,7 +628,7 @@ function handleEvent(event) { handleUserTranscript(event.text); break; case "input.transcript.interim": - handleUserTranscriptInterim(event.text); + // Ignore partial ASR updates; chat history renders committed user turns. break; case "transport.message": // Reserved for future structured messages; ignore silently. diff --git a/examples/webpage/styles.css b/examples/webpage/styles.css index 6204693..28ede32 100644 --- a/examples/webpage/styles.css +++ b/examples/webpage/styles.css @@ -239,10 +239,6 @@ body { border-bottom-right-radius: 4px; } -.bubble--user.bubble--interim { - opacity: 0.75; -} - .bubble--assistant { background: var(--assistant); color: var(--text);