Remove xfyun asr interim in frontend

This commit is contained in:
Xin Wang
2026-05-22 09:40:16 +08:00
parent dab2d0593e
commit 0d82acc0d2
2 changed files with 2 additions and 40 deletions

View File

@@ -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.

View File

@@ -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);