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
audioFormat
audioFormat
setAudioFormat(). With Opus input, sampleRate reads 48000.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
setAudioFormat(sampleRate, opusBitrate, inputAudioFormat, opusUplinkEnabled)
setAudioFormat(sampleRate, opusBitrate, inputAudioFormat, opusUplinkEnabled)
null keeps the current value.sampleRate: The new sample rate in Hz. Accepted: 8000, 16000, 22050, 24000, 32000, 44100, 48000.opusBitrate: The new uplink Opus bitrate in bits/sec.inputAudioFormat: The new codec of the audio you feed into the SDK.opusUplinkEnabled: Whether the SDK compresses the Direct Mode uplink to Opus.
start() to reconnect; audio you feed after the call is interpreted in the new format. The SDK recreates the AudioTrack for the next conversation automatically; no audio-side work is needed. Passing values identical to the current format does nothing.- Switching
inputAudioFormattoAudioCodec.OPUSsets the sample rate to 48000. Switching back toAudioCodec.PCMkeeps the current rate unless you passsampleRatein the same call. - With PCM input at a rate the Opus uplink does not support (anything other than 8000, 16000, 24000, or 48000), the SDK sends raw PCM. Changing back to a supported rate restores the Opus uplink you requested.
- An unsupported
sampleRate, or asampleRatepassed with Opus input, logs an error and leaves the format unchanged. It is not reported throughonError.
AvatarView
3D rendering view that automatically creates and manages AvatarController.Initializers
constructor(context)
constructor(context)
Properties
controller
controller
avatarTransform
avatarTransform
Methods
init(avatar, scope, audioFormat)
init(avatar, scope, audioFormat)
avatar: The avatar to displayscope: Coroutine scope, usually obtained viaactivity.lifecycleScopeaudioFormat: The audio format for this view. Defaults to 16 kHz PCM. Each view has its own format, so two views can run different sample rates. Change it later withcontroller.setAudioFormat().
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, drivingServiceMode, logLevel, renderQuality)
Configuration(region, 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.drivingServiceMode: The driving service modelogLevel: The log levelrenderQuality: Render quality tier
AvatarView.init and AudioFormat.AudioFormat
Audio format of anAvatarView. Pass it to AvatarView.init(...) and change it later with controller.setAudioFormat().
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 view runs at 48000.inputAudioFormat: The codec of the audio you feed into the SDK viasendoryieldAudioData.AudioCodec.PCM(default) for raw PCM16,AudioCodec.OPUSfor Opus. Applies to all audio fed to the view until you change it withcontroller.setAudioFormat(); 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.

