Skip to main content
Every TruGenSession and TruGenRunner is event-driven. Register handlers with decorators; the SDK invokes them on the correct thread as events fire. You have two entry points:
  • @runner.on_* decorators on a TruGenRunner — main-thread callbacks, ideal for UI updates
  • @session.on() decorator on a TruGenSession — low-level async callbacks, run on the session’s event loop
Use runner decorators for GUI apps. Use session decorators when you’re driving the session directly from your own async code.

Runner Decorators

@runner.on_frame

Receives BGR video frames (NumPy arrays) or None on the main thread. Fired on every new frame.

@runner.on_caption

Receives real-time streaming caption chunks — ideal for UI overlays.

@runner.on_state

Called when the session’s connection state transitions.

@runner.on_event

Handles any standard TruGenEvent enum or custom string event.

Session Decorators

If you’re not using TruGenRunner, listen to events directly on the TruGenSession using @session.on():
Register handlers before calling session.connect(). Startup events like microphone permission, connection, and stream initialization can fire while connect() is running. Late listeners will not receive events that already fired.

Common patterns

Connection lifecycle

Reconnection handling

Transient network drops emit connection.reconnecting and connection.reconnected as string events:

Speaking indicators

Microphone permission lifecycle

Next steps

List all events

Complete reference of every event the SDK emits.

Audio Control

Programmatically control the mic and inject audio.