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
renderResolutionEnabled
renderResolutionEnabled
setRenderResolutionConfig() are applied.renderResolutionConfig
renderResolutionConfig
setRenderResolutionConfig().autoRenderQualityEnabled
autoRenderQualityEnabled
setAutoRenderQuality().onRenderQualityChanged
onRenderQualityChanged
setRenderQuality().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)
AvatarView instances.- Call it after
initialize(). A call made beforeinitialize()is ignored and an error is logged; pass the initial tier asConfiguration.renderQualityinstead. - Calling
setRenderQuality()turns automatic adjustment (setAutoRenderQuality()) off.
setAutoRenderQuality(enabled, options)
setAutoRenderQuality(enabled, options)
- The SDK judges the load only from frames rendered while the Avatar is idle; speaking frames depend on the network and are not used. It lowers the tier one step at a time when the GPU render time exceeds
loadThresholdof the 33.3 ms frame budget (the render loop runs at 30 fps). - Besides the three tiers, the SDK uses one intermediate step between each pair of tiers. The reported tier is the highest tier not above the current step.
onRenderQualityChangedis called only when that tier changes, withRenderQualityChangeReason.AUTO_DOWNGRADEorAUTO_UPGRADE. - Quality stays between
minQualityandmaxQuality; withallowUpgrade = trueit is raised again when the load drops. A current tier outside that range is moved into it as soon as automatic adjustment is turned on. - Call it after
initialize(). A call made beforeinitialize(), aloadThresholdoutside 0.6–1.0, or aminQualityabovemaxQualityis ignored and an error is logged. setAutoRenderQuality(false)andsetRenderQuality()both turn automatic adjustment off and keep the current tier.
setRenderResolutionConfig(enabled, config)
setRenderResolutionConfig(enabled, config)
AvatarView, in physical pixels, within [minHeight, maxHeight]. Aspect ratio and the view’s layout size are unchanged; the system compositor scales the buffer to fit. The quality tier’s render scale still applies on top. Off by default.minHeight: a view shorter than this renders atminHeightand is scaled down. Small views render noticeably sharper, at extra GPU cost.maxHeight: a view taller than this renders atmaxHeightand is scaled up, which saves GPU work on high-density screens.- A bound left
nullis not applied. - A non-positive bound, or a
minHeightabovemaxHeight, makes the call ignored: an error is logged and the current setting is kept. - Takes effect on every live
AvatarViewimmediately. Read the current setting fromrenderResolutionEnabledandrenderResolutionConfig.
setRenderResolutionCap(enabled, maxHeight) (deprecated)
setRenderResolutionCap(enabled, maxHeight) (deprecated)
maxHeight makes the call ignored: an error is logged and the current setting is kept.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.A cached avatar is used only when its metadata can be read and every cached file is present and matches the size recorded when it was downloaded; otherwise the avatar is downloaded again.retrieve(id)
retrieve(id)
id: The avatar identifier
Avatar if available, otherwise null. Also returns null when the cached metadata cannot be read, or a cached file is missing or does not match the size recorded when it was downloaded; call load() to download the avatar again.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
AvatarError is a sealed class, so an exhaustive when over it must cover every case, including RenderBlankCanvas.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
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 viasend.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 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.
DrivingServiceMode
Driving service modes for AvatarKit.AudioCodec
Codec of the audio the host feeds into the SDK.RenderQuality
Render quality tiers for AvatarKit.AutoRenderQualityOptions
Options forAvatarSDK.setAutoRenderQuality().
RenderQualityChangeReason
WhyAvatarSDK.onRenderQualityChanged was called.
RenderResolutionConfig
Height bounds for the render buffer of everyAvatarView, in physical pixels, used by AvatarSDK.setRenderResolutionConfig(). Width follows the view’s aspect ratio.

