Installation
Install the SDK in your project using npm:Browser Requirements
The TruGen SDK uses WebRTC for real-time video and audio streaming. Ensure your target browsers support:- WebRTC (Chrome 56+, Firefox 44+, Safari 11+, Edge 79+)
- MediaDevices API for microphone access
HTML Setup
This example requires a video element to display the persona:autoplaystarts the stream when the page loads.playsinlineprevents fullscreen mode on mobile devices.
Basic Usage
To keep your API key secure, exchange it for a short-lived session token on your server before initializing the client. See Usage in Production for detailed session token information.Initialize the Client
UsecreateClient with your session token:
Start Streaming
To start streaming the avatar, register a video stream event listener to attach the track to your video element, then connect the session:Listen for Events
Handle connection lifecycle and speaking events using theTruGenEvent enum:
Stopping a Stream
To stop an active session and release media resources:Custom Track and Frame Processing
For advanced use cases, the SDK provides low-level getters and event helpers to access WebRTC media tracks and raw video frames.Accessing Media Tracks
Get direct access to the underlying LiveKit track instances once the session is connected:Track Subscriptions
Use callbacks to listen for track updates. These helpers automatically execute the callback if the track is already active, and return an unsubscribe function:Processing Raw Video Frames
If you need to feed video frames into a custom canvas layout, AI processing pipeline, or video filters, useonVideoFrame.
It decodes and emits raw frames (using VideoFrame via browser WebCodecs if supported, or falling back to canvas-rendered ImageData frames) and returns an unsubscribe function: