API reference
Offline speech synthesis converts text into natural, fluent speech using a local speech synthesis model on a device. This feature works in environments with poor or no network connectivity.
Features
Offline speech synthesis includes the following features. Multiple instance calls are not supported.
You can adjust the speech rate, pitch, and volume.
This feature is suitable for scenarios such as in-car navigation, smart hardware, audiobook reading, and accessibility announcements.
It integrates as a software development kit (SDK) and supports multiple hardware platforms.
Billing is based on the number of activated devices.
Multiple voices are available. For supported languages and downloads, see Voice packages.
Prerequisites
Configure and activate the SDK license before use. For instructions, see Activate SDK licenses. Initial registration and authentication require a network connection. After activation, speech synthesis runs locally on the device.
Sequence diagram
Activation and initialization parameters
This section describes the parameters for activating and initializing the offline text-to-speech (TTS) SDK. These parameters include authentication credentials, the workspace path, and the log storage path.
After you set and enable the initialization parameters, you cannot change them.
Parameter | Type | Description | Required |
ak_id | string | The AccessKey ID. For more information about how to obtain an AccessKey ID, see Quick start: Create an AccessKey pair. | Yes |
ak_secret | string | The AccessKey secret. For more information about how to obtain an AccessKey secret, see Quick start: Create an AccessKey pair. | Yes |
app_key | string | The AppKey of the project. It is automatically generated after the project is created. In the navigation bar of the console, click All Projects to view the AppKey. | Yes |
sdk_code | string | The product code.
| Yes |
device_id | string | The device ID. Note The device_id must be globally unique within an AppKey. | Yes |
workspace | string | The resource path. | Yes |
mode_type | string | Set to "0" to initialize the local engine. | Yes |
debug_path | string | The log storage path. Note Including this field enables log storage. To disable log storage, set the debug_level parameter to 5 in the dynamic parameter settings. Log files are stored in append mode. | No |
enable_et | string | Valid values: true and false. Set to false to disable data reporting. Data reporting is enabled by default. For more information about data reporting, see How does the SDK perform data reporting? | No |
enable_ntp | string | Valid values: true and false. Set to false to disable NTP. NTP is enabled by default. The NTP feature is used to get the Alibaba Cloud time for authentication. For more information, see What is the purpose of NTP? | No |
enable_low_precision | string | Valid values: true and false. The default value is false, which indicates high-precision mode. If you set this parameter to true, low-precision mode is used. This reduces the computational load but slightly degrades audio quality. | No |
authspace | string | For debugging purposes, you can generate the authentication file in a fixed directory, such as "/storage/emulated/0/tts". Make sure the directory exists and has read and write permissions. This avoids re-authentication when you uninstall and reinstall the app. If you do not set this parameter, the authentication file is stored in the workspace directory. | No |
extend | string | Extended field (JSON). | No |
Dynamic parameters
The in property indicates a parameter that you can set for the SDK. You can dynamically set in parameters using
setparamTts. Android is used as an example. The new setting takes effect for the next request.The out property indicates a parameter that you can retrieve from the SDK. You can retrieve out parameters using
getparamTts.
Parameter | Type | Property | Value | Meaning |
extend_font_name | string | in | full_path | Switches the voice. The full path of the voice package resource, such as /sdcard/xiaoyun. |
speed_level | string | in|out | (0, 2]. Default: 1.0. | The speech rate. A larger value indicates a faster rate. If the set value is out of range, the default value is used. |
pitch_level | string | in|out | [-500, 500]. Default: 0. | The pitch. A larger value indicates a higher pitch. If the set value is out of range, the default value is used. |
volume | string | in|out | (0, 2]. Default: 1.0. | The volume. A larger value indicates a higher volume. If the set value is out of range, the default value is used. Important To avoid clipping noise, we recommend keeping the value below 1.5. |
callback_raw_data | string | in | 0 or 1. Default: 0. |
|
debug_level | string | in|out | 0, 1, 2, 3, 4, 5 | Log level
|
error_msg | string | out | Error message | Retrieves detailed error information when an API call fails. We recommend recording this information in data reporting to help troubleshoot issues. |
model_sample_rate | string | out | 16000 or 24000 | The sample rate of the audio data. The typical value is 24000. |
enable_callback_vol | string | in | 0 or 1. Default: 0. |
|
enable_monopoly | string | in | 0 or 1. Default: 1. |
|
Voice packages
|
Name |
voice parameter value |
Type |
Scenarios |
Supported languages |
Supported sample rates (Hz) |
Notes |
Download link |
|
Aijia |
aijia |
Standard female voice |
General |
Supports Chinese and mixed Chinese-English scenarios. |
24000 |
Premium Edition |
|
|
Aicheng |
aicheng |
Warm male voice |
General scenarios |
Supports Chinese and mixed Chinese-English scenarios. |
24000 |
Premium Edition |
|
|
Aiqi |
aiqi |
Gentle female voice |
General |
Supports Chinese scenarios. |
24000 |
Premium Edition |
|
|
Aida |
aida |
Standard male voice |
General |
Supports Chinese scenarios. |
24000 |
Premium Edition |
|
|
Aihao |
aihao |
News-style male voice |
Literature |
Supports Chinese scenarios. |
24000 |
Premium Edition |
|
|
Aishuo |
aishuo |
Natural male voice |
Customer service |
Supports Chinese scenarios. |
24000 |
Premium Edition |
|
|
Aiying |
aiying |
Cute child voice |
Literature |
Supports Chinese and mixed Chinese-English scenarios. |
24000 |
Premium Edition |
|
|
Aitong |
aitong |
Child voice |
Child voice scenarios |
Supports only Chinese scenarios. |
24000 |
Premium Edition |
|
|
Abby |
abby |
American English female voice |
English scenarios |
Supports only English scenarios. |
24000 |
Premium Edition |
|
|
Andy |
andy |
American English male voice |
English scenarios |
Supports only English scenarios. |
24000 |
Premium Edition |
|
|
Annie |
annie |
American English female voice |
English scenarios |
Supports only English scenarios. |
24000 |
Premium Edition |
|
|
Xiaoyun |
xiaoyun |
Standard female voice |
General |
Supports Chinese and mixed Chinese-English scenarios. |
16000 |
Standard Edition |
|
|
Xiaoda |
xiaoda |
Standard male voice |
General |
Chinese and mixed Chinese-English scenarios |
16000 |
Standard Edition |
|
|
Xiaogang |
xiaogang |
Warm male voice |
General |
Chinese and mixed Chinese-English scenarios |
16000 |
Standard Edition |
|
|
Xiaoqi |
xiaoqi |
Gentle female voice |
General |
Chinese and mixed Chinese-English scenarios |
16000 |
Standard Edition |
|
|
Xiao Xia |
xiaoxia |
Natural female voice |
Customer service |
Chinese and mixed Chinese-English scenarios |
16000 |
Standard Edition |
Performance metrics
The following metrics are provided for reference for the Chinese voice aicheng and the device configurations listed below. Performance may vary slightly between voices.
Item | Metric | |||
CPU | Model | Hardware specifications | Initialization time | CPU (synthesis state: single core) |
Redmi 6A | CPU: MediaTek Helio A22 2 GHz RAM: 2 GB OS: Android 9.0 | 273 ms | 19% | |
Huawei P10 | CPU: HiSilicon Kirin 960 2.4 GHz RAM: 4 GB OS: Android 7.0 | 178 ms | 12% | |
Huawei P40 | CPU: HiSilicon Kirin 990 2.86 GHz RAM: 6 GB OS: Android 10.0 | 67 ms | 8.2% | |
ROM |
| |||
RAM | 21.73 M | |||
Error codes
If speech synthesis fails, the SDK returns an error code in the TTS_EVENT_ERROR event. For codes and solutions, see Error codes for speech synthesis and offline speech synthesis SDKs.