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
- Python 3.10+
- A TruGen API key from the Developer Portal
- An agent ID — create one in the Teammate Library
1. Install
[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 asavatar.py:
What just happened
create_sessioninitialised aTruGenClientwith your API key and asked it to create aTruGenSessionfor your agent.connect()opened the WebRTC connection;enable_audio_output()activated the speaker with built-in Acoustic Echo Cancellation.TruGenRunnerspun up a background thread running the async session event loop. The main thread stays free for your rendering code.@runner.on_frameregistered 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 theqkey 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.