dazzling-greece-44016
08/22/2025, 3:42 AMtall-airline-16756
08/22/2025, 3:42 AMtall-airline-16756
08/22/2025, 3:43 AMfrom livekit.agents import AgentSession
session = AgentSession(
stt=your_stt_instance,
llm=your_llm_instance,
tts=your_tts_instance,
preemptive_generation=True
)
• Also, optimizing network proximity can really help cut down round-trip time for API calls.
• Don’t forget to use the UsageCollector to keep an eye on latency metrics like Time To First Token (TTFT).
2. Implementing Keyword Buzz:
• Keep an eye on transcription streams and trigger actions whenever certain keywords pop up. Here’s how you might do it:
async def on_transcribed(data):
transcript = data.alternatives[0].text.lower()
if "urgent" in transcript:
await session.speech.handle.interrupt()
await session.say("I understand this is urgent. How can I assist immediately?")
session.on("user_input_transcribed", on_transcribed)
• Or, you can use the on_user_turn_completed event to check full transcripts and respond accordingly.
If you want, I’m here to help with more examples or tailor things specifically for your setup. Just let me know!
Sources: livekit-agents/livekit/agents/voice/agent_session.py | Voice Assistants | livekit/livekit_composite | DeepWiki | How can I reduce latency in voice agents using STT, TTS and LLM? | Agent speech and audio | LiveKit Docs