I am using "await self.session.say" how do I delay...
# ask-ai
h
I am using "await self.session.say" how do I delay the TTS output while allowing the user to speak and interrupt?
t
Thanks for reaching out, Prathamesh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to delay TTS when using
await self.session.say
but still allow the user to speak and interrupt. Use an async delay before calling
say
and keep interruptions enabled. Example:
Copy code
import asyncio

await asyncio.sleep(2.0)  # delay while VAD/STT remains active
await self.session.say("Your delayed message here.", allow_interruptions=True)
Notes: •
asyncio.sleep()
delays the TTS call without blocking VAD/STT, so user speech can start and interrupt playback. • Ensure
allow_interruptions=True
(default) so VAD-based interruption works. Sources: Turn detection and interruptions | LiveKit Docs | Agent speech and audio | LiveKit docs | External data and RAG | LiveKit Docs
h
The agent is currently not adhering to instruction and system prompt, and starts to hallucinate and speak to itself. How to solve this ?
t
You're asking how to stop the agent from hallucinating, speaking to itself, and ignoring the system prompt. Helpful steps you can take now to diagnose and fix it — and a couple quick questions so I can narrow recommendations. 1) Check and tighten the system prompt • Make the role, allowed actions, and turn-taking rules explicit and short. Example instruction to add: "Only respond to human user input. Never respond to your own speech or produce internal monologue." • Put strict negative constraints too: "Do not speculate. If you don't know, say 'I don't know'." 2) Ensure the agent ignores its own audio • Configure turn-detection/participant filtering so audio from agent participants is not treated as user input (only standard human participants trigger turns). • Confirm VAD/source labels so the agent doesn't interpret its TTS playback as incoming speech. 3) Validate and sanitize LLM output before playback • Intercept LLM responses and filter out chain-of-thought, self-references, or meta commentary before calling TTS. • Example: drop fragments containing "I think", "internal", or similar patterns; require final answer format. 4) Use interruption and playback controls • Keep
allow_interruptions=True
so humans can cut off inappropriate speech. • If the agent loops, allow shorter utterances and require explicit user prompts to continue. 5) Reduce false triggers from echoes/noise • Enable noise cancellation and echo-suppression on room inputs so the agent doesn't hear echoes of its own TTS. • Tune VAD thresholds to avoid brief artifacts being treated as user speech. 6) Test with targeted scenarios • Create short test scripts where the human is silent after speaking, and where the human interrupts mid-speech, to confirm correct turn-taking and interruption behavior. • Record sessions to inspect what the agent hears vs. what it speaks. Quick questions so I can give concrete code/config examples: • Can you paste your current system prompt (redact sensitive data)? • How is your session/room configured for participant kinds or VAD? (a short snippet or settings helps) • Do you see the agent reacting to audio labeled as AGENT or to its own local playback? If you share those, I’ll give exact config/code changes to stop self-talk and reduce hallucinations. Sources: examples/drive-thru | livekit/livekit_composite | DeepWiki | How to Enable Agent-to-Agent Speech Detection in LiveKit | Agents (Node.js) | livekit/livekit_composite | DeepWiki | Modifying LLM output before TTS | LiveKit docs | Testing and evaluation | LiveKit docs