how to have speech interrupt setup?
# ask-ai
d
how to have speech interrupt setup?
t
Thanks for reaching out, Giriraj. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Setting up speech interrupt functionality in LiveKit is pretty straightforward, and I’m here to help you through it! You can tweak interruption settings both at the session level and when generating speech: 1. Configure Session-Level Interruption Settings: • allow_interruptions: This is set to
True
by default, letting users jump in and interrupt the agent mid-speech. If you want to keep things uninterrupted, just set it to
False
. • min_interruption_duration: This is the minimum amount of speech (in seconds) that needs to be detected before an interruption kicks in (default is 0.5). • min_interruption_words: The fewest number of words that need to be transcribed before we consider the interruption intentional (default is 0). • min_endpointing_delay: This is the wait time before we decide the user has finished speaking (default is 0.5). 2. Control Interruptions During Speech: When you use
session.say()
to get the agent talking, you can choose if that specific message can be interrupted or not:
Copy code
await session.say(
    "Hello. How can I help you today?",
    allow_interruptions=False  # This message won’t be interrupted
)
3. Manual Interruption: If you ever need to jump in and stop the agent right away, you can use
session.interrupt()
. It’ll halt any speech happening and trim the context to just what was actually heard. 4. SpeechHandle Configuration: Every speech action uses a
SpeechHandle
, which you can set up to allow or block interruptions. When you create a
SpeechHandle
, there’s an
allow_interruptions
option that’s
True
by default. If you want me to walk you through any part of this or have other questions, just let me know—I’m here to help! Sources: Turn detection and interruptions | LiveKit Docs | Configuring turn detection and interruptions | LiveKit Docs | Agent speech | LiveKit Docs | Turn detection and interruptions | LiveKit Docs | tests/test_agent_session.py