Integration
Add the SDK dependency to yourbuild.gradle file:
Copy
implementation("ai.spatialwalk:avatarkit:1.0.0-beta26")
Usage
- SDK Driving Service Mode
- Host Driving Service Mode
Obtain app ID and temporary session token from Open Platform
1
Initialize SDK
Copy
AvatarSDK.initialize(
context = applicationContext,
appId = "your_app_id",
configuration = Configuration(
environment = Environment.intl,
audioFormat = AudioFormat(sampleRate = 16000),
drivingServiceMode = DrivingServiceMode.SDK,
logLevel = LogLevel.OFF
)
)
2
Provide Session Token
Copy
AvatarSDK.sessionToken = "your_session_token"
3
Load Avatar
Copy
lifecycleScope.launch {
try {
val avatar = withContext(Dispatchers.IO) {
AvatarManager.load("your_avatar_id") { progress -> }
}
} catch (e: Exception) {
// handle error
}
}
4
Create Avatar View
Copy
val avatarView = AvatarView(context)
avatarView.init(avatar, lifecycleScope)
5
Register Callbacks
Copy
val avatarController = avatarView.avatarController
avatarController?.onConnectionState = { connectionState -> }
avatarController?.onConversationState = { conversationState -> }
avatarController?.onError = { error -> }
6
Drive Avatar
Copy
// Start avatar service connection
avatarController?.start()
// Trigger new conversation by sending audio data stream
avatarController?.send(audioData1, end = false)
avatarController?.send(audioData2, end = true)
// Interrupt current conversation
avatarController?.interrupt()
// Close avatar service connection
avatarController?.stop()
Obtain app ID from Dashboard
1
Initialize SDK
Copy
AvatarSDK.initialize(
context = applicationContext,
appId = "your_app_id",
configuration = Configuration(
environment = Environment.intl,
audioFormat = AudioFormat(sampleRate = 16000),
drivingServiceMode = DrivingServiceMode.HOST,
logLevel = LogLevel.OFF
)
)
2
Load Avatar
Copy
lifecycleScope.launch {
try {
val avatar = withContext(Dispatchers.IO) {
AvatarManager.load("your_avatar_id") { progress -> }
}
} catch (e: Exception) {
// handle error
}
}
3
Create Avatar View
Copy
val avatarView = AvatarView(context)
avatarView.init(avatar, lifecycleScope)
4
Register Callbacks
Copy
val avatarController = avatarView.avatarController
avatarController?.onConnectionState = { connectionState -> }
avatarController?.onConversationState = { conversationState -> }
avatarController?.onError = { error -> }
5
Drive Avatar
Copy
// Trigger new conversation by yielding audio data stream
// The returned conversationID is required to associate animations
lifecycleScope.launch {
val conversationID = avatarController?.yield(audioData1, end = false) ?: ""
avatarController?.yield(audioData2, end = true)
// Yield animation data list from the server SDK integration
avatarController?.yield(animations1, conversationID)
avatarController?.yield(animations2, conversationID)
// Interrupt current conversation
avatarController?.interrupt()
}

