Skip to main content

AvatarSDK

Main initialization and configuration interface for AvatarKit.
abstract class AvatarSDK
Static Methods
Returns the app identifier.
static Future<String> appID()
Returns the configuration.
static Future<Configuration> configuration()
Returns the session token.
static Future<String> sessionToken()
Sets the session token used to authenticate avatars with the AvatarKit Server.
static Future<void> setSessionToken(String sessionToken)
Returns the user identifier provided by the developer.
static Future<String> userID()
Sets the user identifier provided by the developer to identify the user in the AvatarKit Log Service.
static Future<void> setUserID(String userID)
Returns a Boolean value that indicates whether AvatarKit supports the current device.
static Future<bool> supportsCurrentDevice()
Returns the version of AvatarKit.
static Future<String> version()
Initialize AvatarKit.
static Future<void> initialize({required String appID, required Configuration configuration})
Parameters:
  • appID: The app identifier
  • configuration: The configuration for AvatarKit
Measures the device’s computational performance for avatar rendering.
static Future<int> benchmark()
Returns: A performance score indicating the device’s capability.

AvatarManager

Manage avatar asset loading, caching, and retrieval.
class AvatarManager
Static Properties
The shared avatar manager instance.
static final AvatarManager shared
Instance Methods
Loads an avatar by ID.
Future<Avatar> load({required String id, void Function(double progress)? onProgress})
Parameters:
  • id: The avatar identifier
  • onProgress: Optional progress callback
Returns: The loaded Avatar instance.
Retrieves a cached avatar by ID.
Future<Avatar?> retrieve({required String id})
Parameters:
  • id: The avatar identifier
Returns: The cached Avatar if available, otherwise null.
Derives an avatar from a local asset path.
Future<Avatar> derive(String assetPath)
Parameters:
  • assetPath: The path to the avatar asset
Returns: The derived Avatar instance.
Clears cached data for a specific avatar.
Future<void> clear({required String id})
Parameters:
  • id: The avatar identifier to clear
Clears all cached avatar data.
Future<void> clearAll()
Gets the cache size for a specific avatar.
Future<int> getCacheSize({required String id})
Parameters:
  • id: The avatar identifier
Returns: The cache size in bytes.
Gets the total cache size for all avatars.
Future<int> getAllCacheSize()
Returns: The total cache size in bytes.

AvatarController

class AvatarController
Instance Properties
Callback when the avatar is first rendered.
void Function()? onFirstRendering
Callback for connection state changes.
void Function(ConnectionState state, String? errorMessage)? onConnectionState
Callback for conversation state changes.
void Function(ConversationState state)? onConversationState
Callback for error events.
void Function(AvatarError error)? onError
Instance Methods
Starts the avatar driving service connection.
Future<void> start()
Closes the avatar driving service.
Future<void> close()
Stops playback and terminates the current conversation.
Future<void> interrupt()
Sends audio to the avatar driving service.
Future<String> send(Uint8List audioData, {bool end = false})
Parameters:
  • audioData: The audio data to send
  • end: Whether this is the end of the audio stream (default: false)
Returns: A conversation ID string.
Yields audio from the host.
Future<String> yieldAudioData(Uint8List audioData, {bool end = false, AudioFormat? audioFormat})
Parameters:
  • audioData: The audio data
  • end: Whether this is the end of the audio stream (default: false)
  • audioFormat: The audio format (optional)
Returns: A conversation ID string.
Yields animations from the host.
Future<void> yieldAnimations(List<Uint8List> animations, {required String conversationID})
Parameters:
  • animations: List of animation data
  • conversationID: The conversation identifier
Returns the point count of the current avatar.
Future<int> pointCount()
Returns the volume of playback.
Future<double> volume()
Sets the volume of playback.
Future<void> setVolume(double volume)
Returns whether the widget is opaque.
Future<bool> isOpaque()
Sets whether the widget is opaque.
Future<void> setOpaque(bool opaque)
Returns the transform for avatar content position and scale within the widget.
Future<Transform> contentTransform()
Sets the transform for avatar content position and scale within the widget.
Future<void> setContentTransform(Transform transform)

AvatarWidget

class AvatarWidget extends StatelessWidget
Constructor
Creates a new avatar widget with the specified avatar.
const AvatarWidget({
  Key? key,
  required Avatar avatar,
  required void Function(AvatarController controller) onPlatformViewCreated,
})
Parameters:
  • avatar: The specified avatar
  • onPlatformViewCreated: Callback that provides the AvatarController instance when the platform view is created

Avatar

class Avatar
Instance PropertyTypeDescription
idStringThe avatar identifier.
assetPathStringThe local asset path of the avatar.

Configuration

Configuration for AvatarKit.
class Configuration
Constructor
Creates a new configuration with the specified parameters.
const Configuration({
  required Environment environment,
  AudioFormat audioFormat = const AudioFormat(),
  DrivingServiceMode drivingServiceMode = DrivingServiceMode.sdk,
  LogLevel logLevel = LogLevel.off,
})
Parameters:
  • environment: The environment to use
  • audioFormat: The audio format configuration
  • drivingServiceMode: The driving service mode
  • logLevel: The log level
Instance PropertyTypeDescription
environmentEnvironmentEnvironment for AvatarKit.
audioFormatAudioFormatAudio format for AvatarKit.
drivingServiceModeDrivingServiceModeDriving service mode for AvatarKit.
logLevelLogLevelLog level for AvatarKit.

Environment

Environments for AvatarKit.
enum Environment
CaseDescription
intlInternational environment.
cnChina environment.

AudioFormat

Audio format configuration for AvatarKit.
class AudioFormat
Constructor
Creates a new audio format with the specified sample rate.
const AudioFormat({int sampleRate = 16000})
Parameters:
  • sampleRate: The audio sample rate in Hz (default: 16000)
Instance PropertyTypeDescription
sampleRateintThe audio sample rate in Hz.
channelCountintThe number of audio channels. Fixed to 1 for mono.

DrivingServiceMode

Driving service modes for AvatarKit.
enum DrivingServiceMode
CaseDescription
sdkThe SDK handles driving service internally.
hostThe host application handles driving service.

LogLevel

Log levels for AvatarKit.
enum LogLevel
CaseDescription
offDisable logging.
errorLog errors only.
warningLog warnings and errors only.
allLog all messages.

ConnectionState

Connection states for AvatarKit.
enum ConnectionState
CaseDescription
disconnectedThe connection has been closed.
connectingThe connection is being established.
connectedThe connection is active.
failedThe connection failed.

ConversationState

Conversation states for AvatarKit.
enum ConversationState
CaseDescription
idleNo active conversation.
pausedThe conversation is paused.
playingThe avatar is playing audio/animation.

Transform

Transform for avatar content rendering.
class Transform
Constructor
Creates a new transform with the specified translation and scale.
const Transform({double x = 0.0, double y = 0.0, double scale = 1.0})
Parameters:
  • x: The x-axis translation (default: 0.0)
  • y: The y-axis translation (default: 0.0)
  • scale: The scale factor (default: 1.0)
Static PropertyTypeDescription
identityTransformThe identity transform.
Instance PropertyTypeDescription
xdoubleThe x-axis translation.
ydoubleThe y-axis translation.
scaledoubleThe scale factor.

AvatarError

Avatar errors for AvatarKit.
enum AvatarError
CaseDescription
appIDUnrecognizedThe app ID is not recognized.
avatarIDUnrecognizedThe avatar ID is not recognized.
avatarAssetMissingThe avatar asset is missing.
sessionTokenInvalidThe session token is invalid.
sessionTokenExpiredThe session token has expired.
failedToFetchAvatarMetadataFailed to fetch avatar metadata.
failedToDownloadAvatarAssetsFailed to download avatar assets.