Update asr interim

This commit is contained in:
Xin Wang
2026-02-09 17:24:15 +08:00
parent b52cd65848
commit 088943166c
2 changed files with 16 additions and 18 deletions

View File

@@ -414,6 +414,8 @@ class DuplexPipeline:
) )
}) })
if not is_final:
logger.info(f"ASR interim: {text[:100]}")
logger.debug(f"Sent transcript ({'final' if is_final else 'interim'}): {text[:50]}...") logger.debug(f"Sent transcript ({'final' if is_final else 'interim'}): {text[:50]}...")
async def _on_speech_start(self) -> None: async def _on_speech_start(self) -> None:
@@ -463,14 +465,16 @@ class DuplexPipeline:
logger.info(f"EOU detected - user said: {user_text[:100]}...") logger.info(f"EOU detected - user said: {user_text[:100]}...")
# Send final transcription to client # For ASR backends that already emitted final via callback,
await self.transport.send_event({ # avoid duplicating transcript.final on EOU.
**ev( if user_text != self._last_sent_transcript:
"transcript.final", await self.transport.send_event({
trackId=self.session_id, **ev(
text=user_text, "transcript.final",
) trackId=self.session_id,
}) text=user_text,
)
})
# Clear buffers # Clear buffers
self._audio_buffer = b"" self._audio_buffer = b""

View File

@@ -1703,16 +1703,10 @@ export const DebugDrawer: React.FC<{
} }
const last = prev[prev.length - 1]; const last = prev[prev.length - 1];
if (last?.role === 'user') { if (last?.role === 'user') {
if (last.text === finalText) { const next = [...prev];
lastUserFinalRef.current = finalText; next[next.length - 1] = { ...last, text: finalText };
return prev; lastUserFinalRef.current = finalText;
} return next;
if (finalText.startsWith(last.text) || last.text.startsWith(finalText)) {
const next = [...prev];
next[next.length - 1] = { ...last, text: finalText };
lastUserFinalRef.current = finalText;
return next;
}
} }
lastUserFinalRef.current = finalText; lastUserFinalRef.current = finalText;
return [...prev, { role: 'user', text: finalText }]; return [...prev, { role: 'user', text: finalText }];