chilly-nest-87883
07/24/2025, 3:09 AMtall-airline-16756
07/24/2025, 3:09 AMtall-airline-16756
07/24/2025, 3:10 AM@session.on("user_state_changed")
def on_user_state_changed(ev: UserStateChangedEvent):
if ev.new_state == "listening":
print("User stopped speaking")
@session.on("agent_state_changed")
def on_agent_state_changed(ev: AgentStateChangedEvent):
if ev.new_state == "speaking":
print("Agent started speaking")
These events work in conjunction with LiveKit's Voice Activity Detection (VAD) system, which detects when users have finished speaking by waiting for a minimum duration of silence before considering the turn complete.
Sources: Turn detection and interruptions | LiveKit Docs | AI voice agents | LiveKit Docs | VoicePipelineAgent | LiveKit Docs | Agents 0.x migration guide | LiveKit Docschilly-nest-87883
07/25/2025, 12:14 AMtall-airline-16756
07/25/2025, 12:15 AMuser_started_speaking event that lets you know when someone starts chatting.
⢠In version 1.0, you can also use the user_state_changed event to keep an eye on things. Check out this neat example:
@session.on("user_state_changed")
def on_user_state_changed(ev: UserStateChangedEvent):
if ev.new_state == "speaking":
print("User started speaking")
For Client SDKs:
⢠The ParticipantEvent.IsSpeakingChanged is your go-to for tracking when someone starts or stops talking. Here's a quick example that shows how easy it is:
`participant.on(ParticipantEvent.IsSpeakingChanged, (speaking: boolean) => {
console.log(${participant.identity} is ${speaking ? 'now' : 'no longer'} speaking. audio level: ${participant.audioLevel});
});`
For Low-Level Speech Detection:
⢠Want more detailed control? Voice Activity Detection (VAD) events like on_start_of_speech have got you covered.
⢠Speech-to-Text services also chip in with START_OF_SPEECH events to help you out.
The right event really depends on what you're building - whether it's an agent, a client app, or you need super precise speech detection. Hope this helps you find exactly what you need! š Sources: SpeechEventType | LiveKit Agents | VoicePipelineAgent | LiveKit Docs | VoicePipelineAgent | LiveKit Docs | VPAEvent | LiveKit Agents | Turn detection and interruptions | LiveKit Docschilly-nest-87883
07/25/2025, 12:19 AMtall-airline-16756
07/25/2025, 12:20 AMFunctionCall objects that show which tools were used.
⦠`function_call_outputs`: The results from those tool calls - think of it like getting the receipts for what just happened!
⦠`created_at`: A timestamp that tells you exactly when this event popped up.
Wanna see how it works? Check this out:
from livekit.agents.voice.events import FunctionToolsExecutedEvent
def on_tools_executed(event: FunctionToolsExecutedEvent):
for call, output in event.zipped():
print(f"Tool {call.name} executed with output: {output}")
session.on("function_tools_executed", on_tools_executed)
The coolest part? That zipped() method that pairs up your function calls with their outputs - it's like matching socks, but for code! š
This event is your behind-the-scenes buddy, letting you know exactly what tools have been called and what they discovered. Pretty neat, right? Sources: livekit-agents/livekit/agents/llm/llm.py