Updated on 2025-05-08 GMT+08:00

Main Entry (HwICSUiSdk)

This section describes the APIs of the web SDK.

Table 1 APIs

API

Description

Supported by a Third-Party Large Model

Supported by a Non-Third-Party Large Model

activeInteractionMode

Obtains the interaction mode (speech/text Q&A) in use.

×

addEventListeners

Callback registration.

changeLanguage

Sets the language of an interaction task.

×

checkBrowserSupport

Checks the browser compatibility.

create

Creates an interaction task.

destroy

Destroys an interaction task.

getJobInfo

Obtains interaction task information.

getLanguageInfo

Obtains language information of an interaction task.

×

initResourcePath

Initializes voice wakeup resources. If voice wakeup is not used, ignore this API.

×

interactionModeSwitch

Switches the interaction mode (speech/text Q&A).

×

interruptSpeaking

Interrupts the virtual avatar's speech.

×

muteRemoteAudio

Mutes the virtual avatar.

sendDrivenText

Sends the text to be read by the interactive virtual avatar.

×

sendTextQuestion

Sends the question text.

×

setConfig

Updates a configuration item.

setLogLevel

Sets the log level.

startChat

Starts a dialog.

×

startSpeak

Starts speaking by calling the new API startUserSpeak.

×

startUserSpeak

The user starts to ask questions.

×

stopChat

Ends a dialog.

×

stopSpeak

Stops speaking by calling the new API stopUserSpeak.

×

stopUserSpeak

The user stops asking questions. The automatic speech recognition (ASR) stops receiving the user's speech but the dialog is still active.

×

unmuteRemoteAudio

Unmutes the virtual avatar.

activeInteractionMode

(static) activeInteractionMode(): Promise<InteractionModeResult>

[Function Description]

Obtains the interaction mode (speech/text Q&A) in use.

[Request Parameters]

None.

[Response Parameters]

Table 2 InteractionModeResult

Parameter

Type

Description

result

boolean

Execution result.

errorCode

string | undefined

Error code. See Table 1.

errorMsg

string | undefined

Error message.

interactionMode

'AUDIO' | 'TEXT'

Interaction mode.

[Code Examples]

const { result, interactionMode } = await HwICSUiSdk.activeInteractionMode();

addEventListeners

(static) addEventListeners(eventMap: EventMap): void

[Function Description]

Sets the event callback.

[Request Parameters]

Table 3 eventMap

Parameter

Mandatory

Default Value

Type

Description

eventMap

Yes

-

EventMap

Event registration map. See Table 4.

Table 4 EventMap

Parameter

Mandatory

Default Value

Type

Description

error

No

-

(icsError: IcsError) => any

Error event.

jobInfoChange

No

-

(jobInfo: JobInfo) => any

Interaction task information change.

speakingStart

No

-

() => any

A virtual avatar starts speaking.

speakingStop

No

-

() => any

A virtual avatar stops speaking.

speechRecognized

No

-

(question: SpeechRecognitionInfo) => any

Speech recognition result.

semanticRecognized

No

-

(answer: SemanticRecognitionInfo) => any

Semantic recognition result.

[Response Parameters]

None

[Code Examples]

HwICSUiSdk.addEventListeners({
  error: (icsError) => {
    console.error('icsError', icsError);
  },
  jobInfoChange: (jobInfo) => {
    console.info('jobInfoChange', jobInfo);
  } 
});

changeLanguage

(static) changeLanguage(param: ChangeParam): Promise<void>

[Function Description]

Sets the language of an interaction task.

[Request Parameters]

Table 5 param

Parameter

Mandatory

Default Value

Type

Description

param

Yes

-

ChangeParam

Language options. For details, see Table 6.

Table 6 ChangeParam

Parameter

Mandatory

Default Value

Type

Description

langCode

Yes

-

'zh_CN' | 'en_US'

Language code, which is obtained from the API getLanguageInfo.

[Response Parameters]

See Table 22.

[Code Examples]

const { result } = await HwICSUiSdk.changeLanguage({
  langCode: 'zh_CN',
});

checkBrowserSupport

(static) checkBrowserSupport(): Promise<boolean>

[Function Description]

Checks whether the SDK is supported by the browser.

[Request Parameters]

None

[Response Parameters]

Promise<boolean>: whether the SDK is supported by the browser

[Code Examples]

1
2
3
4
5
6
const result = await HwICSUiSdk.checkBrowserSupport();
if (result) {
  // Supported
} else {
  // Not supported
}

create

(static) create(param: CreateParam): Promise<void>

[Function Description]

Creates an intelligent interaction task using the obtained task link and one-off authentication code.

[Request Parameters]

Table 7 param

Parameter

Mandatory

Default Value

Type

Description

param

Yes

-

CreateParam

For details about how to create an activity option, see Table 8.

Table 8 CreateParam

Parameter

Mandatory

Default Value

Type

Description

onceCode

Yes

-

string

One-off authentication code. For details about how to obtain an authentication code, see Creating a One-Off Authentication Code.

NOTE:

The API CreateOnceCode needs to be called in the backend and cannot be directly called on the browser. Otherwise, cross-domain problems may occur.

serverAddress

Yes

-

string

IP address of the intelligent interaction server.

The values of different regions are as follows:

  • AP-Singapore: metastudio-api.ap-southeast-3.myhuaweicloud.com

robotId

No

-

string

Intelligent interaction activity ID, which is the value of robot_id in the URL specified by taskUrl.

For example, if the URL is https://metastudio-api.cn-north-4.myhuaweicloud.com/icswebclient?robot_id=a1b2c3d4e5f6, the robot ID is a1b2c3d4e5f6.

Note: Specify robotId or taskUrl, or both.

taskUrl

No

-

string

URL of the virtual avatar interaction task page created on the MetaStudio console. For details about how to obtain the URL, see Creating an Interactive Virtual Avatar.

Note: Specify robotId or taskUrl, or both.

containerId

Yes

-

string

ID of the DOM node for the rendering SDK interaction UI.

config

No

-

ConfigMap

Configuration information. See Table 18.

eventListeners

No

-

EventMap

Event registration map. See Table 4.

This parameter is mandatory for the intelligent interaction using a third-party application.

logLevel

No

info

string

Log level.

Options:

  • debug
  • info
  • warn
  • error
  • none

[Response Parameters]

None

[Code Examples]

HwICSUiSdk.create({
  serverAddress: 'serverAddress',
  onceCode: 'onceCode',
  robotId: 'robotId',
  containerId: 'ics-root',
  logLevel: 'debug',
  config: {
    enableCaption: true,
    enableChatBtn: false
  },
  eventListeners: {
    error: (error) => {
      console.error('sdk error', {
        message: error.message,
        code: error.code,
      }, error);
    }
  }
});

destroy

(static) destroy(): Promise<void>

[Function Description]

Destroys an interaction task.

[Request Parameters]

None

[Response Parameters]

None

[Code Examples]

HwICSUiSdk.destroy();

getJobInfo

(static) getJobInfo(): Promise<JobInfo>

[Function Description]

Obtains interaction task information.

[Request Parameters]

None

[Response Parameters]

Table 9 JobInfo

Parameter

Type

Description

jobId

string

Task ID.

websocketAddr

string | undefined

WebSocket address of the intelligent interaction server. This address is used to assemble a WebSocket connection address when the virtual avatar is equipped with a third-party large model.

NOTICE:

By default, the returned address does not contain the prefix wss://. You need to add the prefix. For example, if the returned content is metastudio-api.cn-north-4.myhuaweicloud.com:443, the address should be wss://metastudio-api.cn-north-4.myhuaweicloud.com:443.

[Code Examples]

const jobInfo = await HwICSUiSdk.getJobInfo();

getLanguageInfo

(static) getLanguageInfo(): Promise<LanguageResult>

[Function Description]

Obtains language information of an interaction task. To implement the multilingual capability, you need to create an intelligent interaction page in the backend and set the languages, which can be Chinese and English currently.

[Request Parameters]

None

[Response Parameters]

Table 10 LanguageResult

Parameter

Type

Description

languageList

LanguageInfo[]

Language list.

currentLanguage

'zh_CN' | 'en_US'

Language of the current interaction task.

result

boolean

Execution result.

errorCode

string | undefined

Error code. See Table 1.

errorMsg

string | undefined

Error message.

Table 11 LanguageInfo

Parameter

Type

Description

language

'zh_CN' | 'en_US'

Language.

language_desc

string

Language description.

isDefault

boolean

Whether it is the default language.

[Code Examples]

const languageResult = await HwICSUiSdk.getLanguageInfo();

initResourcePath

(static) interactionModeSwitch(param: ResourcePath): Promise<void>

[Function Description]

Initializes voice wakeup resources. If voice wakeup is not used, ignore this API.

The web SDK package later than 3.0.1 contains the following two resource files, which are needed only when voice wakeup is used:

  • wasmData.js: voice wakeup algorithm resource file
  • modelData.js: voice wakeup model resource file

The SDK has a preset wakeup model that allows customizing wakeup phrases. You can update the model to a local path. For details, see Web Voice Wakeup.

[Request Parameters]

Table 12 ResourcePath

Parameter

Mandatory

Default Value

Type

Description

wasmPath

Yes

'wasmData.js'

string

Relative or absolute path of the wakeup algorithm resource file.

  • The relative path is based on the current page. For example, if the page URL is https://.../a/b and the default value is wasmData.js, the path of the algorithm executable file is https://.../a/b/wasmData.js.

    Ensure that this path contains the file wasmData.js of the web SDK package.

  • The absolute path is a complete HTTP file resource path.

dataPath

Yes

'modelData.js'

string

Relative or absolute path of the wakeup model resource file.

  • The relative path is based on the current page. For example, if the page URL is https://.../a/b and the default value is modelData.js, the path of the algorithm executable file is https://.../a/b/modelData.js.
  • The absolute path is a complete HTTP file resource path.

initModel

No

true

boolean

Whether to initialize the wakeup model when calling an API.

It takes 2 to 3 seconds to load the wakeup model before initialization. During this period, no operations can be performed. Therefore, you need to select a proper time point for model initialization:

  • true means initializing the model when an API is called.
  • false means initializing the model during virtual avatar creation.

[Response Parameters]

None.

[Code Examples]

await HwICSUiSdk.initResourcePath({
  wasmPath: 'wasmData.js',
  dataPath: 'modelData.js',
  initModel: true,
});

Note: If wasmPath and dataPath are not set or are incorrectly set, error messages as shown in the following figure will be reported.

In this case, voice wakeup is not available. You need to set the paths correctly.

Figure 1 Error messages

interactionModeSwitch

(static) interactionModeSwitch(param: InteractionModeParam): Promise<InteractionModeResult>

[Function Description]

Switches the interaction mode (speech/text Q&A).

[Request Parameters]

Table 13 InteractionModeParam

Parameter

Mandatory

Default Value

Type

Description

interactionMode

No

AUDIO

  • AUDIO
  • TEXT

Interaction mode, which can be speech or text interaction.

[Response Parameters]

See Table 2.

[Code Examples]

const { result } = await HwICSUiSdk.interactionModeSwitch({ interactionMode: 'AUDIO' });

interruptSpeaking

(static) interruptSpeaking(): Promise<UISdkResult>

[Function Description]

Interrupts the virtual avatar's speech.

[Request Parameters]

None

[Response Parameters]

See Table 22.

[Code Examples]

const { result } = await HwICSUiSdk.interruptSpeaking();

muteRemoteAudio

(static) muteRemoteAudio(): Promise<boolean>

[Function Description]

Mutes the virtual avatar.

[Request Parameters]

None

[Response Parameters]

Promise<boolean>: whether the virtual avatar has been muted

[Code Examples]

const result = await HwICSUiSdk.muteRemoteAudio();

sendDrivenText

(static) sendDrivenText(param: TextDrivenParam): Promise<ChatResult>

[Function Description]

Sends the text to be read by the interactive virtual avatar.

The parameter isLast:true must be transferred for the last calling when active script reading ends. Otherwise, the virtual avatar cannot receive the notification speakingStop when finishing the reading.

[Request Parameters]

Table 14 TextDrivenParam

Parameter

Mandatory

Default Value

Type

Description

text

Yes

""

String

Text to be read by the interactive virtual avatar.

isLast

No

false

Boolean

Whether it is the last piece of text.

[Response Parameters]

See Table 21.

[Code Examples]

const { result } = await HwICSUiSdk.sendDrivenText({ text: 'Hello', isLast: true });

sendTextQuestion

(static) sendTextQuestion(param: TextQuestionParam): Promise<TextQuestionResult>

[Function Description]

Sends the question text.

[Request Parameters]

Table 15 TextQuestionParam

Parameter

Mandatory

Default Value

Type

Description

text

Yes

-

String

Question text.

[Response Parameters]

Table 16 TextQuestionResult

Parameter

Type

Description

result

Boolean

Execution result.

errorCode

string | undefined

Error code. See Table 1.

errorMsg

string | undefined

Error message.

chatId

String

Dialog ID.

[Code Examples]

const { result } = await HwICSUiSdk.sendTextQuestion({ text: 'Who are you?' });

setConfig

(static) setConfig(config: ConfigMap): void

[Function Description]

Sets config to determine whether to display subtitles or the button for interaction.

[Request Parameters]

Table 17 config

Parameter

Mandatory

Default Value

Type

Description

config

Yes

-

ConfigMap

Configuration information. See Table 18.

Table 18 ConfigMap

Parameter

Mandatory

Default Value

Type

Description

enableCaption

No

false

Boolean

Whether to display subtitles.

enableChatBtn

No

false

Boolean

Whether to display the button for interaction.

enableHotIssues

No

false

Boolean

Whether to display frequently asked questions.

enableWeakErrorInfo

No

true

Boolean

Whether to display a weak prompt.

Example: A WebSocket exception occurs in the SDK.

enableBusinessTrack

No

true

Boolean

Whether to report SDK tracking data.

enableJobCache

No

true

Boolean

Whether to enable task cache. If you want the task configuration modification to take effect immediately, you do not need to enable the cache.

  • Enabling task cache can accelerate the startup of virtual avatars.
  • If task cache is disabled, a new task will be created each time the API create is called, instead of using the cached task.

useDefaultBackground

No

true

Boolean

Whether to use the default background image.

enableLocalWakeup

No

false

Boolean

Whether to enable voice wakeup. To enable it, you need to call the API initResourcePath to initialize the wakeup resource path, and then call the API create to create a virtual avatar.

firstCreateLocalStream

No

false

boolean

Whether to create a local stream first. This method is applicable when the virtual avatar's voice volume is low on some Android devices in receiver mode.

enableMediaViewer

No

true

boolean

Whether to enable image preview. You can click an image in the default dialog list to zoom in on the image.

If this function is not required, set the value to false (disabled).

[Response Parameters]

None

[Code Examples]

HwICSUiSdk.setConfig({
  enableCaption: true,
  enableChatBtn: false,
  enableHotIssues: false,
  enableWeakErrorInfo: true,
});

setLogLevel

(static) setLogLevel(logLevel: 'debug' | 'info' | 'warn' | 'error' | 'none'): void

[Function Description]

Sets the output log level.

[Request Parameters]

Table 19 logLevel

Parameter

Mandatory

Default Value

Type

Description

logLevel

Yes

info

  • debug
  • info
  • warn
  • error
  • none

Log level.

[Response Parameters]

None

[Code Examples]

HwICSUiSdk.setLogLevel('warn');

startChat

(static) startChat(param?: ChatParam): Promise<ChatResult>

[Function Description]

Starts a dialog.

[Request Parameters]

Table 20 ChatParam

Parameter

Mandatory

Default Value

Type

Description

interactionMode

No

AUDIO

  • AUDIO
  • TEXT

Interaction mode, which can be speech or text interaction.

[Response Parameters]

Table 21 ChatResult

Parameter

Type

Description

result

Boolean

Execution result.

errorCode

string | undefined

Error code. See Table 1.

errorMsg

string | undefined

Error message.

chatId

String

Dialog ID.

[Code Examples]

const { result } = await HwICSUiSdk.startChat({ interactionMode: 'AUDIO' });

startSpeak

(static) startSpeak(): Promise<UISdkResult>

[Function Description]

Starting speaking

[Request Parameters]

None

[Response Parameters]

See Table 22.

[Code Examples]

const { result } = await HwICSUiSdk.startSpeak();

startUserSpeak

(static) startUserSpeak(): Promise<UISdkResult>

[Function Description]

The user starts to ask questions.

[Request Parameters]

None

[Response Parameters]

Table 22 UISdkResult

Parameter

Type

Description

result

Boolean

Execution result.

errorCode

string | undefined

Error code. See Table 1.

errorMsg

string | undefined

Error message.

[Code Examples]

const { result } = await HwICSUiSdk.startUserSpeak();

stopChat

(static) stopChat(): Promise<ChatResult>

[Function Description]

Ends a dialog.

[Request Parameters]

None

[Response Parameters]

See Table 21.

[Code Examples]

const { result } = await HwICSUiSdk.stopChat();

stopSpeak

(static) stopSpeak(): Promise<UISdkResult>

[Function Description]

The virtual avatar stops speaking.

[Request Parameters]

None

[Response Parameters]

See Table 22.

[Code Examples]

const { result } = await HwICSUiSdk.stopSpeak();

stopUserSpeak

(static) stopUserSpeak(): Promise<UISdkResult>

[Function Description]

The user stops asking questions.

[Request Parameters]

None

[Response Parameters]

See Table 22.

[Code Examples]

const { result } = await HwICSUiSdk.stopUserSpeak();

unmuteRemoteAudio

(static) unmuteRemoteAudio(): Promise<boolean>

[Function Description]

Unmutes the virtual avatar.

[Request Parameters]

None

[Response Parameters]

Promise<boolean>: whether the virtual avatar has been unmuted

[Code Examples]

const result = await HwICSUiSdk.unmuteRemoteAudio();