Short Text to Speech
H5 SDK
TTS H5 SDK
1. Browser Compatibility
| Operating System | Supported Browser Minimum Version | |
|---|---|---|
| chrome | Firefox | |
| Windows 7 | 41.0.2272.76 | 46 |
| Windows 10/11 | 43.0.2357.81 | 46 |
| MAC OS | 43.0.2357.81 | 46 |
2. Import
<!-- 【1.1】Import the streaming player file -->
<script type="text/javascript" src="static/pcm-player.js"></script>
<!-- 【1.2】Import the SDK core file -->
<script type="text/javascript" src="sdk/TtsSDK.min.js"></script>Audio stream playback. You can use the pcm-player plugin for audio stream playback, or by other means, just for reference.
3. Parameter Configuration
3.1 Engine Parameters
(1)Parameter Example
-
Set app_id and secret
- Contact business for app_id and secret
-
signature and timestamp
- Users call the interface to obtain timestamp and signature
-
Set synthesis parameters
- Set synthesis parameters through JSON in the
payloadfield - If parameters are missing or values are out of range, an error code and error message will be returned in the
onErrorcallback
- Set synthesis parameters through JSON in the
| Parameter | Type | Required | Description | Default Value |
|---|---|---|---|---|
| text | String | Yes | Text to be synthesized, limited to 1024 bytes (UTF-8 encoding) | Required |
| format | String | No | Audio encoding format, wav / pcm / mp3, default is pcm | pcm |
| sample_rate | Integer | No | Audio sampling rate, default is 24000, options are 8000, 16000 | 24000 |
| lang_type | String | Yes | Language options | Required |
| voice | String | No | Voice options | Japanese: Yuko English:Julie Chinese:Xiaohui |
| emotion | String | No | Emotional style | No |
| volume | Float | No | Volume, [0.1, 3], default is 1, usually one decimal place is sufficient | 1 |
| speech_rate | Float | No | Speech rate, [0.2, 3], default is 1, usually one decimal place is sufficient | 1 |
| pitch_rate | Float | No | Pitch rate, [0.1, 3], default is 1, usually one decimal place is sufficient | 1 |
| silence_duration | Integer | No | Silence duration at the end of a sentence, in ms, default is 125 | 125 |
| enable_timestamp | Boolean | No | Whether to enable timestamp return function | false |
Example (Method 1, recommended): Obtain timestamp、signature from the backend
new TTSEngine({
app_id: '',
signature : '',
timestamp : 1234567890,
payload: {
text: '',
format: '',
sample_rate: 24000,
lang_type: '',
voice: '',
emotion: '',
volume: 1,
speech_rate: 1,
pitch_rate: 1,
silence_duration: 125,
enable_timestamp: false,
}
})Example (Method 2, not recommended): Write secret in the frontend and generate signature in the frontend
new TTSEngine ({
app_id: '',
secret : '',
payload: {
text: '',
format: '',
sample_rate: 24000,
lang_type: '',
voice: '',
emotion: '',
volume: 1,
speech_rate: 1,
pitch_rate: 1,
silence_duration: 125,
enable_timestamp: false,
}
})3.2 Initialization Method
(1)Configuration Parameters
| Name | Type | Description | Default Value |
|---|---|---|---|
| engineFirstInitDone | Function | Initialization success callback method | None |
| engineFirstInitFail | Function | Initialization failure callback method | None |
(2)Parameter Example
new TTSEngine ({
engineFirstInitDone : function () {},
engineFirstInitFail : function (status,msg) {}
})3.3 Synthesis Result Return
(1)Configuration Parameters
| Name | Type | Description | Default Value |
|---|---|---|---|
| onTimestamp | Function | Synthesis timestamps returned by the engine | None |
| onDuration | Function | Synthesis duration returned by the engine | None |
| onResult | Function | Callback method for synthesized binary data stream returned by the engine | None |
| onCompleted | Function | Synthesis task_id returned by the engine | None |
| onWarning | Function | Warning callback method for synthesis results returned by the engine | None |
| onError | Function | Error callback method for synthesis results returned by the engine | None |
(2)Parameter Example
new TTSEngine ({
onTimestamp : function (taskId, payload) {},
onDuration : function (taskId, payload) {},
onResult : function (data) {},
onCompleted : function (taskId) {},
onWarning : function (status, msg, taskId) {},
onError : function (status, msg, taskId) {}
})3.4 Network
(1)Configuration Parameters
| Name | Type | Description | Default Value |
|---|---|---|---|
| onNetworkError | Function | Network monitoring callback | None |
(2)Parameter Example
new TTSEngine ({
onNetworkError : function (status, msg) {},
})4. Method Invocation
startSynthesis()
Function: Start synthesis;
cancelSynthesis()
Function: Cancel synthesis;
destroySynthesis()
Function: Destroy synthesis instance;