Skip to main content

Installation

Use the latest standard release from Maven Central. Compatibility-suffixed artifacts expose a reduced API and are not a drop-in replacement.
build.gradle.kts

AvatarSDK

The core management class of the SDK, responsible for initialization and global configuration.
Properties
The session token used to authenticate avatars with Motion Server.
The user identifier.
Returns the version of AvatarKit.
Whether the bounds set by setRenderResolutionConfig() are applied.
The bounds last passed to setRenderResolutionConfig().
Whether automatic render quality adjustment is on. See setAutoRenderQuality().
Called on the main thread each time automatic adjustment changes the reported render quality tier. A step within the same tier does not call it, and it is not called for setRenderQuality().
Methods
Initialize AvatarKit.
Parameters:
  • context: Application context
  • appId: Your application identifier
  • configuration: The configuration for AvatarKit
Returns a Boolean value that indicates whether AvatarKit supports the current device.
Update the global rendering quality tier. The change takes effect on the next rendered frame across all active AvatarView instances.
  • Call it after initialize(). A call made before initialize() is ignored and an error is logged; pass the initial tier as Configuration.renderQuality instead.
  • Calling setRenderQuality() turns automatic adjustment (setAutoRenderQuality()) off.
Let the SDK lower the render quality tier when the GPU cannot keep up. Off by default.
  • 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 loadThreshold of 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. onRenderQualityChanged is called only when that tier changes, with RenderQualityChangeReason.AUTO_DOWNGRADE or AUTO_UPGRADE.
  • Quality stays between minQuality and maxQuality; with allowUpgrade = true it 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 before initialize(), a loadThreshold outside 0.6–1.0, or a minQuality above maxQuality is ignored and an error is logged.
  • setAutoRenderQuality(false) and setRenderQuality() both turn automatic adjustment off and keep the current tier.
See AutoRenderQualityOptions for the options.
Keep the render buffer height of every 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 at minHeight and is scaled down. Small views render noticeably sharper, at extra GPU cost.
  • maxHeight: a view taller than this renders at maxHeight and is scaled up, which saves GPU work on high-density screens.
  • A bound left null is not applied.
  • A non-positive bound, or a minHeight above maxHeight, makes the call ignored: an error is logged and the current setting is kept.
  • Takes effect on every live AvatarView immediately. Read the current setting from renderResolutionEnabled and renderResolutionConfig.
Deprecated. Use setRenderResolutionConfig(enabled, RenderResolutionConfig(maxHeight = maxHeight)) instead. setRenderResolutionCap() keeps working and will be removed in the next GA release.
Cap the render buffer height while preserving the view’s layout size. A non-positive maxHeight makes the call ignored: an error is logged and the current setting is kept.
Measures the device’s computational performance for avatar rendering.
The result contains separate cpuScore and gpuScore values.

AvatarManager

Avatar resource manager, responsible for downloading, caching, and loading avatar data.
The disk cache holds up to 128 MB. When a download or SDK start finds it larger, the least recently used avatars are removed until it fits.
Methods
Initialize AvatarManager. Must be called before use.
Parameters:
  • context: Application context
Loads an avatar by ID.
Parameters:
  • id: The avatar identifier
  • useCompressedModel: Load the smaller compressed model variant
  • onProgress: Optional progress callback
Returns: The loaded 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.
Retrieves a cached avatar by ID without downloading it.
Parameters:
  • id: The avatar identifier
Returns: The cached 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.
Clears cached data for a specific avatar.
Parameters:
  • id: The avatar identifier to clear
Clears all cached avatar data.
Gets the cache size for a specific avatar.
Parameters:
  • id: The avatar identifier
Returns: The cache size in bytes.
Gets the total cache size for all avatars.
Returns: The total cache size in bytes.

AvatarController

Real-time communication controller that handles connections, audio, and motion data.
Properties
Callback for connection state changes.
Callback for conversation state changes.
Callback for error events.
AvatarError is a sealed class, so an exhaustive when over it must cover every case, including RenderBlankCanvas.
The audio format currently in effect for this view. Read-only; change it with setAudioFormat(). With Opus input, sampleRate reads 48000.
Sets or gets the playback volume (0.0 to 1.0).
Methods
Starts the avatar driving service connection.
Close connection.
Pause Avatar playback.
Resume Avatar playback.
Stops playback and terminates the current conversation.
Sends audio to the avatar driving service.For audio source and timing guidance, see Audio.
Parameters:
  • audioData: The audio data to send
  • end: Whether this is the end of the audio stream
Returns: A conversation ID string.
Changes the audio format of this view without reinitializing the SDK. Only the parameters you pass change; null keeps the current value.
Parameters:
  • 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.
Any change interrupts the current playback and, in Direct Mode, disconnects. Call 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 inputAudioFormat to AudioCodec.OPUS sets the sample rate to 48000. Switching back to AudioCodec.PCM keeps the current rate unless you pass sampleRate in 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 a sampleRate passed with Opus input, logs an error and leaves the format unchanged. It is not reported through onError.

AvatarView

3D rendering view that automatically creates and manages AvatarController.
Initializers
Creates a new avatar view.
Properties
The controller for the avatar.
Transform for Avatar position and scale within the view.
Methods
Initialize view with avatar.
Parameters:
  • avatar: The avatar to display
  • scope: Coroutine scope, usually obtained via activity.lifecycleScope
  • audioFormat: 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 with controller.setAudioFormat().
Pause rendering for this view.
Resume rendering for this view.
Returns the rendered Avatar bounds when available.
Clean up all resources. Should be called when no longer in use.

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 background Image and AvatarView in the same Box. AvatarView renders on a transparent surface by default, so the background shows through.
For square or portrait display windows, center this 16:9 stage inside a clipped outer container. See Avatar Background for the shared cropping rules.

Avatar

Avatar data class containing core avatar information.

Configuration

SDK configuration class.
Initializers
Creates a new configuration with the specified parameters.
Parameters:
  • 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 mode
  • logLevel: The log level
  • renderQuality: Render quality tier
The audio format is set per view; see AvatarView.init and AudioFormat.

AudioFormat

Audio format of an AvatarView. Pass it to AvatarView.init(...) and change it later with controller.setAudioFormat().
Initializers
Creates a new audio format.
Parameters:
  • sampleRate: The audio sample rate in Hz. Supported sample rates are: 8000, 16000, 22050, 24000, 32000, 44100, 48000. Not used when inputAudioFormat is AudioCodec.OPUS: Opus always decodes at 48 kHz, so the view runs at 48000.
  • inputAudioFormat: The codec of the audio you feed into the SDK via send. AudioCodec.PCM (default) for raw PCM16, AudioCodec.OPUS for Opus. Applies to all audio fed to the view until you change it with controller.setAudioFormat(); audio that does not match is reported as AvatarError.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. Set false to keep a raw PCM uplink. Not used with Opus input, which is already compressed. With PCM input, sampleRate must 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 for AvatarSDK.setAutoRenderQuality().

RenderQualityChangeReason

Why AvatarSDK.onRenderQualityChanged was called.

RenderResolutionConfig

Height bounds for the render buffer of every AvatarView, in physical pixels, used by AvatarSDK.setRenderResolutionConfig(). Width follows the view’s aspect ratio.

FrameStarvationMode

Controls playback behavior when motion data cannot keep up with the audio clock.

LogLevel

Log levels for AvatarKit.

ConnectionState

Connection state sealed class.

ConversationState

Avatar conversation state enum.

LoadProgress

Load progress sealed class.