nice-fish-21757
09/28/2025, 7:25 AMtall-airline-16756
09/28/2025, 7:26 AMtall-airline-16756
09/28/2025, 7:26 AMallow_interruptions, min_interruption_duration, and min_interruption_words.
• Event Monitoring: Keep track of interruptions by listening to events such as agent_state_changed or playback_finished.
• Chat Context: The interrupted flag in the conversation history helps you spot any responses that didn’t finish completely.
• Manual Control: If you want to take charge directly, you can use session.interrupt() to stop agent speech whenever needed.
If you’d like, I’m here to provide detailed examples or guide you through the implementation—just let me know!
Sources: Turn detection and interruptions | LiveKit Docs | Docs::Agents | livekit-agents/livekit/agents/voice/agent_session.py | VoicePipelineAgent | LiveKit Docs | pipeline-llm/interrupt_user.pynice-fish-21757
09/28/2025, 7:28 AMtall-airline-16756
09/28/2025, 7:28 AMagent_state_changed event to notice when the agent switches from speaking to listening because of an interruption:
@session.on("agent_state_changed")
def on_agent_state_changed(ev):
if ev.new_state == "listening" and ev.old_state == "speaking":
print("Agent was interrupted by user speech")
• Playback Finished Event: Another way is to use the playback_finished event, which helps detect if playback was interrupted. This event includes an interrupted flag you can check:
@session.output.audio.on("playback_finished")
def on_playback_finished(ev):
if ev.interrupted:
print(f"Speech was interrupted at {ev.playback_position} seconds")
These events are great tools to help your program respond smoothly to interruptions. If anything feels unclear or if you'd like me to walk you through more examples, just let me know—I'm here to help!nice-fish-21757
09/28/2025, 7:59 AMtall-airline-16756
09/28/2025, 7:59 AMplayback_finished event in LiveKit! This event is emitted by the AudioOutput class to let you know when an audio playback segment has ended. Here are some important details to keep in mind:
• Event Properties:
• `playback_position`: This tells you the duration of the audio that has been played, measured in seconds.
• `interrupted`: This indicates whether the playback was stopped before it naturally finished.
• `synchronized_transcript`: An optional transcript that syncs with the playback, which can be really useful.
Here's a Python example to illustrate:
@session.output.audio.on("playback_finished")
def _on_playback_finished(ev):
print(f"Playback finished: interrupted={ev.interrupted}, position={ev.playback_position}")
And here's how you might use it in JavaScript:
session.output.audio.on('playbackFinished', (ev) => {
console.log(`Playback finished at ${ev.playbackPosition}s, interrupted: ${ev.interrupted}`);
});
If you have any questions or would like me to walk you through more examples, please don’t hesitate to ask—I’m here to help!
Sources: livekit-agents/livekit/agents/voice/transcription/synchronizer.py | How to detect when an agent has finished speaking | agents/src/voice/io.ts