Skip to main content

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 NameDescription
errorUncaught error occurred
byeSession ended
initialSuccessInitialization successful — safe to call start()
showDigital human is displayed
progressLoading progress (0–100)
speakSectionCurrent incremental audio/text segment while speaking
speakStartSpeech playback started
speakEndSpeech playback ended
asrStartSingle-sentence ASR started
asrDataSingle-sentence ASR interim result
asrStopSingle-sentence ASR ended
reportPeriodic RTC/network/video quality report

Event Details

1. error

Triggered when an unexpected error occurs. Payload
{
  code: "",      // Error code
  message: "",   // Error message
  data: {}       // Additional error data
}

Error codes
NameDescriptiondata
3001RTC connection failed
4001Failed to start session
4005Authentication failed
4007Server session abnormally endedcode: 100305 Model file not found
4008Failed to get microphone stream
4009Browser blocked autoplayStart 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
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
{
  "audio": "string",   // Audio stream URL
  "content": "string"  // Partial text content currently being spoken
}
Example
duix.on('speakSection', (data) => {
  console.log('Current segment:', data.content);
});

speakStart

Triggered when the avatar begins speech playback. Payload
{
  "audio": "string",   // Audio stream URL
  "content": "string"  // Text content being spoken
}
Example
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
{
  "audio": "string",
  "content": "string"
}
Example
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
{
  "content": "string" // Recognized text fragment
}
Example
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
{
  "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
duix.on('report', (stats) => {
  console.log('Network report:', stats.connection);
});
Note: Event payloads not explicitly documented above will return empty objects. Register all event listeners before invoking duix.start().