Installation
build.gradle.kts
AvatarSDK
The core management class of the SDK, responsible for initialization and global configuration.Properties
sessionToken
sessionToken
The session token used to authenticate avatars with the AvatarKit Server.
userId
userId
The user identifier.
version
version
Returns the version of AvatarKit.
Methods
initialize(context, appId, configuration)
initialize(context, appId, configuration)
Initialize AvatarKit.Parameters:
context: Application contextappId: Your application identifierconfiguration: The configuration for AvatarKit
isDeviceSupported()
isDeviceSupported()
Returns whether the current device meets the minimum requirements for avatar rendering.
deviceScore()
deviceScore()
Measures the device’s computational performance for avatar rendering.Returns: A
DeviceScore containing cpuScore and gpuScore.AvatarManager
Avatar resource manager, responsible for downloading, caching, and loading avatar data.Methods
initialize(context)
initialize(context)
Initialize AvatarManager. Must be called before use.Parameters:
context: Application context
load(id, onProgress)
load(id, onProgress)
Loads an avatar by ID.Parameters:
id: The avatar identifieronProgress: Optional progress callback
Avatar instance.clear(id)
clear(id)
Clears cached data for a specific avatar.Parameters:
id: The avatar identifier to clear
clearAll()
clearAll()
Clears all cached avatar data.
getCacheSize(id)
getCacheSize(id)
Gets the cache size for a specific avatar.Parameters:
id: The avatar identifier
getAllCacheSize()
getAllCacheSize()
Gets the total cache size for all avatars.Returns: The total cache size in bytes.
getCacheStats()
getCacheStats()
Get cache statistics.Returns: A
CacheStats object containing total entries, total size, and max size.AvatarController
Real-time communication controller that handles WebSocket connections and audio/video data.Properties
onConnectionState
onConnectionState
Callback for connection state changes.
onConversationState
onConversationState
Callback for conversation state changes.
onError
onError
Callback for error events.
volume
volume
The volume of playback (0.0 to 1.0).
Methods
start()
start()
Starts the avatar driving service connection.
close()
close()
Close connection.
interrupt()
interrupt()
Stops playback and terminates the current conversation.
send(audioData, end)
send(audioData, end)
Sends audio to the avatar driving service.Parameters:
audioData: PCM16 (S16LE) mono audio data. Byte length must be even (2 bytes per sample).end: Whether this is the end of the audio stream
yield(audioData, end, audioFormat)
yield(audioData, end, audioFormat)
Yields audio from the host.Parameters:
audioData: The audio dataend: Whether this is the end of the audio streamaudioFormat: The audio format (optional)
yield(animations, conversationId)
yield(animations, conversationId)
Yields animations from the host. Returns whether the server has sent all animation data for this conversation.Parameters:
animations: List of animation dataconversationId: The request ID returned from yield audio
true if the server has sent all animation data (end signal received), false otherwise.AvatarView
3D rendering view that automatically creates and manages AvatarController.Initializers
constructor(context)
constructor(context)
Creates a new avatar view.
Properties
controller
controller
The controller for the avatar.
avatarTransform
avatarTransform
Transform for avatar content position and scale within the view.
onFirstRendering
onFirstRendering
Callback when the first frame is rendered.
Methods
init(avatar, scope)
init(avatar, scope)
Initialize view with avatar.Parameters:
avatar: The avatar to displayscope: Coroutine scope, usually obtained viaactivity.lifecycleScope
pauseRendering()
pauseRendering()
Pause avatar rendering.
resumeRendering()
resumeRendering()
Resume avatar rendering.
dispose()
dispose()
Release all resources. Call when the avatar view is no longer needed (e.g., in onDestroy).
Avatar
Avatar data class containing core avatar information.| Property | Type | Description |
|---|---|---|
id | String | The avatar identifier. |
pointCount | Int | The avatar point count. |
Configuration
SDK configuration class.Initializers
Configuration(environment, audioFormat, drivingServiceMode, logLevel)
Configuration(environment, audioFormat, drivingServiceMode, logLevel)
Creates a new configuration with the specified parameters.Parameters:
environment: The environment to useaudioFormat: The audio format configurationdrivingServiceMode: The driving service modelogLevel: The log level
Environment
Environment enum.| Case | Description |
|---|---|
intl | International environment. |
cn | China environment. |
test | Test environment. |
AudioFormat
Audio format configuration for AvatarKit.Initializers
AudioFormat(sampleRate:)
AudioFormat(sampleRate:)
Creates a new audio format with the specified sample rate.Parameters:
sampleRate: The audio sample rate in Hz. Supported sample rates are: 8000, 16000, 22050, 24000, 32000, 44100, 48000.
DrivingServiceMode
Driving service modes for AvatarKit.| Case | Description |
|---|---|
SDK | The SDK handles driving service internally. |
HOST | The host application handles driving service. |
LogLevel
Log levels for AvatarKit.| Case | Description |
|---|---|
ALL | Log all messages. |
VERBOSE | Log verbose messages. |
DEBUG | Log debug messages. |
INFO | Log info messages. |
WARNING | Log warning messages. |
ERROR | Log error messages. |
OFF | Disable logging. |
ConnectionState
Connection state sealed class.| Case | Description |
|---|---|
Connecting | The connection is being established. |
Connected | The connection is active. |
Disconnected | The connection has been closed. |
Failed(Exception) | The connection failed with an exception. |
ConversationState
Avatar conversation state enum.| Case | Description |
|---|---|
Idle | Idle state, showing breathing animation. |
Playing | The avatar is playing audio/animation. |
Paused | Playback is paused. |
LoadProgress
Load progress sealed class.| Case | Description |
|---|---|
Downloading(Float) | Downloading with progress (0-1). |
Completed | Loading completed. |
Failed(Throwable) | Loading failed with error. |

