/docs
JS sdk 7.X
0. Integration preparation
Instructions
This page is the documentation for JS SDK version 7.X. The previous version was 6.X. For reference, see the JS SDK 6.X Documentation.
Get sample codeAuthorized Account
- AppKey
- SecretKey
Importe JS SDK
- CDN Import
import { AIEngine } from 'https://sdk.cloud.chivox.com/chivoxsdk-js/v7.2.0/index.js';
- npm Import
npm install chivox_jssdk_7.2
import { AIEngine } from 'chivox_jssdk_7.2';
1. Create Engine
let engine = new AIEngine({
server: "wss://cloud.chivox.com", //Server address
onInited: () => { //The engine can only be used for evaluation after this event is triggered.
console.log("engine onInited")
},
onError: (err) => { //Triggering this event indicates that the engine initialization has failed. To continue the evaluation, the engine must be recreated.
console.log("engine onError: " + JSON.stringify(err))
}
})
2. Start Recording
start(param)
Parameter
| Name | Type | Optional | Defaults | Description |
|---|---|---|---|---|
| audioType | string | Required | None | Audio format: WAV |
| duration | int | Optional | None | Recording duration, in milliseconds. If the recording duration is less than 2000 ms, it defaults to 2000 ms. |
| app | Object | None | Required | Signature verification informationValid for one hour |
| serverParams | Object | Required | None | Different question parameters, see details English question type ,Chinese question type |
| onStart | callback | Optional | None | Callback notification for starting recording |
| onStop | callback | Optional | None | Recording end callback notification |
| onInternalScore | callback | Optional | None | Intermediate scoring results returned during the recording process |
| onScore | callback | Required | None | Final Score |
| onError | callback | Required | None | Scoring-related error |
| onSoundIntensity | callback | Optional | None | Real-time volume, parameter is "soundIntensity", value range 0~100 |
Signature information
- The correct signature information must include the following parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
| applicationId | string | Required | Chivox authorized appKey |
| timestamp | string | Required | Timestamp for generating the signature, unit: milliseconds (ms) |
| alg | string | Required | Algorithm for generating signatures, supports SHA256 and MD5 |
| sig | string | Required | Signature string, generated using the signature algorithm alg(appkey+timestamp+secretKey) |
| userId | string | Optional | User identifier, please ensure that each user's userId is unique |
- Correct json format:
{
"applicationId": "your appKey",
"timestamp": "1759216733709",
"sig": "9xxxxxxxxccad7d31d6xxxxd6xxxx3xxxx6exxxx",
"alg": "sha256",
"userId": "Tom"
}
Sample code
engine.start({
audioType: "wav",
duration: 2000, //Unit: milliseconds
app: {
applicationId: string
sig: string
alg: string
timestamp: string
},
serverParams: {
coreType: "en.sent.score",
refText: refText,
rank: 100,
attachAudioUrl: 1
},
listener: {
onStart: () => {
console.log("onStart");
},
onStop: (audioBlob) => {
console.log("onStop")
},
onInternalScore: (data) => {
console.log("onInternalScore: " + JSON.stringify(data))
},
onScore: (data) => {
console.log("onScore: " + JSON.stringify(data))
},
onError: (err) => {
console.log("onEvalError: " + JSON.stringify(err))
},
onSoundIntensity: (data) => {
console.log(typeof data);
console.log(data);
}
}
})
3. Stop recording
// Stop recording, and the evaluation results will output through the listener event provided by the start interface.
engine.stop({
cancel: false // cancel current evaluation or not
})
4. Destroy engine
// Call this interface to release internal resources when the engine is no longer in use.
engine.dispose()
5. Microphone Volume Control Interface
This interface can only be effectively called after the engine has been successfully initialized.
5.1 Get microphone volume
getMicVolume(): number
5.2 Set microphone volume
setMicVolume(volume: number)
Volume value range [0, 0.1, 0.2 ~ 1]
6. Error code
Based on the reuse of jssdk-6.x error codes, some new error codes are added
| Error Code | Description | Version |
|---|---|---|
| 50201 | Timeout waiting for the server to return the evaluation result | 6.x |
| 70001 | Recorder initialization failed | 6.x |
| 70002 | The recorder is recording | 6.x |
| 70003 | The engine is initializing | 7.1 |
| 70004 | Recorder failed to start recording | 7.1 |
| 70005 | Recorder failed to stop recording | 7.1 |
| 70006 | Engine operation abnormality | 7.1 |
| 70007 | The engine has been destroyed. | 7.1 |
| 70008 | The interface calling sequence is wrong | 7.1 |
| 73001 | WebSocket connection error | 6.x |
| 73002 | The evaluation result is not a valid JSON format | 7.1 |
| 73003 | Evaluation canceled | 7.1 |
| 73004 | Internal error | 7.1 |
| 75006 | Input parameter error | 7.1 |
