Remove xfyun asr interim in frontend
This commit is contained in:
@@ -60,7 +60,6 @@ const state = {
|
|||||||
botUiTimer: null,
|
botUiTimer: null,
|
||||||
|
|
||||||
// Chat state.
|
// Chat state.
|
||||||
currentUserBubble: null,
|
|
||||||
currentAssistantBubble: null,
|
currentAssistantBubble: null,
|
||||||
|
|
||||||
// VU meter smoothing.
|
// VU meter smoothing.
|
||||||
@@ -152,7 +151,6 @@ function scrollChatToBottom() {
|
|||||||
|
|
||||||
function clearChat() {
|
function clearChat() {
|
||||||
els.chatLog.innerHTML = "";
|
els.chatLog.innerHTML = "";
|
||||||
state.currentUserBubble = null;
|
|
||||||
state.currentAssistantBubble = null;
|
state.currentAssistantBubble = null;
|
||||||
const empty = document.createElement("div");
|
const empty = document.createElement("div");
|
||||||
empty.className = "chat__empty";
|
empty.className = "chat__empty";
|
||||||
@@ -533,32 +531,7 @@ function resetPlaybackClock() {
|
|||||||
function handleUserTranscript(text) {
|
function handleUserTranscript(text) {
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
state.currentAssistantBubble = null;
|
state.currentAssistantBubble = null;
|
||||||
if (state.currentUserBubble) {
|
addBubble("user", text);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendText(text) {
|
function sendText(text) {
|
||||||
@@ -580,7 +553,6 @@ function sendText(text) {
|
|||||||
// reply will be created when `response.text.started` arrives.
|
// reply will be created when `response.text.started` arrives.
|
||||||
wsSend(JSON.stringify(message));
|
wsSend(JSON.stringify(message));
|
||||||
stopPlaybackQueue();
|
stopPlaybackQueue();
|
||||||
state.currentUserBubble = null;
|
|
||||||
addBubble("user", value);
|
addBubble("user", value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -595,11 +567,6 @@ function handleAssistantDelta(text) {
|
|||||||
|
|
||||||
function handleAssistantStarted() {
|
function handleAssistantStarted() {
|
||||||
state.currentAssistantBubble = null;
|
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) {
|
function handleAssistantFinal(text, interrupted) {
|
||||||
@@ -643,7 +610,6 @@ function handleEvent(event) {
|
|||||||
break;
|
break;
|
||||||
case "response.audio.started":
|
case "response.audio.started":
|
||||||
setBotIndicator(true);
|
setBotIndicator(true);
|
||||||
state.currentUserBubble = null;
|
|
||||||
break;
|
break;
|
||||||
case "response.audio.stopped":
|
case "response.audio.stopped":
|
||||||
finalizeAssistantBubble();
|
finalizeAssistantBubble();
|
||||||
@@ -662,7 +628,7 @@ function handleEvent(event) {
|
|||||||
handleUserTranscript(event.text);
|
handleUserTranscript(event.text);
|
||||||
break;
|
break;
|
||||||
case "input.transcript.interim":
|
case "input.transcript.interim":
|
||||||
handleUserTranscriptInterim(event.text);
|
// Ignore partial ASR updates; chat history renders committed user turns.
|
||||||
break;
|
break;
|
||||||
case "transport.message":
|
case "transport.message":
|
||||||
// Reserved for future structured messages; ignore silently.
|
// Reserved for future structured messages; ignore silently.
|
||||||
|
|||||||
@@ -239,10 +239,6 @@ body {
|
|||||||
border-bottom-right-radius: 4px;
|
border-bottom-right-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bubble--user.bubble--interim {
|
|
||||||
opacity: 0.75;
|
|
||||||
}
|
|
||||||
|
|
||||||
.bubble--assistant {
|
.bubble--assistant {
|
||||||
background: var(--assistant);
|
background: var(--assistant);
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
|
|||||||
Reference in New Issue
Block a user