Skip to main content

Installation

In Xcode, open File > Add Package Dependencies, enter https://github.com/spatius-ai/avatarkit-ios-release.git, and select the latest stable release.

AvatarSDK

Main initialization and configuration interface for AvatarKit.
Type Properties
The app identifier.
The app configuration.
The session token used to authenticate avatars with Motion Server.
The user identifier provided by the developer to identify the user in the AvatarKit Log Service.
Returns the version of AvatarKit.
Type Methods
Initialize AvatarKit.
Parameters:
  • appID: The app identifier
  • configuration: The configuration for AvatarKit
Update the global rendering quality tier.
Cap render backing-buffer height while preserving the view’s CSS/layout size.
Check whether the current device can run AvatarKit.
Measures the device’s computational performance for avatar rendering.

AvatarManager

Manage avatar asset loading, caching, and retrieval.
Type Properties
The shared avatar manager instance.
Instance Methods
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.
Cancels the loading of avatar by ID.
Parameters:
  • id: The avatar identifier
Cancels all loading of avatars.
Retrieves a cached avatar by ID.
Parameters:
  • id: The avatar identifier
Returns: The cached Avatar if available, otherwise nil.
Derives an avatar from a local asset path.
Parameters:
  • assetPath: The path to the avatar asset
Returns: The derived Avatar instance.
Clears cached data for a specific avatar.
Parameters:
  • id: The avatar identifier to clear
Clears all cached avatar data.
Clears least recently used avatars, keeping the specified count.
Parameters:
  • keepCount: Number of most recently used avatars to keep
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

The main controller for managing avatar driving service connections and interactions.
Instance Properties
Callback for connection state changes.
Callback for conversation state changes.
Callback for error events.
Starts the avatar driving service connection.
Closes the avatar driving service.
Pauses Avatar playback.
Resumes 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:
  • data: The audio data to send
  • end: Whether this is the end of the audio stream
Returns: A conversation ID string.
Provides response audio received from your backend in Backend Mode.
Parameters:
  • data: The audio data
  • end: Whether this is the end of the audio stream
Returns: A conversation ID string.
Provides motion data payloads received from your backend in Backend Mode.
Parameters:
  • frames: Array of encoded motion data payloads
  • conversationID: The identifier returned by the matching yieldAudioData() call
Returns: Whether the payload completed the current conversation.
The point count of the current avatar.
The volume of playback.

AvatarView

A UIView subclass for rendering avatars.
Initializers
Creates a new avatar view with the specified avatar.
Parameters:
  • avatar: The avatar to display
Instance Properties
The controller for the avatar.
Callback when the Avatar is first rendered.
Transform for avatar content position and scale within the view.
Instance Methods
Pauses Avatar rendering.
Resumes Avatar rendering.
Returns whether rendering is enabled.
Returns the rendered Avatar bounds when available.

Render over an Avatar Background

Download the optional 16:9 background from Spatius Studio and add it to the Asset Catalog. Place the image and AvatarView in the same ZStack, with the image first. AvatarView is transparent by default, so the background shows through.
For square or portrait display windows, center this 16:9 stage inside a clipped outer view. See Avatar Background for the shared cropping rules.

Avatar

Represents an avatar instance.

Configuration

Configuration for AvatarKit.
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.
  • audioFormat: The audio format configuration
  • drivingServiceMode: The driving service mode
  • logLevel: The log level
  • renderQuality: Render quality tier

AudioFormat

Audio format configuration for AvatarKit.
Initializers
Creates a new audio format.
Parameters:
  • sampleRate: The audio sample rate in Hz. Defaults to 16000. Supported: 8000, 16000, 22050, 24000, 32000, 44100, 48000. Not used when inputAudioFormat is .opus: Opus always decodes at 48 kHz, so the session runs at 48000.
  • inputAudioFormat: The codec of the audio you feed into the SDK via send or yieldAudioData. .pcm (default) for raw PCM16, .opus for Opus. Fixed for the whole session; audio that does not match is reported as AvatarError.invalidAudioInput.
  • opusBitrate: Target bitrate in bits/sec for the uplink the SDK encodes. Defaults to 48000. Higher means better quality and a larger upload.
  • 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 in .backend mode, which has no uplink, or 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.

DrivingServiceMode

Driving service modes for AvatarKit.

AudioCodec

Codec of the audio the host feeds into the SDK.

RenderQuality

Render quality tiers for AvatarKit.

FrameStarvationMode

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

LogLevel

Log levels for AvatarKit.

ConnectionState

Connection states for AvatarKit.

ConversationState

Conversation states for AvatarKit.

Transform

Transform for avatar content rendering.
Initializers
Creates a new transform with the specified translation and scale.
Parameters:
  • x: The x-axis translation
  • y: The y-axis translation
  • scale: The scale factor

AvatarError

Avatar errors for AvatarKit.