Skip to main content
A minimal but production-shaped OpenCV viewer for a TruGen agent. Adapted verbatim from the examples/basic_session_ui.py in the official Python SDK repository.

What it does

  • Connects to a live TruGen session and renders the avatar in a resizable OpenCV window
  • Shows a top status bar with the current session state and mic status
  • Overlays streaming captions with a fade-out timer at the bottom
  • Toggles mic mute with M, quits with Q or Esc

Requirements

Set your credentials in a .env:

Run

Full source

What to notice

  • create_session() owns the connection — this pattern keeps your credentials, agent selection, and setup calls in one place.
  • enable_audio_output() activates the speaker with Acoustic Echo Cancellation. Without it, the agent hears its own voice through the mic and gets caught in a feedback loop.
  • @runner.on_frame runs on the main thread, so cv2.imshow, cv2.waitKey, and window management are all safe from here.
  • runner.get_caption() returns (text, timestamp) so you can time-box overlays — the CAPTION_HOLD_SECS check fades captions after 5 seconds.
  • runner.stop() is thread-safe and idempotent — call it from any thread, any time.

Next steps

Advanced GUI Example

Full-feature viewer with WAV injection, speaking indicators, and reconnect handling.

Event Handling

Subscribe to every event the SDK emits.