agents icon indicating copy to clipboard operation
agents copied to clipboard

Voice assistant starts speaking before user finishes - turn detection issue

Open amn-max opened this issue 1 year ago • 9 comments

Hi LiveKit team,

I'm building a voice assistant using LiveKit's AgentSession, and it's working well in general. However, I’m facing some issues with turn detection and endpointing that are impacting the user experience.

Problems I'm facing:

  1. The assistant starts speaking while the user is still talking — especially when users speak slowly or take pauses between words.
  2. Even if users speak quickly or say longer sentences, the assistant sometimes interrupts and starts responding in between.
  3. The agent interrupts too much, even when users are just thinking or hesitating — for example, when they say "emmm", "uhh", or pause to gather their thoughts.
  4. There’s no reliable way to ensure the user has finished speaking before the assistant starts talking.
  5. This leads to a frustrating user experience where the assistant blabbers or responds prematurely.

What I've tried:

  • Using the built-in silero VAD but it doesn't handle slow speech or longer sentences well.
  • Adjusting some session parameters but I haven't found the right configuration.
  • Looking into the turn detection model mentioned in the docs, but I need further guidance on implementation and tuning.
session = AgentSession(
    llm=openai.LLM(model="gpt-4.1-mini"),
    stt=openai.STT(model="gpt-4o-transcribe"),
    tts=elevenlabs.TTS(
        voice_id="wqS2JTzjt7fARO3ZxCVZ",
        model="eleven_multilingual_v2",
    ),
    turn_detection=MultilingualModel(),
    vad=ctx.proc.userdata["vad"],
    preemptive_generation=True,
)

Thanks for your support!

amn-max avatar Sep 08 '25 06:09 amn-max

As an update, I’ve also tried using OpenAI’s semantic_vad with eagerness="low" in the turn detection settings. It’s a bit better at reducing interruptions, but it still interrupts too soon on longer pauses or when users hesitate.

Here’s the session setup I’m using:

session = AgentSession(
    llm=openai.realtime.RealtimeModel(
        modalities=["text"],
        turn_detection=TurnDetection(
            type="semantic_vad",
            eagerness="low",
            create_response=True,
            interrupt_response=True, # same with False
        ),
    ),
    tts=elevenlabs.TTS(
        voice_id="wqS2JTzjt7fARO3ZxCVZ",
        model="eleven_multilingual_v2",
    ),
)

I’ve also tried AssemblyAI’s stt turn detection, but it’s not as effective as OpenAI’s model in this case.

Is there any way to further tune the eagerness or other settings to make the agent more patient and avoid interrupting during long pauses or while users are thinking?

amn-max avatar Sep 09 '25 02:09 amn-max

maybe similar issue to https://github.com/livekit/agents/issues/3382, you can try to increase the min_endpointing_delay to let the agent to wait for a longer time before start speaking (https://github.com/livekit/agents/issues/3382#issuecomment-3268566593)

longcw avatar Sep 09 '25 02:09 longcw

Hey, we are encountering the same problem. And I think it's linked to the issue but not exactly the same.

I also realized that this is a tradeoff between how easy is to interrupt the agent, and occurrences of the agent speaking over the user.

Maybe it's a candidate for change in livekit-agents, maybe if there is a vad event in the thinking state, it should always interrupt, the agent activity, as in fact the previous trigger was to soon, as the user is still speaking.

@longcw what you think? If it makes sense maybe I could implement it soon.

Bnowako avatar Sep 11 '25 21:09 Bnowako

@Bnowako do you mean to have a lower threshold for VAD interruption (min_interruption_duration) when the agent state is thinking?

longcw avatar Sep 12 '25 00:09 longcw

Yes, I think it should be either parametrized, or in thinking any vad event should interrupt thinking. In our case, I would probably want to test it with min_interruption_duration=0. Currently if you want the agent to be less interruptible, if human is speaking with long breaks the agent will speak over the user.

I am fairly new to the agents repo, but if I understand correctly it would require som additional logic here

https://github.com/livekit/agents/blob/d0c84e8cc3a150f32dd2457034f7267253d485b3/livekit-agents/livekit/agents/voice/agent_activity.py#L1137

    def on_vad_inference_done(self, ev: vad.VADEvent) -> None:
        if self._turn_detection_mode in ("manual", "realtime_llm"):
            # ignore vad inference done event if turn_detection is manual or realtime_llm
            return

        if ev.speech_duration >= self._session.options.min_interruption_duration:
            self._interrupt_by_audio_activity()

Then maybe I could add those additional parameters for the thinking state.

Bnowako avatar Sep 12 '25 06:09 Bnowako

@longcw would be very grateful for your guidance here, we moved recently 100% of our traffic to livekit, and this is getting very problematic. Maybe there is also other way of solving that, but I am also happy to contribute

Bnowako avatar Sep 12 '25 15:09 Bnowako

so perhaps interruption options (min_interruption_duration and min_interruption_words ) need to be different when agent is speaking or not speaking (thinking state). When agent is speaking we use a higher threshold, and lower when speaking not started.

longcw avatar Sep 12 '25 15:09 longcw

Yes @longcw created this issue https://github.com/livekit/agents/issues/3427 as it is not exactly the same problem as we are having

Bnowako avatar Sep 15 '25 17:09 Bnowako

we reverted the adjustment of min_endpointing_delay in recent versions, close this issue for now.

longcw avatar Sep 23 '25 02:09 longcw