API reference
The mobile NUI SDK converts text to speech. You can select a voice and audio format, and adjust the speech rate, pitch, and volume.
Description
The NUI SDK provides end-to-end speech capabilities and can also be used for speech synthesis alone. Speech synthesis supports PCM, WAV, and MP3 audio output. The SDK delivers synthesized audio and events through callbacks.
For supported voices, languages, sample rates, and timestamp capabilities, see the voice list. In the mobile SDK, set font_name to the corresponding voice value in the list.
Limitations
Input text must be UTF-8 encoded.
-
Short-text synthesis processes up to 300 characters per request. Text beyond this limit is truncated.
To synthesize text that exceeds 300 characters, set
tts_versionto"1"to use long-text synthesis.
Service endpoints
Set url to the service endpoint when you initialize the SDK.
|
Access method |
Region |
URL |
|
Internet |
Shanghai (default) |
|
|
Beijing |
|
|
|
Shenzhen |
|
|
|
ECS internal network |
Shanghai |
|
|
Beijing |
|
|
|
Shenzhen |
|
ECS instances in China (Shanghai), China (Beijing), or China (Shenzhen) can access the internal endpoint in the same region through a virtual private cloud (VPC). This access does not incur Internet traffic fees for the ECS instance. Classic networks do not support access to speech services. Use a VPC instead.
Interaction process
Authenticate and initialize
The client uses an NLS token for authentication when establishing a WebSocket connection. For instructions, see Obtain a token.
Pass the following parameters during initialization. In the Android SDK, call tts_initialize with a JSON string that contains these parameters.
|
Parameter |
Type |
Description |
|
app_key (required) |
String |
The Appkey of the project created in the console. |
|
token (required) |
String |
A valid NLS token. Set it during initialization or update it through the parameter-setting method. |
|
device_id (required) |
String |
A unique device identifier, such as a MAC address, SN, or UniquePsuedoID. |
|
mode_type (required) |
String |
The online speech synthesis mode. Set this parameter to the string |
|
url |
String |
The service endpoint. Use the endpoint that corresponds to the project and token. |
|
workspace (required) |
String |
The working directory from which the SDK reads configuration files. This parameter can be omitted for online-only synthesis in Android SDK 2.7.4. |
Start synthesis
After initialization, configure synthesis parameters by calling setparamTts, and then start a speech synthesis request.
|
Parameter |
Type |
Description |
|
app_key |
String |
The project Appkey. The value set during initialization remains available. |
|
token |
String |
Set this parameter when the authentication token needs to be updated. |
|
font_name |
String |
The voice. The default is |
|
encode_type |
String |
The audio encoding format. Valid values: |
|
sample_rate |
String |
The audio sample rate in Hz. The default is |
|
volume |
String |
The volume. Valid range: 0 to 2. The default is |
|
speed_level |
String |
The speech rate. Valid range: 0 to 2. The default is |
|
pitch_level |
String |
The pitch. Valid range: -500 to 500. The default is |
|
enable_subtitle |
String |
The timestamp switch. Set it to |
|
tts_version |
String |
The synthesis mode. |
|
Additional parameter |
Type |
Description |
|
direct_host |
String |
Allows the client to resolve the service domain name and pass an IP address to access the service. |
|
custom_params |
String |
Sets parameters supported by the interaction protocol but not listed above. Use |
Receive synthesized audio
The server returns synthesized audio as binary data. The SDK provides the audio data through callbacks.
Complete synthesis
When synthesis is complete, the server sends a synthesis completion event.
Error codes
If an error occurs during synthesis, the SDK reports a TTS_EVENT_ERROR event with error details.
For error descriptions and solutions, see Error codes.