Skip to main content
Every SDK feature in one runnable example. Adapted verbatim from examples/advanced_session_ui.py in the official Python SDK repository.

Features demonstrated

  • Live video avatar display
  • Audio output with Acoustic Echo Cancellation (AEC)
  • Agent captions overlay
  • Mic mute/unmute
  • Agent speaking detection
  • User speaking detection
  • Connection quality monitoring
  • Mic permission events (pending / granted / denied)
  • Reconnect handling
  • Custom WAV audio injection (press A or pass --wav flag)
  • Input audio stream events

Controls

Click the video window first to focus it, then:

Requirements

Set your credentials in a .env:

Run

Full source

Notable patterns to steal

  • inject_wav() schedules audio injection safely using asyncio.run_coroutine_threadsafe — the correct way to bridge from your main GUI thread into the SDK’s async loop.
  • Mic muting during injection — this is critical for AEC. Without it, the agent responds to its own injected audio via the mic, spiraling into feedback.
  • connection.quality_changed gives you a live signal from LiveKit about the participant’s connection quality — display it as a small badge for user awareness.
  • _caption_buffer on TEXT_CHUNK_RECEIVED is cleared when the agent stops speaking, so stale captions don’t linger.

Next steps

Basic GUI Example

The minimal viewer this one is built on.

Audio Control

Deeper reference on injection and mic control.