AvatarKit
The main entry point class for the SDK, responsible for initialization and global configuration.Type Properties
isInitialized
isInitialized
Check initialization status.
appId
appId
Get the App ID provided during initialization.
configuration
configuration
Get the configuration object provided during initialization.
sessionToken
sessionToken
Get the currently set session token.
userId
userId
The user identifier provided by the developer to identify the user in the AvatarKit Log Service.
version
version
Get SDK version.
Type Methods
initialize(appId, configuration)
initialize(appId, configuration)
Initialize SDK.Parameters:
appId: Application ID (obtained from Developer Platform)configuration: SDK configuration
setSessionToken(token)
setSessionToken(token)
Set session token for WebSocket authentication.Parameters:
token: Session token (obtained from Developer Platform, must be paired with the App ID)
setUserId(userId)
setUserId(userId)
Set user ID for logging and analytics.Parameters:
userId: User ID
cleanup()
cleanup()
Clean up SDK global resources.If you no longer need the digital human SDK, you must call this to release all occupied resources, including WASM modules, memory, etc.Note: Only call this when the entire application no longer needs digital human functionality.
AvatarManager
Avatar loader responsible for downloading and caching avatar resources.Type Properties
shared
shared
Instance Methods
load(avatarId, onProgress)
load(avatarId, onProgress)
Load avatar.Parameters:
avatarId: Avatar IDonProgress: Progress callback (optional)
AvatarView
3D rendering view (rendering layer), responsible for 3D rendering only. Internally automatically creates and managesAvatarController.
Initializers
constructor(avatar, container)
constructor(avatar, container)
Create view instance.Parameters:
avatar: Loaded avatar objectcontainer: Container element (required)- Canvas automatically uses the full size of the container (width and height)
- Canvas aspect ratio adapts to container size - set container size to control aspect ratio
- Canvas is automatically added to the container
Instance Properties
avatarController
avatarController
Real-time communication controller.
ready
ready
Wait for first frame to render.
onFirstRendering
onFirstRendering
Callback when the avatar is first rendered.
transform
transform
Transform for avatar content position and scale within the canvas.
x: Horizontal offset in normalized coordinates (-1 to 1, where -1 = left edge, 0 = center, 1 = right edge)y: Vertical offset in normalized coordinates (-1 to 1, where -1 = bottom edge, 0 = center, 1 = top edge)scale: Scale factor (1.0 = original size, 2.0 = double size, 0.5 = half size)
Instance Methods
dispose()
dispose()
Clean up view resources.
AvatarController
Real-time communication controller that handles WebSocket connections and audio/video data.Instance Properties
connectionState
connectionState
Service connection state.
conversationState
conversationState
Conversation state.
onConnectionState
onConnectionState
Connection state callback.Note: SDK mode only.
onConversationState
onConversationState
Conversation state callback.
onError
onError
Error callback.
volume
volume
The volume of playback.Volume level from 0.0 to 1.0. Affects only avatar audio player, not system volume.
Instance Methods
initializeAudioContext()
initializeAudioContext()
Initialize audio context. This method MUST be called before any audio-related operations.Example:
start()
start()
Connect to service.Note: SDK mode only. Must call
initializeAudioContext() first.close()
close()
Close service and reset conversation state.Note: SDK mode only.
interrupt()
interrupt()
Interrupt conversation.
send(audioData, end)
send(audioData, end)
Send audio data to server.Parameters:
audioData: PCM audio data (ArrayBuffer or Uint8Array format, must be mono PCM16 matching configured sample rate)- PCM files: Can be directly read as ArrayBuffer
- WAV files: Extract PCM data from WAV format (may require resampling)
- MP3 files: Decode first (e.g., using AudioContext.decodeAudioData()), then convert to PCM16
end: Whether audio data has been fully sent
setVolume(volume)
setVolume(volume)
Set volume level.Parameters:
volume: Volume level from 0.0 to 1.0
getVolume()
getVolume()
Get current volume level.Returns: Current volume level from 0.0 to 1.0.
Configuration
Configuration
SDK configuration interface.environment: Specifies the environment (cn/intl), SDK will automatically use the corresponding API address and WebSocket address based on the environmentaudioFormat: Configures audio sample rate and channel count (optional)- Default:
{ channelCount: 1, sampleRate: 16000 } channelCount: Fixed to 1 (mono channel)sampleRate: Audio sample rate in Hz- Supported values: 8000, 16000, 22050, 24000, 32000, 44100, 48000
- The configured sample rate will be used for both audio recording and playback
- Default:
AudioFormat
Audio format configuration interface.Environment
Environment enumeration.Connection State
ConnectionState
SDK connection state definition.Conversation State
ConversationState
SDK conversation state definition.LoadProgress
Load progress enumeration.CameraConfig
Camera configuration interface.Error Handling
AvatarError
SDK error type definition.Usage Examples
Basic Initialization
1
Create Configuration
2
Initialize SDK
Authentication will start when connecting to the service. If authentication fails, onError callback will be called
Create Avatar View
1
Create Avatar Manager Instance
2
Create Avatar View
Audio Processing
Audio Usage Example
Implement Event Callbacks
Event Callbacks Implementation
Error Code Reference
| Error Type | Error Code | Description | Solution |
|---|---|---|---|
sdkNotVerified | 1001 | SDK not verified | Check if SDK started successfully |
avatarIdWrong | 1002 | Avatar ID is invalid | Check avatar status |
avatarAssetsMissing | 1003 | Avatar assets are missing | Check if avatar resources are complete |
avatarCameraSettingsWrong | 1004 | Avatar camera settings are invalid | Check camera parameters |
serviceError | 1005 | Server error | Network service may be temporarily down |
sendDataWrong | 1008 | Sent data is invalid | Check if the audio data sent is valid |
requestTimeout | 1009 | Request timeout | Check network status |
Memory Management
- AvatarKit automatically manages internal resources
- When exiting the avatar page, call
close()through AvatarController anddispose()through AvatarView to clean up resources

