Installation
Use the latest standard release from Maven Central. Compatibility-suffixed artifacts expose a reduced API and are not a drop-in replacement.AvatarSDK
The core management class of the SDK, responsible for initialization and global configuration.Properties
sessionToken
sessionToken
userId
userId
version
version
Methods
initialize(context, appId, configuration)
initialize(context, appId, configuration)
context: Application contextappId: Your application identifierconfiguration: The configuration for AvatarKit
isDeviceSupported()
isDeviceSupported()
setRenderQuality(quality)
setRenderQuality(quality)
setRenderResolutionCap(enabled, maxHeight)
setRenderResolutionCap(enabled, maxHeight)
deviceScore()
deviceScore()
cpuScore and gpuScore values.AvatarManager
Avatar resource manager, responsible for downloading, caching, and loading avatar data.Methods
initialize(context)
initialize(context)
context: Application context
load(id, useCompressedModel, onProgress)
load(id, useCompressedModel, onProgress)
id: The avatar identifieruseCompressedModel: Load the smaller compressed model variantonProgress: Optional progress callback
Avatar instance.clear(id)
clear(id)
id: The avatar identifier to clear
clearAll()
clearAll()
getCacheSize(id)
getCacheSize(id)
id: The avatar identifier
getAllCacheSize()
getAllCacheSize()
AvatarController
Real-time communication controller that handles connections, audio, and motion data.Properties
onConnectionState
onConnectionState
onConversationState
onConversationState
onError
onError
volume
volume
Methods
start()
start()
close()
close()
pause()
pause()
resume()
resume()
interrupt()
interrupt()
send(audioData, end)
send(audioData, end)
audioData: The audio data to sendend: Whether this is the end of the audio stream
yieldAudioData(audioData, end)
yieldAudioData(audioData, end)
audioData: The audio dataend: Whether this is the end of the audio stream
yieldFramesData(animations, conversationId)
yieldFramesData(animations, conversationId)
animations: List of encoded motion data payloadsconversationId: The identifier returned by the matchingyieldAudioData()call
AvatarView
3D rendering view that automatically creates and manages AvatarController.Initializers
constructor(context)
constructor(context)
Properties
controller
controller
avatarTransform
avatarTransform
Methods
init(avatar, scope)
init(avatar, scope)
avatar: The avatar to displayscope: Coroutine scope, usually obtained viaactivity.lifecycleScope
pauseRendering()
pauseRendering()
resumeRendering()
resumeRendering()
getBoundingRect()
getBoundingRect()
dispose()
dispose()
Render over an Avatar Background
Download the optional 16:9 background from Spatius Studio and add it as a drawable resource. In Compose, place the backgroundImage and AvatarView in the same Box. AvatarView renders on a transparent surface by default, so the background shows through.
Avatar
Avatar data class containing core avatar information.Configuration
SDK configuration class.Initializers
Configuration(region, audioFormat, drivingServiceMode, logLevel, renderQuality)
Configuration(region, audioFormat, drivingServiceMode, logLevel, renderQuality)
region: The region to connect to. Defaults to"auto": the SDK selects the closest serving region at initialization and reuses the cached choice on later launches. Pass"us-west","ap-northeast", or"cn-beijing"to force that region. If automatic selection cannot be reached, the SDK falls back to a default region and continues initializing.audioFormat: The audio format configurationdrivingServiceMode: The driving service modelogLevel: The log levelrenderQuality: Render quality tier
AudioFormat
Audio format configuration for AvatarKit.Initializers
AudioFormat(sampleRate:opusBitrate:inputAudioFormat:opusUplinkEnabled:)
AudioFormat(sampleRate:opusBitrate:inputAudioFormat:opusUplinkEnabled:)
sampleRate: The audio sample rate in Hz. Supported sample rates are: 8000, 16000, 22050, 24000, 32000, 44100, 48000. Not used wheninputAudioFormatisAudioCodec.OPUS: Opus always decodes at 48 kHz, so the session runs at 48000.inputAudioFormat: The codec of the audio you feed into the SDK viasendoryieldAudioData.AudioCodec.PCM(default) for raw PCM16,AudioCodec.OPUSfor Opus. Fixed for the whole session; audio that does not match is reported asAvatarError.InvalidAudioInput.opusUplinkEnabled: Whether the SDK compresses the direct mode uplink to Opus. On by default, which reduces the upload to roughly an eighth at the cost of encoding on the client. Setfalseto keep a raw PCM uplink. Not used inBACKENDmode, which has no uplink, or with Opus input, which is already compressed. With PCM input,sampleRatemust be 8000, 16000, 24000, or 48000; on any other rate the SDK logs a warning and sends raw PCM instead of failing to initialize.opusBitrate: Target bitrate in bits/sec for the uplink the SDK encodes. Defaults to 48000. Higher means better quality and a larger upload.

