AvatarKit follows a four-stage lifecycle: Initialize → Load → Connect → Cleanup. Each stage maps to a core component.
Overview
Stage 1: Initialize
Call AvatarSDK.initialize() once at app startup. This sets global configuration that all subsequent operations depend on.
Set AvatarSDK.sessionToken before connecting. The token authenticates your session with the driving service.
Stage 2: Load Avatar
Use AvatarManager to download and cache avatar assets. Loading is asynchronous and supports progress tracking.
Loaded assets are cached locally. Subsequent loads for the same avatar ID skip the download. Use AvatarManager.clear(id:) or clearAll() to manage cache.
Stage 3: Render
Create an AvatarView with the loaded avatar. The view automatically creates an AvatarController you can access to manage the connection and send audio.
Stage 4: Connect and Interact
Call controller.start() to open the WebSocket connection. Once connected, send audio with controller.send() (SDK Mode) or controller.yield() (Host Mode).
Call controller.interrupt() to stop the current playback immediately. Call controller.close() when done.
Cleanup
Clean up resources when the avatar is no longer needed.
On Web and Android, always call avatarView.dispose() when the view is no longer needed. On iOS, resources are released automatically when the view is deallocated.