proud-lawyer-39815
12/29/2025, 4:30 PMtall-airline-16756
12/29/2025, 4:30 PMtall-airline-16756
12/29/2025, 4:30 PMtall-airline-16756
12/29/2025, 4:31 PM.say() activity to stop immediately. Here’s a concise pattern that accomplishes that.
1) Say the short message (optional)
await context.session.say("Processing, please wait...", allow_interruptions=False)
2) Immediately stop all speech output (ongoing + queued)
context.session.interrupt()
3) Disable audio input so the agent stops listening
context.session.input.set_audio_enabled(False)
4) Cancel any background .say() tasks you launched
if hasattr(self, "status_task") and not self.status_task.done():
self.status_task.cancel()
5) Do your long-running work
await long_running_operation()
6) When finished, re-enable input or end the call
context.session.input.set_audio_enabled(True) # if you want to resume listening
# or end the call
await context.ctx.room.disconnect()
Notes/tips
• session.interrupt() cancels ongoing and queued .say() calls immediately.
• Use task references (e.g., status_task) so you can cancel background tasks; cancelling the task prevents further .say() calls.
• If you never want the agent to speak during the function, omit the initial say() and call interrupt() + disable input immediately.
If you want, share a short snippet of how you start background status updates (how you create the .say() tasks) and I’ll show exactly where to track and cancel them.
Sources: Text and transcriptions | LiveKit docs | examples/voice_agents | livekit/livekit_composite | DeepWiki | External data and RAG | LiveKit docsproud-lawyer-39815
12/29/2025, 4:32 PMtall-airline-16756
12/29/2025, 4:32 PMsession.interrupt() only cancels the current and queued speech; it does NOT block future session.say() calls. If your background loop keeps calling .say(), it can schedule new speech after the interrupt.
To prevent the loop from producing more speech, stop or control the loop itself. Two common options:
• Cancel the background task:
if not status_task.done():
status_task.cancel()
• Use a shared flag the loop checks before calling `.say()`:
silent = True # set when entering silent mode
while not stopped:
if not silent:
await session.say("status update")
await asyncio.sleep(1)
Combine with session.interrupt() and session.input.set_audio_enabled(False) to immediately stop ongoing speech, stop listening, and ensure no further .say() runs.
Sources: examples/voice_agents | livekit/livekit_composite | DeepWiki | Turns overview | LiveKit docs | Tool definition and use | LiveKit docs