Skip to main content

Quick Reference

Important: App ID and Session Token are paired and must be used together. Each App ID corresponds to a specific list of avatars that can be driven. You must obtain both App ID and Session Token from the SpatialReal Studio.

AvatarSDK

Main entry point for SDK initialization and global configuration.

Static Properties

Static Methods

initialize(appId, configuration)

Initialize the SDK. Must be called before any other operations.

setSessionToken(token)

Set session token for authentication. Only required for SDK Mode (server-driven animation).
Important:
  • Only needed for SDK Mode - not required for Host Mode or RTC Mode
  • Token must be obtained from your backend server
  • Token has max 24 hours validity
  • Token must be paired with App ID

setUserId(userId)

Set user ID for logging and analytics.

cleanup()

Release all SDK resources. Call when SDK is no longer needed.

AvatarManager

Handles avatar loading and caching.

Static Properties

Instance Methods

load(id, onProgress?)

Load an avatar by ID.
Parameters: Returns: Promise<Avatar | null>

clearAll()

Clear all cached avatar resources.

AvatarView

3D rendering view that displays the avatar.

Constructor

⚠️ Important: The container element MUST have non-zero width and height. The canvas will automatically fill the container size.

Instance Properties

Instance Methods

dispose()

Clean up view resources. Call when view is no longer needed.

AvatarController

Handles real-time communication with the avatar service.

Instance Properties

Event Callbacks

Instance Methods

initializeAudioContext()

Initialize audio context. MUST be called in user gesture context.

start()

Connect to the avatar service. SDK mode only.

send(audioData, end)

Send audio data to server. SDK mode only.
Audio data byte length must be even (2 bytes per sample). Odd-length data will cause a server-side validation error and WebSocket disconnect.
Returns: string - Conversation ID

close()

Close service connection. SDK mode only.

Host Mode Methods

For Host Mode (DrivingServiceMode.host) only:

yieldAudioData(audioData, end)

Provide audio data in Host Mode.

yieldFramesData(frames, conversationId)

Provide animation frames in Host Mode.

Common Methods (Both Modes)

pause()

Pause current playback.

resume()

Resume paused playback.

interrupt()

Interrupt current playback and clear data.

clear()

Clear all data and resources.

getCurrentConversationId()

Get the current active conversation ID.

volume

Playback volume property (avatar audio only, not system volume). Range: 0.0 to 1.0.

Types and Enums

Configuration

Environment

DrivingServiceMode

LogLevel

ConnectionState

ConversationState

LoadProgressInfo

AudioFormat


Error Codes


Complete Usage Example