Feature request: smooth fade-out when the agent is interrupted
Feature request: smooth fade-out when the agent is interrupted
The problem
When a user starts talking over the agent and the SDK confirms an interruption, the agent's voice stops instantly. The decision to stop is correct β but the abrupt cut, often mid-word, is the single most "robotic" artifact we hear on real phone calls.
Here's an example of what it sounds like today β the user interrupts and the agent stops abruptly: https://drive.google.com/file/d/128KuaXsuUTkGBBxy9ycaxNI__Q4Pap-9/view?usp=sharing
We're on livekit-agents 1.6.0.
What we'd like
A supported option to let the agent's voice fade out over a short window (~100β250ms) when an interruption is confirmed, instead of cutting instantly.
To be clear about scope: this is only about the way the agent stops, not when. Interruption detection would stay exactly as it is β same rules, same timing. The only thing that changes is that the last fraction of a second fades out smoothly instead of being chopped off.
Ideally this would be a simple, declarative setting β something like:
interruption_fade_out = 0.2 # seconds; 0 = instant cut (today's behavior)
I'd like to take a shot at this β I built hybrid barge-in handling for a production telephony agent and the hard cut on interruption was one of the most audible quality issues we had.
Looking at the code, the abrupt stop comes from clear_buffer() in _ParticipantAudioOutput plus AudioSource.clear_queue(): frames already pushed into the rtc.AudioSource queue (up to queue_size_ms=200) can't be modified anymore, so there's nothing left to fade at that point.
The approach I'd propose: an opt-in fade stage in the AudioOutput chain (fits the existing next_in_chain design). It holds back a small tail buffer (~100ms) before forwarding frames downstream; on clear_buffer() it applies a short linear gain ramp (say 50β80ms, configurable) to the held frames, pushes them, then clears. Cost is added playback latency equal to the tail buffer, which is why it should be opt-in β something like fade_out_on_interruption: float | None = None on the session/output options.
Two questions before I write it: (1) chain node vs. building it directly into _ParticipantAudioOutput β any preference? (2) is added latency of ~100ms acceptable as an opt-in tradeoff, or would you rather see a smaller default tail?
Do humans naturally fade their voice when they're interrupted?
Maybe the issue here is that it creates an audio artifact when the waveform is cut?
Do humans naturally fade their voice when they're interrupted?
No, but i think can be a solution so the agent does not produce audio artifact when is interrupted
Maybe the issue here is that it creates an audio artifact when the waveform is cut?
Yes
ο»ΏYes β hard cut on interrupt produces a click/pop from the discontinuous waveform. Humans don't fade, but a short gain ramp removes that artifact without changing turn-taking behavior.
Implemented as opt-in zero-latency fade inside _ParticipantAudioOutput (no holdback buffer / no added playback latency): https://github.com/livekit/agents/pull/6410
@theomonnom still sitting on #6410. If a fade API is the wrong call I can close it. I kept it only for the click/pop on a hard cut. The ramp is opt-in and adds no playback latency.