Skip to main content
This quickstart uses TruGenRunner — the thread-safe wrapper that runs the async session loop on a background thread while your main thread handles rendering. Perfect for OpenCV, Pygame, PyQt/PySide, or any UI toolkit.

Prerequisites

1. Install

The [display] extra pulls in opencv-python, sounddevice, and numpy for the GUI example below.

2. Set your credentials

Create a .env file:

3. Run your first avatar

Save the following as avatar.py:
Run it:
A window opens showing the avatar. Speak into your microphone — the agent responds. Press Q to quit.

What just happened

  • create_session initialised a TruGenClient with your API key and asked it to create a TruGenSession for your agent. connect() opened the WebRTC connection; enable_audio_output() activated the speaker with built-in Acoustic Echo Cancellation.
  • TruGenRunner spun up a background thread running the async session event loop. The main thread stays free for your rendering code.
  • @runner.on_frame registered a callback that fires on the main thread with each new BGR video frame (a NumPy array) — perfect for OpenCV, Pygame, or any UI toolkit.
  • runner.run() blocked the main thread to drive the rendering loop; runner.stop() (from the q key press) shut down the background loop and cleanly disconnected.

Next steps

Authentication

Secure your API key and manage session tokens.

Basic Usage

Full SDK reference for initializing, streaming, and disconnecting.

Basic GUI Example

Complete OpenCV viewer with status bar, mic indicator, and floating captions.

Event Handling

Listen to connection, speaking, and transcription events in real time.