TruGenClient, TruGenSession, and TruGenRunner. This page walks each one from bottom to top so you understand what’s happening under the hood before adopting the higher-level TruGenRunner in your app.
Installation
Requirements
- Python 3.10+
- Core:
livekit(>= 0.11.0),aiohttp(>= 3.8.0) [display]extras:opencv-python(>= 4.8.0),sounddevice(>= 0.4.6),numpy(>= 1.24.0)
TruGenClient
The entry point for starting TruGen AI sessions.create_session() is async: call it from an event loop.
TruGenSession
Represents an active connection to a streaming room. Everything below is a method or attribute on the session returned fromcreate_session().
Connection
await session.connect(): Connect to the streaming room and publish the local microphone.await session.disconnect(): Disconnect and cleanly release all hardware/stream resources.
Audio Output
await session.enable_audio_output(): Activates speaker playback with built-in echo cancellation. Call this once afterconnect().
Video & Audio Generators
session.video_frames_bgr(): Async generator yielding NumPy arrays (NDArray) in BGR format, ready for OpenCV.session.video_frames(): Async generator yielding raw LiveKitVideoFrameobjects.session.audio_frames(): Async generator yielding raw LiveKitAudioFrameobjects.
Low-Level Accessors
session.get_video_track(): Returns the remoteRemoteVideoTrackobject (orNone).session.get_audio_track(): Returns the remoteRemoteAudioTrackobject (orNone).session.room: Returns the underlyinglivekit.rtc.Roominstance for advanced operations.
Direct session usage (async only)
If you’re already inside an event loop and don’t need thread-safety, use the session directly withasync for:
imshow. For real GUI apps, use TruGenRunner instead.
TruGenRunner
TruGenRunner handles the multi-threading dance for you: the async session event loop runs on a background thread while your main thread stays free to drive rendering (OpenCV, Pygame, PyQt/PySide, or any custom engine).
Basic setup
Controls
runner.run(): Starts the runner and blocks the main thread to run the rendering loop.runner.stop(): Safely stops the background loop and disconnects the session (thread-safe).runner.toggle_mute(): Toggles the microphone mute state (thread-safe).
Properties & Accessors
runner.mic_muted: ReturnsTrueif the microphone is currently muted.runner.session_state: Returns the current session state enum (TruGenState).runner.session: Access the activeTruGenSessioninstance (returnsNoneuntil connected).runner.get_caption(): Returns a tuple(text, timestamp)containing the last received caption chunk and the monotonic timestamp it arrived.
The frame callback
Register a function to be called with every new BGR video frame on the main thread:ndarray (a BGR frame) or None when no frame is currently available.
Session states
Check the current state at any time:
Error handling
Wrapcreate_session() and connect() with standard try/except blocks:
TruGenEvent.ERROR: see Event Handling.
Next steps
Audio Control
Microphone lifecycle, mute controls, and custom audio injection.
Event Handling
Subscribe to connection, speaking, and transcription events.