Skip to content

Commit 9a51115

Browse files
committed
fix: prevent overlapping voices in typed chat responses
- Call session.interrupt() before generating reply to typed messages - Add 0.1s delay to let interruption take effect - Prevents two voices talking simultaneously when user types during agent speech
1 parent 70edf0f commit 9a51115

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

apps/agent_worker/worker.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,17 @@ def on_data_received(data: rtc.DataPacket) -> None:
289289
logger.warning(f"Failed to process data channel message: {e}")
290290

291291
async def _handle_typed_message(text: str, sender: str) -> None:
292-
"""Process a typed chat message and generate a response."""
292+
"""Process a typed chat message and generate a response.
293+
294+
Interrupts any ongoing speech before responding to avoid overlapping voices.
295+
"""
293296
try:
297+
# Interrupt any ongoing speech to avoid overlapping voices
298+
session.interrupt()
299+
300+
# Small delay to let the interruption take effect
301+
await asyncio.sleep(0.1)
302+
294303
# Use generate_reply to have the agent respond to the typed text
295304
# The agent will speak the response aloud
296305
await session.generate_reply(

0 commit comments

Comments
 (0)