Web Demo Repository
Complete working examples for Vanilla JS, Vue, and React — the fastest way to get started.
Installation
- pnpm
- npm
- yarn
Build Tool Configuration
- Vite
- Next.js
Add the official plugin to
vite.config.ts:vite.config.ts
Plugin Features
Plugin Features
The plugin automatically handles:
- Development Server: Sets correct MIME type for WASM files
- Build Time: Copies WASM files to
dist/assets/ - Cloudflare Pages: Generates
_headersfile - Vite Configuration: Configures
optimizeDeps,assetsInclude, etc.
Manual Configuration (Without Plugin)
Manual Configuration (Without Plugin)
vite.config.ts
Authentication
SDK Mode requires an App ID and a Session Token.Authentication Flow:The Session Token must be set before calling
start(). Never expose your token generation logic in client-side code.Quick Start
1
Initialize SDK
2
Load Avatar
3
Create View
4
Initialize Audio Context
5
Connect and Send Audio
6
Cleanup
Core API
AvatarSDK
SDK initialization and global configuration.setSessionToken() can be called before or after initialize(). If called before, the token is applied automatically during initialization.AvatarManager
Avatar resource loading and caching. Access via the singletonAvatarManager.shared.
AvatarView
3D rendering view. Automatically creates a Canvas element and anAvatarController.
Transform coordinates:
AvatarController — SDK Mode Methods
These methods are only available whendrivingServiceMode is DrivingServiceMode.sdk.
send() behavior:
end: false— continues the current conversation roundend: true— marks the end of audio input for the current round. The avatar will continue playing remaining animation until finished, then automatically return to idle (notified viaonConversationState). Sending new audio after this starts a new round and interrupts any ongoing playback
AvatarController — Common Methods
Available in both SDK Mode and Host Mode.AvatarController — Event Callbacks
Audio Format
The SDK requires audio in mono PCM16 format:
Data size: 1 second at 16 kHz = 16,000 samples × 2 bytes = 32,000 bytes.
Converting MP3 to PCM16
Converting MP3 to PCM16
Configuration
Configuration Interface
Environment
DrivingServiceMode
AudioFormat
LogLevel
State Management
ConnectionState
Reported viaonConnectionState callback (SDK Mode only).
ConversationState
Reported viaonConversationState callback.
State transitions are notified immediately when the transition starts, not when the animation completes. For example,
playing is reported as soon as the transition from idle begins.Error Handling
AvatarError
Error Callback
Lifecycle Management
Avatar Switching
Resource Cleanup
dispose() automatically cleans up all resources:
- WebSocket connections
- Audio playback data and animation resources
- Canvas elements and render system
- Event listeners and callbacks
Fallback Mechanism
If the WebSocket connection fails within 15 seconds, the SDK automatically enters audio-only fallback mode — audio continues playing without animation. This ensures uninterrupted audio playback when the server is unreachable.- The fallback mode is interruptible like normal playback
onConnectionStatereportsfailedwhen the connection times out

