Skip to content

fix(cli): drain TcpAudioOutput resampler on flush, skip empty flushes, and report pause=False - #8767

Open
yaosongding wants to merge 1 commit into
livekit:mainfrom
yaosongding:fix/tcp-audio-output-flush-and-pause
Open

yaosongding wants to merge 1 commit into
livekit:mainfrom
yaosongding:fix/tcp-audio-output-flush-and-pause

Conversation

@yaosongding

Copy link
Copy Markdown

Summary

  • Drain resampler tail on flush() and reset filter state on clear_buffer(): TcpAudioOutput resamples 24 kHz agent audio to 48 kHz via rtc.AudioResampler, which buffers ~30–40 ms internally. flush() previously sent AudioPlaybackFlush without calling self._resampler.flush(), clipping utterance tails and dropping short (< ~35 ms) segments to zero wire frames; clear_buffer() also left stale samples inside the resampler filter and flush() unconditionally cleared _interrupted_ev even if clear_buffer() had already fired. Drain self._resampler.flush() before AudioPlaybackFlush when not interrupted, recreate the resampler in clear_buffer(), and reset _playout_done / _interrupted_ev at segment boundaries instead of inside flush().
  • Skip wire AudioPlaybackFlush on empty segments: _audio_forwarding_task always calls audio_output.flush() in finally even when zero frames were captured. Sending an unconditional AudioPlaybackFlush on an empty segment causes the Go CLI broker to immediately reply with AudioPlaybackFinished, which can resolve the next utterance's wait_for_playout() prematurely. Return early in flush() when not self._pushed_duration.
  • Report AudioOutputCapabilities(pause=False): TcpAudioOutput advertised pause=True without implementing pause() / resume() (and the ConsoleIO wire protocol has no pause/resume messages), causing resume_false_interruption to call a no-op pause() and transition agent state to "listening" while the CLI broker kept playing buffered audio. Align with QueueAudioOutput and DataStreamAudioOutput by reporting pause=False.

Test plan

  • uv run pytest tests/test_cli.py tests/test_session_host.py tests/test_remote_session.py --unit (covers can_pause, resampler tail draining, empty-flush wire suppression, clear_buffer() before/after flush(), and loopback TCP TcpAudioOutput -> TcpSessionTransport -> SessionHost integration)
  • uv run ruff check and uv run ruff format --check on touched files
  • mypy strict type check on livekit.agents.cli.tcp_console and tests/test_cli.py

@yaosongding
yaosongding marked this pull request as ready for review November 25, 2026 00:45
@yaosongding
yaosongding requested a review from a team as a code owner November 25, 2026 00:45

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 3 flags

Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant