Android SDK
ⅠPreparation
1 Overview
This document serves as the integration guide for the Embodia.ai Embodied Driving SDK Android version. It is intended to guide the usage of the SDK. It assumes that the reader is familiar with the basic use of IDEs (Eclipse or Android Studio) and possesses a foundational knowledge of Android programming.
2 Quick Demo Experience
APK File: The APK file included in the Android package is the installer for the digital human demo. You can install it directly on an Android phone to quickly experience its performance on your device. Access Links:
- GitHub: https://github.com/publicize0828/XmovLiteAvatarAndroidDemo
- Gitee: https://gitee.com/xmovmaster/XmovLiteAvatarAndroidDemo
Sample Project: The demo folder in the Android package contains the digital human sample project. Open the project with Android Studio and follow these steps to configure and run it:
1. Replace the appId and appSecret in demo_configs.json.
2. Configure the settings in demo_configs.json as needed.
3. MockAudioInputsData.json is a sample format for providing custom audio data inputs.
3 Development Environment Setup
(1) Copy SDK to Project:
Copy the .aar package from the libs directory of the SDK into your project's libs directory (create one if it doesn't exist). In the dependencies section of your app's build.gradle, add the dependency as follows:
implementation files('libs/xmovdigitalhuman-xxx.aar')
(2) Add External Third-Party Dependencies:
implementation "javax.vecmath:vecmath:1.5.2"
implementation "com.google.code.gson:gson:2.13.1"
implementation "com.squareup.okhttp3:okhttp:5.1.0"
implementation "org.msgpack:msgpack-core:0.9.3"
implementation "io.socket:socket.io-client:2.1.0"
(3) Configure AndroidManifest.xml:
Add necessary permissions within the <manifest> tag.
<uses-permission android:name="android.permission.INTERNET"/>
(4) ProGuard Rules:
-keep public class com.xmov.metahuman.sdk.data. {;}
-keep public class com.xmov.metahuman.sdk.impl.data. {;}
-keep public class com.xmov.metahuman.sdk.impl.transport.http. {;}
-keep public interface com.xmov.metahuman.sdk.IXmovAvatar {;}
-keep class com.xmov.metahuman.sdk.IXmovAvatar$Companion { ;}
-keep public interface com.xmov.metahuman.sdk.IAvatarListener {
public protected <methods>;
}
-keep public interface com.xmov.metahuman.sdk.PreCacheListener {
public protected ;
}
Ⅱ SDK Usage Instructions
1 Initialization
You must initialize the SDK before using any of its functions.
1.1 Method Prototype
fun init(
context: Context,
layout: ViewGroup,
initConfig: InitConfig,
listener: IAvatarListener?
)
Parameter Description
Parameter | Type | Description |
|---|---|---|
context | Context | Generally passes the Activity object |
layout | ViewGroup | The parent layout where the digital human is loaded |
initConfig | InitConfig | Initialization configuration class |
listener | IAvatarListener | Callback listener |
InitConfig Class Details
Parameter | Type | Description |
appId | String | The appId corresponding to the application in Embodia.ai |
appSecret | String | The appSecret corresponding to the application in Embodia.ai |
gatewayServer | String | Session entry address: |
config | String | JSON string for setting various configuration items |
Initialization Sample Code
IXmovAvatar.get().init(this, mBinding.avatarLayout, initConfig.appId, initConfig.appSecret, initConfig.gatewayServer, object : IAvatarListener {
override fun onInitEvent(code: Int, message: String?) {
// Initialization result callback
LogUtil.d("onInitEvent code: $code, message: $message")
}
override fun onWidgetEvent(widgetData: IRawEventFrameData?) {
// Callback for widget events (e.g., subtitles)
LogUtil.d("onWidgetEvent widgetData: $widgetData")
}
override fun onNetworkInfo(sdkNetworkInfo: SDKNetworkInfo?) {
// Callback for network latency and speed
LogUtil.d("onNetworkInfo $sdkNetworkInfo")
}
override fun onMessage(sdkMessage: SDKMessage?) {
// General SDK message callback
LogUtil.d("onMessage $sdkMessage")
}
override fun onStateChange(state: String?) {
// Callback when digital human state changes
LogUtil.d("onStateChange $state")
}
override fun onStatusChange(status: SDKStatus?) {
// Callback when SDK connection status changes
LogUtil.d("onStatusChange $status")
}
override fun onStateRenderChange(state: String?, duration: Long) {
// Time taken from state change to rendering
LogUtil.d("onStateRenderChange state: $state, duration: $duration")
}
override fun onVoiceStateChange(status: String?) {
// Callback for audio playback status
LogUtil.d("onVoiceStateChange status: $status")
runOnUiThread {
if ("voice_end" == status) {
// Speech finished
} else if ("voice_start" == status) {
// Speech started
}
}
}
override fun onDebugInfo(debugInfo: JSONObject) {
// Debug information callback
}
override fun onReconnectEvent(code: Int, message: String?) {
// Callback for reconnection attempt
toast("Reconnecting: code=$code message=$message")
}
override fun onOfflineEvent() {
// Triggered when entering offline mode
toast("Entered offline mode")
}
})
1.2 Detailed Callback Descriptions
(1) Initialization Callback
onInitEvent(code: Int, message: String?)
The return parameters of the method are divided into the outer code and result, with the following meanings:
Field | Type | Meaning |
|---|---|---|
code | Int | Code 0: Success; Others: Failure |
message | String | Return information |
(2) Event Callback (Subtitle Callback)
onWidgetEvent(widgetData: IRawEventFrameData?)
IRawEventFrameData Entity Class
Field | Type | Meaning |
|---|---|---|
startFrame | Int | Start frame |
event | JSONArray | type: "subtitle_on" (subtitle type), text: subtitle content |
(3) Voice Broadcast Callback
onVoiceStateChange(status: String?)
Field | Type | Meaning |
status | String | "voice_start": Broadcast started; "voice_end": Broadcast finished |
(4) Reconnection Online Mode Callback
onReconnectEvent(code: Int, message: String?)
Field | Type | Meaning |
code | Int | Code 0: Success; Others: Failure |
message | String | Return information |
2 config Configuration
The config in InitConfig is a JSON string used for customization.
Field | Data Type | Description | Sample Value |
|---|---|---|---|
input_audio | boolean | Enable custom audio input. true: custom input; false: SDK internal input | FALSE |
output_audio | boolean | Enable SDK internal audio output. true: use SDK output; false: do not use SDK output | TRUE |
resolution | JSONObject | Resolution configuration object defining width and height | {"height": 1920, "width": 1080} |
resolution.height | number | Image height in pixels (px) | 1920 |
resolution.width | number | Image width in pixels (px) | 1080 |
init_events | JSONArray | List of initialization events for preset operations | See example below |
init_events[0].type | string | Type of init event. SetCharacterCanvasAnchor sets the anchor | SetCharacterCanvasAnchor |
init_events[0].x_location | number | X-axis offset for anchor (defaults to horizontal center) | 0 |
init_events[0].y_location | number | Y-axis offset for anchor (unit: px) | 0 |
init_events[0].width | number | Width scale for anchor area | 1 |
init_events[0].height | number | Height scale for anchor area | 1 |
Configuration Example
{
"input_audio": false,
"output_audio": true,
"resolution": {
"width": 1080,
"height": 1920
},
"init_events": [
{
"type": "SetCharacterCanvasAnchor",
"x_location": 0,
"y_location": 0,
"width": 1,
"height": 1
}
]
}
3 Speak
Method Prototype
fun speak(ssml: String?, isStart: Boolean, isEnd: Boolean)
Parameter Description
Parameter | Type | Description |
|---|---|---|
ssml (Required) | String | Text or SSML content to be spoken |
isStart (Required) | boolean | Whether this is the start of the message |
isEnd (Required) | boolean | Whether this is the end of the message |
Code Examples
Full Text Input:
IXmovAvatar.get().speak("Welcome to Embodia.ai", true, true)
Streaming Text Input:
// Start
IXmovAvatar.get().speak("msg segment 1", true, false)
// Middle
IXmovAvatar.get().speak("msg segment 2", false, false)
...
// End
IXmovAvatar.get().speak("msg final segment", false, true)
4 Reconnection
The SDK supports automatic switching to offline mode when the network is unstable. Reconnection starts automatically when the network is restored. Manual switching is also supported. Note: Reconnection can only be initiated from an offline state.
Method Prototype
fun switchModel(isOffline: Boolean)
Parameter Description
Parameter | Type | Description |
|---|---|---|
isOffline | Boolean | true: switch to offline mode; false: reconnect to online mode |
5 Destroy
Destroys the SDK instance and releases resources. Call this when the digital human exits.
IXmovAvatar.get().destroy()
Ⅲ Digital Human States
Common action/state switching for the digital human:
1. Listen: IXmovAvatar.get().listen()
2. Think: IXmovAvatar.get().think()
3. Interrupt: IXmovAvatar.get().interrupt()
Ⅳ Return Codes
These codes represent the internal status of the digital human SDK.
Return Code | Description |
|---|---|
0 | Success |
1000 | No room available |
1001 | Initialization failed: SDK is already initialized |
2000 | State operation attempted before successful initialization |
3000 | Reconnection attempt failed: SDK must be in offline state to reconnect |