Skip to main content

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.
duix.init({
  sign: '',
  containerLable: '.remote-container',
  conversationId: '',
  platform: 'duix.com'
});
Parameters
NameTypeRequiredDescription
containerLablestringYesContainer selector. The digital human will be rendered in this DOM.
signstringYesAuthentication signature. How to get sign?
conversationIdstringYesPlatform conversation ID
platformstringYesPlatform 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:
duix.on('initialSuccess', () => {
  duix.start({
    muted: true,
    wipeGreen: false,
  }).then(res => {
    console.log('Session started:', res);
  });
});
Parameters
keyTypeRequiredDefaultDescription
mutedbooleanNofalseStart video muted. Due to autoplay policy 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)
openAsrbooleanNofalseEnable real-time recognition immediately (equivalent to calling openAsr after start)
wipeGreenbooleanNofalseEnable green screen removal. Requires a pure green background when creating the session
userIdnumberNoUnique user identifier
vadSilenceTimenumberNo800ASR silence timeout (ms)
enableLLMnumberNo1Enable 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.
duix.speak({content: '', audio: 'https://your.website.com/xxx/x.wav'})
Parameters
NameTypeRequiredDescription
contentstringYesText to speak
audiostringNoAudio URL to play. Can also use getAnswer() to obtain platform-configured responses.
interruptbooleanNoIf true, interrupts any ongoing speech before playback.

answer(options: object): Promise

Asks a question and drives the digital human to respond with speech.
duix.answer({question: 'xxx'})
Parameters
NameTypeRequiredDescription
questionstringYesQuestion text
interruptbooleanNoIf true, interrupts previous speech before answering.

getAnswer(options: object): Promise

Fetches a platform-generated response to a question without directly playing it.
duix.getAnswer({ question: 'what is your name?' })
Parameters
NameTypeRequiredDescription
questionstringYesQuestion text
userIdnumberNoUnique business user ID. If provided, the answer will enable memory
Return data
NameTypeDescription
answerstringAnswer text
audiostringAnswer audio URL

startRecord(): Promise

Start recording.
await duix.startRecord();

stopRecord(): Promise

Stops recording and returns a Promise resolving with the speech recognition result.
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.
duix.openAsr();

closeAsr(): Promise

Disables real-time speech recognition.
duix.closeAsr();

stop()

Terminates the current session and releases all resources. Call this during page unload or refresh to avoid lingering RTC connections.
window.addEventListener('beforeunload', () => {
  if (duix) duix.stop();
});

getLocalStream()

Returns the local audio stream (useful for visualizations or waveform analysis).
const stream = duix.getLocalStream();

getRemoteStream()

Returns the remote audio and video stream (for custom rendering or media processing).
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.
duix.resume();

on(eventName, callback)

Registers an event listener for SDK events.
duix.on('speakStart', (data) => {
  console.log('Speech started:', data.content);
});
Parameters
NameTypeDescription
eventNamestringName of the event to listen for. See the table below.
callbackfunctionCallback function invoked with event data.

Return format

All Promise-based methods resolve to a unified object format:
{
  "err": null,
  "data": {}
}
If err is non-null, the call failed. Use console.error(err) for diagnostic details.
I