# Close all sessions Source: https://docs.duix.com/api-reference/close-all-sessions GET /distroyCallSessionsByAppId Terminate all active sessions for a specific app. # Close session Source: https://docs.duix.com/api-reference/close-session GET /sessionStop Terminate a active sessions by its session ID. # Create avatar Source: https://docs.duix.com/api-reference/create-avatar POST /createAvatar Create an avatar # Get conversation details Source: https://docs.duix.com/api-reference/get-conversation-details GET /getConversationById Query conversation details by providing the conversation ID. # Query account Source: https://docs.duix.com/api-reference/query-account GET /queryAccount Query user account information. # Query creation status Source: https://docs.duix.com/api-reference/query-creation GET /queryAvatar Query avatar creation status about the AI avatar using its unique taskId. # Get concurrency Source: https://docs.duix.com/api-reference/real-time-concurrency GET /getconcurrentNumber Retrieve the real-time concurrency status of an application # Get sessions Source: https://docs.duix.com/api-reference/real-time-sessions GET /getconcurrentList Retrieve a list of all active (in-call) sessions for an app. # API reference Source: https://docs.duix.com/documentation/api-reference # duix-avatar-conversation Source: https://docs.duix.com/documentation/duix-avatar-conversation # duix-avatar-video-generation Source: https://docs.duix.com/documentation/duix-avatar-video-generation # Get conversation ID Source: https://docs.duix.com/documentation/get-conversation-id Learn how to retrieve your conversation ID from the Interactive AI Avatar dashboard for API integration. ## Overview Each **Conversation ID** uniquely identifies a specific Interactive AI avatar session.\ You’ll use this ID to connect and interact programmatically with your avatar through the **Duix API**. *** ## How to Retrieve Your Conversation ID Follow the steps below to obtain your Conversation ID from the Duix dashboard. ### Step 1: Locate Your Avatar Card Open the **Interactive AI Avatar Dashboard** and find the avatar card associated with the conversation you want to access. ### Step 2: Copy the Conversation ID 1. Locate the **Copy ID** button in the bottom-right corner of the avatar card. 2. Click **Copy ID** to copy the conversation ID to your clipboard. The **Copy ID** button instantly copies the Conversation ID to your clipboard, allowing you to paste it directly into your code or API requests. *** ## Next Steps With your **Conversation ID** ready, you can start integrating it into your API workflows: * [Get Your API Keys](/documentation/get-your-api-keys) # Get token Source: https://docs.duix.com/documentation/get-token The access token authenticates API requests to Duix interactive services. Include the token in the HTTP header for all API calls. ## Overview The **access token** serves as the authentication credential for all Duix interactive service APIs.\ Each HTTP request must include the token in the **Authorization Header**. *** ## How to Generate an Access Token ### Prerequisites Before generating a token, ensure you have the following: * **appId** — The unique identifier of your application. * **appKey** — The secret key associated with your application. *** ### Steps to Generate a Token 1. Generate a **JWT signature** using your `appId` and `appKey`. 2. Pass the generated signature to the H5 SDK `init` method. *** ## Signature Generation The signature is implemented using **JWT (JSON Web Token)**.\ Use the following parameters and example code to generate a valid signature. ### Parameters | Name | Type | Description | Example | | ------ | ------- | -------------------------------------------------- | --------- | | appId | string | Application identifier obtained after registration | `xxxxxxx` | | appKey | string | Application secret key obtained after registration | `xxxxxxx` | | sigExp | integer | Signature validity period (in seconds) | `1800` | *** ## Example: Java Implementation ### Add Maven Dependency ```xml theme={null} com.auth0 java-jwt 3.8.3 ``` ```java theme={null} import com.auth0.jwt.JWT; import com.auth0.jwt.algorithms.Algorithm; import java.util.Calendar; import java.util.Date; public class SigUtils { /** * Create JWT Signature * * @param appId Application ID * @param appKey Application Secret Key * @param sigExp Signature validity duration (seconds) * @return JWT signature string */ public static String createSig(String appId, String appKey, int sigExp) { Calendar nowTime = Calendar.getInstance(); nowTime.add(Calendar.SECOND, sigExp); Date expiresDate = nowTime.getTime(); return JWT.create() // Issued time .withIssuedAt(new Date()) // Expiration time .withExpiresAt(expiresDate) // Payload data .withClaim("appId", appId) // Sign using HMAC256 with appKey .sign(Algorithm.HMAC256(appKey)); } } ``` Note: This token is the H5 SDK signature value (`sign`). ### Integration Once you have your appId, appKey, and generated token, follow the SDK and API guides to connect Duix to your application. # Get API keys Source: https://docs.duix.com/documentation/get-your-api-keys Learn how to generate and manage your Duix API keys for secure authentication with Duix services. ## Overview **API keys** are the credentials used to authenticate your application with **Duix services**.\ They allow you to send authorized API requests and manage Interactive AI avatars programmatically. Never share your API keys publicly. Treat them like passwords and store them securely — for example, in environment variables or a secrets manager. *** ## Retrieve Your API Keys Follow the steps below to generate and manage your API keys from the Duix dashboard. ### Step 1: Access Your Duix Dashboard 1. Log in to the [Duix website](https://www.duix.com). 2. Open your workspace by either: * Using the navigation bar at the top of the page, or * Clicking your profile avatar and selecting **Settings** from the dropdown menu. *** ### Step 2: Open API Key Settings 1. In your **My Duix** workspace, navigate to **Settings**. 2. Select the **API Keys** tab to open the key management page. *** ### Step 3: Generate New API Keys 1. Click **Generate** to create a new API key pair. 2. Copy both keys immediately and store them in a secure location — they will not be displayed again. 3. Use these keys when authenticating API or SDK requests. # Introduction Source: https://docs.duix.com/documentation/introduction # Explore the Duix Take a look at our **Documentation** and **API Reference** to learn how to build with Duix. Manage your API keys, conversations, and avatars. Create and test configurations before integrating them into your app. Need assistance? Contact our support team — we’ll help you get unblocked quickly. *** # Getting Started ## Prerequisites and Support All Duix plans — including the **Free Plan** — provide access to our **API (Application Programming Interface)**. The API enables you to integrate Duix features directly into your own applications. In this section, you’ll learn how to create your **first Duix session** by making API calls. > **Note:** > The Duix web app uses the same APIs as the SDK. > With identical settings, results should be similar; however, generation is **non-deterministic**, so slight variations may occur. *** ## Billing and usage You’ll need available **conversation minutes** in your account to start or use a session through the API. You can either: * Purchase a paid plan — see [Pricing](https://www.duix.com/pricing), or * Begin with the **free quota** to explore and test the workflow. *** ## What you’ll learn This section provides a **quick overview** with examples designed to help you become productive quickly and understand the full scope of the Duix API. # SDKs docs Source: https://docs.duix.com/documentation/sdk # Code sample Source: https://docs.duix.com/documentation/sdk-demo # Precautions Source: https://docs.duix.com/sdks/android/be-careful Important considerations for using the Duix Android SDK, including microphone permissions and audio format requirements. ## Overview Before running the **Duix Android SDK**, please review the following important notes.\ Failure to meet these requirements may cause initialization or audio transmission failures. *** 1. Microphone Permission The **RTC (Real-Time Communication)** module requires access to the device’s microphone.\ You must request and obtain this permission **dynamically at runtime** before initializing or using any real-time interaction feature. 2. Audio Format When providing audio input, use **WAV files** with the following specifications: * **Sample rate:** 16,000 Hz * **Channel:** Mono * **Bit depth:** 16-bit # Add dependencies Source: https://docs.duix.com/sdks/android/dependent Integrate the Duix Android SDK by adding the required AAR package and Gradle dependencies. ## Overview This section explains how to import the **Duix Android SDK** into your project\ and configure all necessary dependencies for MQTT, WebRTC, and JWT authentication. # Add Dependencies 1. **Import the SDK Package**\ Download the AAR package named `duix_cloud_sdk_release_${version}.aar`.\ Create a `libs` directory under your app module, and place the AAR file inside. 2. **Configure Gradle**\ Add the following dependency settings to your module’s `build.gradle` file: ```gradle theme={null} dependencies { implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs') implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5' implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' implementation "org.webrtc:google-webrtc:1.0.32006" implementation 'com.auth0:java-jwt:3.18.1' } ``` # Download and installation (Android) Source: https://docs.duix.com/sdks/android/download Download and set up the Duix Android SDK demo project to quickly test real-time digital human capabilities. ## Overview This guide explains how to download and run the **Duix Android demo project**, which showcases real-time digital human rendering, speech interaction, and SDK initialization within an Android environment. *** ## Step 1: Download the Sample Project Click below to download the latest **Duix Android demo** package: 👉 [**duix-cloud-global-demo\_1.3.0.zip**](https://duix-sgp.obs.ap-southeast-3.myhuaweicloud.com/duix/sdk/duix-cloud-global-demo_1.3.0.zip) > **Note:** > The demo project includes all required SDK dependencies and Gradle configuration for quick testing. *** ## Step 2: Open in Android Studio 1. Extract the downloaded `.zip` file. 2. Open the extracted project in **Android Studio (version 2021.3 or later)**. 3. Wait for Gradle to sync automatically. 4. Verify that your **Android SDK version** is **API Level 29 or higher**. *** ## Step 3: Build and Run 1. Connect an Android device or start an emulator. 2. Click **Run ▶️** in Android Studio to launch the demo. 3. The digital human should appear and respond once initialization completes. *** ## Environment Requirements | Component | Minimum Version | Notes | | ------------------ | ------------------- | ------------------------------------------ | | **Android Studio** | 2021.3 (Arctic Fox) | Required for Gradle 7+ compatibility | | **Android SDK** | API Level 29+ | Recommended API Level 33+ | | **JDK** | 11+ | Ensure JAVA\_HOME is set correctly | | **Network** | HTTPS (TLS 1.2+) | Required for WebRTC and SDK initialization | *** ## Troubleshooting * **Gradle Sync Failed?** Ensure your network allows Maven Central and Google repositories. * **Build Failed?** Try selecting “Sync Project with Gradle Files” and cleaning the build. * **App Crash at Launch?** Confirm camera and microphone permissions are granted. * **Network Timeout?** Ensure your device can access `duix.com` over HTTPS. # Key interfaces Source: https://docs.duix.com/sdks/android/interface # Key Interfaces ### 1). Initialization Initialize the SDK with your `appId` and `appSecret`, then obtain a `Player` instance: ```kotlin theme={null} VirtualFactory.init("your appId", "your appSecret") player = VirtualFactory.getPlayer(mContext, eglBaseContext) ``` ### 2) Connect to the digital human Connect using your platform `conversationId`: ``` player?.addCallback(callback) player?.connect("your conversation id") ``` The player exposes the following callbacks: #### `onShow` — Digital human is ready to display ``` void onShow(); ``` #### `onError` — Error occurred during connection ``` void onError(int msgType, int msgSubType, String msg); ``` Parameters: | Parameter Name | Type | Description | | -------------- | ------ | ----------------- | | msgType | int | Error type | | msgSubType | int | Sub-error type | | msg | String | Exception message | Possible `msgType` values: | Value | Description | | | ----- | ------------------------------------ | - | | 1000 | Authorization exception | | | 1001 | Session creation exception | | | 1002 | Resource retrieval exception | | | 1010 | IM connection creation failed | | | 1011 | Rendering service returned exception | | | 1020 | RTC status exception | | | 1030 | Rendering service actively closed | | | 1040 | IM connection lost | | | 1050 | RTC connection lost | | #### `onVideoTrack` — RTC media channel created successfully Bind your digital human view to the track in this callback ``` void onVideoTrack(VideoTrack track); ``` | Parameter Name | Type | Description | | -------------- | ---------- | ----------------- | | track | VideoTrack | Video media track | #### `onAudioSamples` — Local audio sampling data callback Use this callback for audio visualization or processing. ``` default void onAudioSamples(int audioFormat, int channelCount, int sampleRat, byte[] data){} ``` #### `onTtsSpeakStart` — TTS playback started ``` default void onTtsSpeakStart(){} ``` #### `onTtsSpeakText` — TTS text content ``` default void onTtsSpeakText(String text){} ``` #### `onTtsSpeakStop` — TTS playback completed ``` default void onTtsSpeakStop(){} ``` #### `onSpeakStart` — Speaking started ``` default void onSpeakStart(){} ``` #### `onSpeakText` — Spoken text content ``` default void onSpeakText(String text){} ``` #### `onSpeakStop` — Speaking completed ``` default void onSpeakStop(){} ``` #### `onAsrResult` — ASR recognition result ``` default void onAsrResult(String text, boolean sentenceEnd){} ``` ### 3) Drive the digital human to speak with an audio URL Use a WAV audio URL with 16 kHz sample rate, 16‑bit, mono channel to drive speech ```kotlin theme={null} player?.speakWithWav(wavUrl, true) ``` | Parameter Name | Type | Description | | -------------- | ------- | ----------------------------------------------- | | wavUrl | String | URL of the WAV audio file | | interrupt | boolean | Whether to interrupt the current speaking state | ### 4) Drive the digital human to speak with text Provide text input. The digital human will speak using the session’s configured voice. ```kotlin theme={null} player?.speakWithTxt(text, true) ``` | Parameter Name | Type | Description | | -------------- | ------- | ----------------------------------------------- | | text | String | Text for the digital human to speak | | interrupt | boolean | Whether to interrupt the current speaking state | ### 5) Q\&A Interaction Ask a question and receive a response from the digital human. ```kotlin theme={null} player?.speakWithQuestion(text, true) ``` | Parameter Name | Type | Description | | -------------- | ------- | ----------------------------------------------- | | text | String | Express your question to the digital human | | interrupt | boolean | Whether to interrupt the current speaking state | ### 6) Interrupt speaking Stop the current speech immediately. ```kotlin theme={null} player?.stopAudio() ``` # Proguard configuration Source: https://docs.duix.com/sdks/android/proguard Proguard rules required to prevent essential Duix SDK classes from being obfuscated during release builds. ## Overview When building a **release version** of your app with code shrinking or obfuscation enabled\ (e.g., using **Proguard** or **R8**), certain SDK dependencies must be excluded from obfuscation\ to ensure stable runtime behavior. Add the following rules to your project’s **`proguard-rules.pro`** file: *** ```proguard theme={null} # Prevent WebRTC classes from being obfuscated -keep class org.webrtc.** { *; } # Preserve MQTT client classes -keep class org.eclipse.paho.client.** { *; } -keep class org.eclipse.paho.uri.** { *; } # (Optional) Preserve Duix SDK classes if referenced by reflection -keep class com.guiji.sdk.** { *; } ``` # Quick start Source: https://docs.duix.com/sdks/android/quickstart Kotlin example showing how to initialize and start a Duix Android SDK session for real-time digital human interaction. ## Overview This **Quick Start** guide demonstrates how to initialize the **Duix Android SDK**,\ set up rendering, and establish a real-time connection with the digital human.\ Before integration, ensure your app requests **microphone permission dynamically at runtime**,\ as it is required for real-time voice communication. *** ## Example Code (Kotlin) ```kotlin theme={null} class DisplayActivity : BaseActivity() { private var eglBaseContext = EglBase.create().eglBaseContext override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // Initialize the view binding.render.init(eglBaseContext, null) binding.render.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL) binding.render.setMirror(false) binding.render.setEnableHardwareScaler(false) // Initialize SDK VirtualFactory.init("your appId", "your appSecret") // Create player instance player = VirtualFactory.getPlayer(mContext, eglBaseContext) // Register callbacks player?.addCallback(object : Player.Callback { override fun onShow() { // Digital human is ready to display } override fun onError(msgType: Int, msgSubType: Int, msg: String?) { // Log connection error } override fun onAsrResult(text: String?, sentenceEnd: Boolean) { // Handle ASR result } override fun onVideoTrack(track: VideoTrack) { runOnUiThread { // Bind track to the digital human view track.addSink(binding.render) } } }) // Connect to the digital human player?.connect("your conversation id") } override fun onDestroy() { super.onDestroy() // Release resources player?.release() binding.render.release() } } ``` ## How It Works 1. **Initialize EGL context**\ The `EglBaseContext` is used to handle **OpenGL rendering** for the digital human view. 2. **Initialize SDK**\ Call `VirtualFactory.init(appId, appSecret)` before creating a player instance. 3. **Create Player Instance**\ The `VirtualFactory.getPlayer()` method returns a `Player` object that manages **RTC sessions** and **digital human rendering**. 4. **Register Callbacks**\ The `Player.Callback` interface provides hooks for **video display**, **ASR recognition**, and **error handling**. 5. **Connect to Session**\ Use `player.connect(conversationId)` to start interacting with the digital human in real time. 6. **Clean Up**\ Release resources in `onDestroy()` to prevent **memory leaks**. *** ## Notes * The **microphone permission** must be granted before calling `VirtualFactory.getPlayer()`. * The digital human video stream uses **WebRTC** under the hood — ensure your device supports it. * For stable rendering, set `SCALE_ASPECT_FILL` and disable hardware scaling if visual artifacts occur. * Network interruptions or invalid credentials may trigger callback errors in `onError()`. *** > **Now!**\ > You can have a **real-time voice conversation** with the digital human through your device’s microphone. # Code examples Source: https://docs.duix.com/sdks/h5/code Demonstration of initializing and starting a Duix Avatar session using the Web SDK. # Code Examples ## Description This example demonstrates how to **initialize**, **authenticate**, and **start** a Duix real-time avatar session using the **Web SDK**.\ It includes event listeners for ASR (speech recognition), subtitles, and conversation lifecycle events. > Note: The CDN demo version may not be the latest. For production use, install the SDK via **npm** to ensure compatibility and security. *** ## Example: Basic HTML Integration ```html theme={null} Duix SDK Simple Example
``` ## Usage Notes > **Tip:**\ > Always generate the `sign` securely on your backend. Never expose API credentials or tokens in client-side code. > **Note:**\ > Some mobile browsers block autoplay of audio or video without user interaction.\ > If the avatar does not render immediately, trigger `duix.start()` within a user gesture event such as `onclick` or `onTap`. > **Warning:**\ > This demo omits advanced error handling, concurrency control, and resource cleanup.\ > For production use, wrap SDK calls in `try/catch` blocks, manage sessions through your backend, and call `duix.stop()` when the conversation ends to release resources properly. # Events Source: https://docs.duix.com/sdks/h5/events List of all Duix SDK events and their corresponding payload structures. ## Overview The Duix SDK emits various **events** throughout the session lifecycle. Developers can listen to these events using the `duix.on(eventName, callback)` method to handle errors, progress updates, speech synchronization, and RTC quality monitoring. *** ## Event Summary | Event Name | Description | | ------------------ | ----------------------------------------------------- | | **error** | Uncaught error occurred | | **bye** | Session ended | | **initialSuccess** | Initialization successful — safe to call `start()` | | **show** | Digital human is displayed | | **progress** | Loading progress (0–100) | | **speakSection** | Current incremental audio/text segment while speaking | | **speakStart** | Speech playback started | | **speakEnd** | Speech playback ended | | **asrStart** | Single-sentence ASR started | | **asrData** | Single-sentence ASR interim result | | **asrStop** | Single-sentence ASR ended | | **report** | Periodic RTC/network/video quality report | | **cameraChange** | Camera current status | *** ## Event Details ### 1. `error` Triggered when an unexpected error occurs. **Payload** ```javascript theme={null} { code: "", // Error code message: "", // Error message data: {} // Additional error data } ``` ***Error codes*** | Name | Description | data | | :--- | :------------------------------ | :----------------------------------------------------- | | 3001 | RTC connection failed | | | 4001 | Failed to start session | | | 4005 | Authentication failed | | | 4007 | Server session abnormally ended | code: 100305 Model file not found | | 4008 | Failed to get microphone stream | | | 4009 | Browser blocked autoplay | Start muted or require user action; then unmute/resume | ### progress Indicates the current loading progress of the digital human and its resources. Returns a numeric value between 0 and 100. Payload: number Example ```js theme={null} duix.on('progress', (value) => { console.log(`Loading progress: ${value}%`); }); ``` ### speakSection Emitted for each incremental speech segment — typically used for real-time subtitles or streaming speech visualization. When answer() is used, this event streams continuously; for speak(), it aligns with speakStart. Payload ```js theme={null} { "audio": "string", // Audio stream URL "content": "string" // Partial text content currently being spoken } ``` Example ```js theme={null} duix.on('speakSection', (data) => { console.log('Current segment:', data.content); }); ``` ### speakStart Triggered when the avatar begins speech playback. Payload ```js theme={null} { "audio": "string", // Audio stream URL "content": "string" // Text content being spoken } ``` Example ```js theme={null} duix.on('speakStart', (data) => { console.log('Speech started:', data.content); }); ``` ### speakEnd Triggered when the avatar completes speech playback. Useful for synchronizing UI transitions or logic after speech completion. Payload ```js theme={null} { "audio": "string", "content": "string" } ``` Example ```js theme={null} duix.on('speakEnd', () => { console.log('Speech ended.'); }); ``` ### asrData Triggered during active speech recognition (ASR). Each ASR cycle starts with asrStart and ends with asrStop. Use this event to display incremental transcription results. Payload ```js theme={null} { "content": "string" // Recognized text fragment } ``` Example ```js theme={null} duix.on('asrData', (data) => { console.log('Recognized:', data.content); }); ``` ### report Delivers a detailed periodic (once per second) network and video quality report. This event helps developers monitor RTC connection quality and performance metrics in real time. Payload ```js theme={null} { "video": { "download": { "frameWidth": 1920, // Video width "frameHeight": 1080, // Video height "framesPerSecond": 24, // Frame rate "packetsLost": 0, // Total lost packets "packetsLostPerSecond": 0 // Packet loss rate per second } }, "connection": { "bytesSent": 206482, // Total bytes sent "bytesReceived": 79179770, // Total bytes received "currentRoundTripTime": 3, // Round-trip latency (ms) "timestamp": 1688043940523, // UNIX timestamp "receivedBitsPerSecond": 2978472, // Download bitrate (bits/s) "sentBitsPerSecond": 7920 // Upload bitrate (bits/s) } } ``` Example ```js theme={null} duix.on('report', (stats) => { console.log('Network report:', stats.connection); }); ``` ### cameraChange Payload ```javascript theme={null} { status: 'show', // camera status, show/hidden } ``` Example ```js theme={null} duix.on('cameraChange', (data) => { console.log('cameraChange:', data.status); }); ``` **Note:** Event payloads not explicitly documented above will return empty objects. Register all event listeners before invoking `duix.start()`. # Methods Source: https://docs.duix.com/sdks/h5/methods Full list of available methods in the Duix H5 SDK, including initialization, playback control, speech interaction, ASR, and session management. ## Overview The Duix SDK exposes a set of core methods for initializing, controlling, and interacting with the real-time digital human. All asynchronous methods return a **Promise** resolving to `{ err, data }`. *** ### `init(options: object): Promise` Initializes the SDK with configuration parameters and prepares the rendering environment. ```js theme={null} duix.init({ sign: '', containerLable: '.remote-container', conversationId: '', platform: 'duix.com' }); ``` ***Parameters*** | Name | Type | Required | Description | | :------------- | :----- | :------- | :------------------------------------------------------------------ | | containerLable | string | Yes | Container selector. The digital human will be rendered in this DOM. | | sign | string | Yes | Authentication signature. [How to get sign?](/api-reference) | | conversationId | string | Yes | Platform conversation ID | | platform | string | Yes | Platform domain, use duix.com | #### start(options: object): Promise Begins rendering the digital human and starts the real-time interaction. > **Note:** Always call `start()` after the `initialSuccess` event to ensure all resources are ready: > > ```js theme={null} > duix.on('initialSuccess', () => { > duix.start({ > muted: true, > wipeGreen: false, > }).then(res => { > console.log('Session started:', res); > }); > }); > ``` ***Parameters*** | key | Type | Required | Default | Description | | -------------- | ------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | muted | boolean | No | false | Start video muted. Due to [autoplay policy](https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide) restrictions, if the user hasn’t clicked anywhere yet, set this to `true` or playback may fail. You can unmute later via `duix.setVideoMuted(false)` | | openAsr | boolean | No | false | Enable real-time recognition immediately (equivalent to calling `openAsr` after `start`) | | wipeGreen | boolean | No | false | Enable green screen removal. Requires a pure green background when creating the session | | userId | number | No | | Unique user identifier | | vadSilenceTime | number | No | 800 | ASR silence timeout (ms) | | enableLLM | number | No | 1 | Enable LLM auto-replies (0 = off, 1 = on) | #### setVideoMuted(flag: boolean) Toggles video playback mute state. `true` = muted, `false` = unmuted. #### break() Immediately interrupts the current speech or response playback. #### speak(options: object): Promise Drives the digital human to speak using text or an audio URL. ```javascript theme={null} duix.speak({content: '', audio: 'https://your.website.com/xxx/x.wav'}) ``` ***Parameters*** | Name | Type | Required | Description | | :-------- | :------ | :------- | :----------------------------------------------------------------------------------- | | content | string | Yes | Text to speak | | audio | string | No | Audio URL to play. Can also use getAnswer() to obtain platform-configured responses. | | interrupt | boolean | No | If true, interrupts any ongoing speech before playback. | #### answer(options: object): Promise Asks a question and drives the digital human to respond with speech. ```javascript theme={null} duix.answer({question: 'xxx'}) ``` ***Parameters*** | Name | Type | Required | Description | | :-------- | :------ | :------- | :---------------------------------------------------- | | question | string | Yes | Question text | | interrupt | boolean | No | If true, interrupts previous speech before answering. | #### getAnswer(options: object): Promise Fetches a platform-generated response to a question without directly playing it. ```javascript theme={null} duix.getAnswer({ question: 'what is your name?' }) ``` ***Parameters*** | Name | Type | Required | Description | | :------- | :----- | :------- | :------------------------------------------------------------------ | | question | string | Yes | Question text | | userId | number | No | Unique business user ID. If provided, the answer will enable memory | ***Return data*** | Name | Type | Description | | :----- | :----- | :--------------- | | answer | string | Answer text | | audio | string | Answer audio URL | #### startRecord(): Promise Start recording. ```js theme={null} await duix.startRecord(); ``` #### stopRecord(): Promise Stops recording and returns a Promise resolving with the speech recognition result. ```js theme={null} const result = await duix.stopRecord(); console.log('Recognized text:', result); ``` #### openAsr(): Promise Enables real-time automatic speech recognition (ASR). Should be called after the show event. ```js theme={null} duix.openAsr(); ``` #### closeAsr(): Promise Disables real-time speech recognition. ```js theme={null} duix.closeAsr(); ``` #### createCamera():Promise Turn on the camera. ```js theme={null} duix.createCamera(); ``` #### destroyCamera():Promise Turn off the camera and release occupied resources. ```js theme={null} duix.destroyCamera(); ``` #### stop() Terminates the current session and releases all resources. Call this during page unload or refresh to avoid lingering RTC connections. ```js theme={null} window.addEventListener('beforeunload', () => { if (duix) duix.stop(); }); ``` #### getLocalStream() Returns the local audio stream (useful for visualizations or waveform analysis). ```js theme={null} const stream = duix.getLocalStream(); ``` #### getRemoteStream() Returns the remote audio and video stream (for custom rendering or media processing). ```js theme={null} const remote = duix.getRemoteStream(); ``` #### resume() Resumes playback. Useful for mobile browsers that may block autoplay even after user interaction. Call this in response to error code 4009. ```js theme={null} duix.resume(); ``` #### on(eventName, callback) Registers an event listener for SDK events. ```js theme={null} duix.on('speakStart', (data) => { console.log('Speech started:', data.content); }); ``` ##### Parameters | Name | Type | Description | | :-------- | :------- | :---------------------------------------------------- | | eventName | string | Name of the event to listen for. See the table below. | | callback | function | Callback function invoked with event data. | ## Return format All Promise-based methods resolve to a unified object format: ```json theme={null} { "err": null, "data": {} } ``` If err is non-null, the call failed. Use console.error(err) for diagnostic details. # Call process Source: https://docs.duix.com/sdks/h5/process Step-by-step lifecycle of the Duix H5 SDK, from initialization to session termination. ## Overview The following diagram illustrates the **Duix H5 SDK call flow**,\ showing how each method and event connects within a real-time digital human session.\ This helps developers understand when to initialize, start, interact, and properly close the session. *** ## SDK Call Flow *** ## Lifecycle Summary Below is a simplified description of the SDK’s execution lifecycle: 1. **Initialize**\ Call `duix.init()` with the required configuration (`sign`, `containerLable`, `conversationId`, `platform`). 2. **Wait for Initialization Event**\ Listen for the `initialSuccess` event to confirm all resources have loaded. 3. **Start the Session**\ Invoke `duix.start()` to begin rendering the digital human and enable audio/video streaming. 4. **Interact in Real Time** * Use `duix.speak()` or `duix.answer()` for text/audio-based responses. * Enable or disable speech recognition via `duix.openAsr()` / `duix.closeAsr()`. * Monitor lifecycle events such as `speakStart`, `speakEnd`, `asrData`, and `report`. 5. **Handle User Actions & Network Events** * Respond to `error` or `report` events for network diagnostics. * Use `duix.break()` to interrupt speech or `duix.setVideoMuted()` to toggle playback. 6. **Terminate the Session** * When done, call `duix.stop()` to gracefully release all WebRTC resources. * Optionally bind `duix.stop()` to `window.beforeunload` for page refresh or close. *** ## Best Practices * Always **register event listeners before** calling `duix.start()`. * For browsers with autoplay restrictions, start muted (`muted: true`) and later unmute via `setVideoMuted(false)`. * If using green-screen background removal (`wipeGreen: true`), ensure the input video uses a **pure green background** during session creation. * To maintain performance, stop the session (`duix.stop()`) when inactive for long periods. *** > **Tip:**\ > Pair this diagram with the [Methods](/sdks/h5/methods) and [Events](/sdks/h5/events) sections\ > to see both the functional flow and event sequence. # Frequently asked questions Source: https://docs.duix.com/sdks/h5/questions Common issues and troubleshooting tips when integrating the Duix H5 SDK. ## Playback & Autoplay Issues **Q1. Why does the digital human not appear or play automatically?**\ Some browsers (especially on mobile) require a **user gesture** to start media playback.\ Always trigger `duix.start()` **from a click handler** (e.g., a button).\ Even if muted, certain browsers may not render the digital human until a user interaction occurs. **Q2. What should I do when autoplay is still blocked after user interaction?**\ Some mobile browsers enforce autoplay restrictions even after a click.\ If you encounter **error code `4009`**, call `duix.resume()` in response to a user action to manually resume playback. *** ## Microphone & Permission Issues **Q3. Why do I need to call `navigator.mediaDevices.getUserMedia` on iOS?**\ On certain iOS-based browsers (especially within **WeChat**),\ you must explicitly call `navigator.mediaDevices.getUserMedia` to pre-authorize microphone access before remote streams can play. **Q4. Why does ASR fail to capture voice input?**\ If **Automatic Speech Recognition (ASR)** is enabled, the browser must have active microphone permission.\ Browsers also typically require **HTTPS** for `getUserMedia` access during local debugging or deployment. *** ## Integration & Compatibility **Q5. How can I integrate the SDK into a WeChat Mini Program?**\ Use the built-in **`web-view`** component to embed the SDK page within your Mini Program environment. **Q6. Why does the SDK not handle wake words or interruption phrases?**\ The SDK only provides core real-time interaction capabilities.\ To implement **wake words, interruption phrases, or scripted openings**,\ fetch them via **OpenAPI → Get Session Details** and manage the logic on your business layer. **Q7. Which browsers are incompatible with Duix SDK?**\ Some mobile browsers do not support WebRTC (e.g., **Xiaomi Browser**).\ For the best experience, use modern Chromium-based browsers such as **Chrome**, **Edge**, or **Samsung Internet**. *** ## Network & Security **Q8. Why doesn’t WebRTC work on HTTP or IP addresses?**\ WebRTC strictly requires **HTTPS** and a valid **domain name**.\ Connections over plain HTTP or direct IP addresses are not supported due to security and permission policies. *** > **Tip:**\ > Always test integrations on HTTPS in a real browser environment,\ > as certain permissions and autoplay behaviors cannot be simulated in headless or local file contexts. # Quick start Source: https://docs.duix.com/sdks/h5/quickstart Set up the Duix H5 SDK and start your first real-time digital human session in under one minute. ## Installation Install the Duix H5 SDK via **npm**: ```bash theme={null} npm install duix-guiji-light --save ``` ## Import and Initialize Import the SDK and create a new instance. The init() method sets up the rendering container, authentication, and platform connection. ```js theme={null} import Duix from 'duix-guiji-light'; // Create Duix instance const duix = new Duix(); // Initialize SDK duix.init({ sign: 'xxxx', // Authentication signature containerLable: '.remote-container', // DOM container selector conversationId: '', // Session ID platform: 'duix.com' // Platform domain }); ``` ## Start the Session Once initialization succeeds, listen for the initialSuccess event before calling start(). This ensures all required assets and network resources are ready. ```js theme={null} duix.on('initialSuccess', () => { // Start session after successful initialization duix.start({ openAsr: true // Enable real-time ASR immediately }).then(res => { console.info('Session started:', res); }).catch(err => { console.error('Session start failed:', err); }); }); ``` **Note:** Do not store the duix instance inside a reactive data object (e.g., Vue’s data() or React’s state). SDK instances should remain stable references outside reactivity systems. # Download and installation Source: https://docs.duix.com/sdks/ios/download Download and set up the Duix iOS SDK demo project to quickly test real-time digital human capabilities. ## Overview This section provides the setup guide for the **Duix iOS SDK demo project**, which allows developers to experience the SDK’s real-time digital human capabilities — including initialization, rendering, and audio-video interaction — directly in **Xcode**. *** ## Step 1: Download the iOS Demo Click below to download the latest official iOS demo package: 👉 [**duix-cloud-demo-ios\_1.2.7.zip**](https://duix-sgp.obs.ap-southeast-3.myhuaweicloud.com/duix/sdk/duix-cloud-demo-ios_1.2.7.zip) > **Note:** > The demo project includes all required SDK dependencies and configuration for quick testing. *** ## Step 2: Open the Project in Xcode 1. Extract the downloaded `.zip` file. 2. Open the project folder in **Xcode 14.0 or later**. 3. Wait for Xcode to automatically index and resolve dependencies. 4. Confirm that your **iOS deployment target** matches your connected device or simulator. *** ## Step 3: Configure and Run 1. Select your build target (e.g., iPhone 14 Pro). 2. Click **Run ▶️** to launch the demo. 3. Once initialized, the digital human should appear and respond in real time. > **Tip:** > The first run may require microphone and camera permissions. Grant access when prompted. *** ## Environment Requirements | Component | Minimum Version | Notes | | ----------- | ---------------- | ------------------------------------------------- | | **macOS** | 12.0 (Monterey) | Required for Xcode 14 or higher | | **Xcode** | 14.0+ | Enable Developer Mode for device testing | | **iOS** | 15.0+ | Recommended for best SDK performance | | **Network** | HTTPS (TLS 1.2+) | WebRTC requires a secure connection to `duix.com` | *** ## Troubleshooting * **Build failed?** Ensure **CocoaPods** and **Xcode Command Line Tools** are up to date. * **Network issues?** Confirm your device can reach `duix.com` and your firewall allows WebRTC ports. * **Permissions denied?** Re-enable microphone and camera in **Settings → Privacy → App Permissions**. # Common errors Source: https://docs.duix.com/sdks/ios/error List of common error codes, their causes, and possible solutions when using the Duix SDK. ## Overview This page lists common error codes returned by the **Duix SDK** or related backend services.\ Errors are grouped by category to help you quickly identify the cause of the problem. *** ## Client-Side Errors | Code | Description | | :----- | :----------------------------------------------------------------------------------------------------------------------------- | | **-1** | **MQTT connection error.** The client failed to connect to the message broker. Check network stability and broker credentials. | | **-2** | **HTTP request failed.** The client received a non-2xx HTTP response. Verify the request URL and parameters. | | **-3** | **Failed to obtain Duix resources.** The client could not retrieve initialization assets or configuration. | | **-4** | **MQTT client connection failure.** The broker handshake or authentication failed. Retry or check server configuration. | | **-7** | **Client session interaction error.** May occur during authentication, ASR startup, or media negotiation. | *** ## WebRTC & Network Errors | Code | Description | | :----- | :----------------------------------------------------------------------------------------------------------------- | | **-5** | **Failed to create SDP.** Typically caused by an ICE server configuration issue. Verify STUN/TURN credentials. | | **-6** | **Failed to set SDP.** Usually indicates an ICE negotiation or connectivity problem. Check WebRTC signaling paths. | *** ## Authentication & Token Errors | Code | Description | | :------- | :--------------------------------------------------------------------------------------------------------- | | **1005** | **Token cannot be empty.** Ensure that the authentication token is correctly generated and passed. | | **1006** | **Token service failure.** The authentication service returned an error. Retry or verify your credentials. | | **1007** | **Server endpoint not found.** The requested API endpoint does not exist or is misconfigured. | | **1009** | **Insufficient access quota.** The user has exceeded their allocated server usage quota. | *** ## Session & Resource Errors | Code | Description | | :-------- | :-------------------------------------------------------------------------------------------- | | **2002** | **Session not found on server.** The specified session ID may be expired or invalid. | | **50001** | **Invalid or empty appId.** Check the application configuration. | | **50002** | **Resource check failed.** Contact your administrator to verify resource allocation. | | **50003** | **Resource in use.** Another session is occupying this resource. Retry after release. | | **50004** | **Request to human service timed out.** Network delay or backend overload; try again. | | **50005** | **Error obtaining resource from resource group.** The assigned resource group is unavailable. | | **50007** | **Insufficient concurrent resources.** Maximum concurrency reached; wait and retry. | | **50009** | **Resource timed out or not configured.** Verify resource binding and expiration time. | *** ## Authentication & Signature Errors | Code | Description | | :-------- | :------------------------------------------------------------------------------- | | **40001** | **Invalid `appId` or `appSecret`.** Confirm your developer credentials. | | **40002** | **Internal server error.** Retry later or contact support if persistent. | | **50006** | **Signature failed.** Ensure your request signature matches server requirements. | *** ## Notes * Client error codes (negative numbers) are generated locally by the SDK. * Server error codes (positive numbers) originate from the Duix backend services. * Always check both **network connectivity** and **authorization configuration** when troubleshooting. * For real-time debugging, enable SDK logs or use browser DevTools to inspect HTTP and WebRTC traffic. # Code example Source: https://docs.duix.com/sdks/ios/example Objective-C code example demonstrating how to initialize, start, and handle errors using the Duix iOS SDK. ## Overview The following Objective-C example demonstrates the basic workflow for integrating the **Duix iOS SDK**,\ including initialization, session management, view setup, and error handling.\ For the complete implementation, see the full demo project:\ 👉 [**duix-cloud-demo-ios\_1.2.6.zip**](https://duix-sgp.obs.ap-southeast-3.myhuaweicloud.com/duix/sdk/duix-cloud-demo-ios_1.2.6.zip) *** ## Full Example ```objective-c theme={null} /// Assign a custom view for digital human rendering [DigitalManager manager].remote_view = self.customView; #pragma mark - SDK Initialization [[GJAccess manager] getCamerapermissions:^(bool isPermis) { if (isPermis) { [[DigitalManager manager] initNewWithAppId:AppId appKey:AppKey conversationId:ConversationId region:REGION block:^(BOOL isSuccee, NSString *errorMsg) { if (isSuccee) { [[DigitalManager manager] toStart]; // Start digital human session } else { NSLog(@"GJDigitalDemo==errorMsg==%@", errorMsg); } }]; } }]; #pragma mark - End Conversation - (void)toStop { self.digitalShow = NO; // Hide the digital human [[DigitalManager manager] toStop]; // Stop the active session } #pragma mark - SDK Delegate (DigitalViewDelegate) #pragma mark - Video Load Completion - (void)onVideoShow:(BOOL)isSuccess progress:(float)progress { if (isSuccess) { self.digitalShow = YES; NSLog(@"GJDigitalDemo==Load Complete"); } else { NSLog(@"GJDigitalDemo==Loading Progress: %lf", progress); } } #pragma mark - Error Handling - (void)onError:(NSInteger)error_code errorMsg:(NSString *)errorMsg { // Handle specific error codes switch (error_code) { case -1: case -2: // MQTT connection issues break; case 50001: // Invalid or empty AppId break; case 50002: // Resource check failed (contact administrator) break; case 50003: // Resource occupied; please check and retry break; case 50004: // Human request timeout break; case 50005: // Error retrieving resources from group break; case 50006: // Signature verification failed break; case 50007: // Insufficient total concurrency of resources break; case 50009: // Resource timeout or not configured break; default: // Unknown error break; } NSLog(@"GJDigitalDemo==errorMsg==%@", errorMsg); } ``` # Key interfaces Source: https://docs.duix.com/sdks/ios/interface Core Objective-C interfaces and delegate callbacks provided by the Duix iOS SDK. ## Overview This section lists the **primary interfaces** and **delegate callbacks**\ used to integrate and control the **Duix iOS SDK**.\ These APIs cover initialization, session control, speech interaction,\ and real-time audio-video event handling. *** ## SDK Core Interfaces ```objective-c theme={null} /** * SDK initialization * * @param appId Application ID * @param appKey Application key * @param conversationId Session ID * @param block Initialization callback */ - (void)initWithAppId:(NSString *)appId appKey:(NSString *)appKey conversationId:(NSString *)conversationId block:(void (^)(BOOL isSuccee, NSString *errorMsg))block; /** * Start session */ - (void)toStart; /** * End session */ - (void)toStop; /** * Speak with text * * @param text Text content * @param interrupt Whether to interrupt the previous speech */ - (void)commandEventWithText:(NSString *)text interrupt:(BOOL)interrupt; /** * Speak with audio URL * * @param audioUrl Audio URL * @param interrupt Whether to interrupt the previous speech */ - (void)commandEventWithAudioUrl:(NSString *)audioUrl interrupt:(BOOL)interrupt; /** * Ask a question (text) * * @param text Text content * @param interrupt Whether to interrupt the previous speech */ - (void)commandAskWithText:(NSString *)text interrupt:(BOOL)interrupt; /** * Interrupt current speech */ - (void)toBreakDigital; /** * Microphone capture control * * @param isEnabled YES to enable microphone pickup, NO to mute */ - (void)setMute:(BOOL)isEnabled; /** * Mute or unmute digital human audio * * @param enable YES to mute, NO to unmute */ - (void)toSpeakerMute:(BOOL)enable; ``` SDK Delegate: DigitalViewDelegate The delegate provides callbacks for SDK events such as loading progress, speech recognition, playback status, and WebRTC connection changes. ```objective-c theme={null} @protocol DigitalViewDelegate /** * Load digital human resources * * @param isSuccess Whether loading succeeded * @param progress Loading progress */ - (void)onVideoShow:(BOOL)isSuccess progress:(float)progress; /** * Error callback * * @param errorCode Error code * @param errorMsg Error message */ - (void)onError:(NSInteger)errorCode errorMsg:(NSString *)errorMsg; @optional /** * ASR start */ - (void)toWebrtcAsrStart; /** * ASR result * * @param asrText Recognized text * @param isFinish Whether recognition has finished */ - (void)toWebrtcAsrText:(NSString *)asrText isFinish:(BOOL)isFinish; /** * Speak start * * @param dict Dictionary containing speech start info */ - (void)toSpeakStart:(NSDictionary *)dict; /** * Speak text * * @param dict Dictionary containing speech text info */ - (void)toSpeakText:(NSDictionary *)dict; /** * Speak stop * * @param dict Dictionary containing speech stop info */ - (void)toSpeakStop:(NSDictionary *)dict; /** * TTS speak start * * @param dict Dictionary containing TTS start info */ - (void)toTTSSpeakStart:(NSDictionary *)dict; /** * TTS speak stop * * @param dict Dictionary containing TTS stop info */ - (void)toTTSSpeakStop:(NSDictionary *)dict; /** * Controller ends the call and sends a bye event */ - (void)onByeBye; /** * Remote video communication completed */ - (void)onRTCReomteSuccess; /** * Audio load result * * @param isSuccess Whether loading succeeded */ - (void)onAudioShow:(BOOL)isSuccess; /** * WebRTC connection state changed * * @param state RTCIceConnectionState */ - (void)didIceConnectionChange:(RTCIceConnectionState)state; /** * Rendering endpoint information retrieved * * @param ID Identifier * @param name Name */ - (void)onRender:(NSString *)ID name:(NSString *)name; /** * Local video stream capture * * @param capturer Video capturer * @param frame Captured frame */ - (void)capturer:(RTCVideoCapturer *)capturer didCaptureVideoFrame:(RTCVideoFrame *)frame; /** * Remote audio stream buffer * * @param sampleBuffer Audio buffer reference */ - (void)onRemoteAudioBuffer:(CMSampleBufferRef)sampleBuffer; @end ``` # Quick start Source: https://docs.duix.com/sdks/ios/quickstart Initialize and start a Duix session after microphone authorization in iOS. ## Overview Before initializing the **Duix iOS SDK**, ensure that microphone permissions are granted.\ The following example demonstrates how to request access and start a digital human session\ after successful authorization. *** ```objective-c theme={null} - (void)toStart { // Initialize SDK after microphone access is granted [[DigitalManager manager] initNewWithAppId:AppId appKey:AppKey conversationId:ConversationId region:REGION block:^(BOOL isSuccee, NSString *errorMsg) { if (isSuccee) { // Start the digital human session [[DigitalManager manager] toStart]; } else { NSLog(@"GJDigitalDemo error: %@", errorMsg); } }]; } ``` # SDK reference Source: https://docs.duix.com/sdks/ios/sdk-reference Integration guide for the Duix iOS SDK, including framework setup and required permissions. ## Overview This section describes how to integrate the **Duix iOS SDK** into your Xcode project,\ including framework import and permission configuration. *** ## Step 1: Add SDK Frameworks 1. Drag the following frameworks into your Xcode project’s **Resources** or **Frameworks** folder: * `GJDigitalSDK.framework` * `WebRTC.framework` 2. In **Xcode → Project → General → Frameworks, Libraries, and Embedded Content**,\ set both frameworks to: ```` ```Embed & Sign``` ```` This ensures the SDK and WebRTC dependencies are correctly embedded during build and code signing. *** ## Step 2: Add Required Permissions Add the following permission descriptions to your project’s **Info.plist** file: ```plist theme={null} NSLocalNetworkUsageDescription Obtain local network permissions NSMicrophoneUsageDescription Recording rights are required for speech recognition ``` # Version history Source: https://docs.duix.com/sdks/versions ## **0.0.1** 1. SDK initialization ## **0.1.0** 1. Add `startRecord` and `stopRecord` ## **0.2.0** 1. Fix exception when ASR is off by default ## **0.2.1** 1. `init` adds `platform` parameter (required for overseas connection) ## **0.2.2** 1. Fix request address error caused by missing internal parameters ## **0.2.3** 1. Add untrained model connection and optimize RTC config retrieval ## **0.2.4** 1. Validate ASR configuration before `startRecord` ## **0.3.0** 1. Added support for using streaming audio as the driver. 2. Domain migration. ## **0.3.1** 1. Fixed an error that occurred when passing false to openAsr during the start process. ## **0.3.2** 1. Added the initialSucccess event to replace the original intialSucccess event. 2. Optimized the logic related to audio/video channel switching. 3. Added two methods: createCamera and destroyCamera, along with the cameraChange event.