Domain name for API request: tts.tencentcloudapi.com.
This API is used to convert any text to speech, allowing your devices and applications to talk to users.
u200bTencent Cloud Text To Speech (TTS) can synthesize speech from text in real time for many use cases, such as audiobook and news apps, voice reminders on smart devices, quick synthesis of a celebrity's voice based on existing programs or certain voice records available on the internet, and personalized vehicle navigation systems.
It is free for use in beta.
It supports SSML. For syntax details, see SSML.
Default API request rate limit: 20 requests/sec.
The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.
Parameter Name | Required | Type | Description |
---|---|---|---|
Action | Yes | String | Common Params. The value used for this API: TextToVoice. |
Version | Yes | String | Common Params. The value used for this API: 2019-08-23. |
Region | Yes | String | Common Params. For more information, please see the list of regions supported by the product. |
Text | Yes | String | The source text for synthesizing speech, which is encoded in UTF-8. It can contain up to 150 Chinese characters (a full-width punctuation as a Chinese character) or 500 letters ( a half-width punctuation as a letter). |
SessionId | Yes | String | The SessionId of a request, which will be returned as-is. We recommend that you pass characters like uuid to prevent repetition. |
Volume | No | Float | Volume range: [0, 10], corresponding to 11 volume levels. 0 is the default value, indicating the normal volume. There is no mute option. |
Speed | No | Float | Speed range: [-2, 6], corresponding to different speeds |
ProjectId | No | Integer | Project ID, which defaults to 0 and can be customized. |
ModelType | No | Integer | Model type, with 1 for the default model. |
VoiceType | No | Integer | Standard voices Premium voices have higher fidelity and more natural-sounding quality than standard voices. For price details, see Purchase Guide. |
PrimaryLanguage | No | Integer | Primary language type: |
SampleRate | No | Integer | Audio sample rate: |
Codec | No | String | Format of returned audio. Valid values: WAV (default), MP3, and PCM. |
EnableSubtitle | No | Boolean | Whether to enable the timestamp feature. Default value: false . |
SegmentRate | No | Integer | The threshold of speech segmentation sensibility, which can be 0 (default), 1 , or 2 . A larger value indicates fewer segments, and the model tends to only segment sentences based on punctuation marks. We recommend you not change this parameter to avoid adverse effect on speech synthesis. |
Parameter Name | Type | Description |
---|---|---|
Audio | String | Base64-encoded WAV/MP3 audio data |
SessionId | String | The SessionId of a request |
Subtitles | Array of Subtitle | Timestamp information. If the timestamp feature is not enabled, an empty array will be returned. |
RequestId | String | The unique request ID, which is returned for each request. RequestId is required for locating a problem. |
This example shows you how to use TTS through API call.
POST / HTTP/1.1
Host: tts.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: TextToVoice
<Common request parameters>
{
"Text": "Hello World",
"ModelType": "1",
"Volume": "1",
"SessionId": "session-1234",
"Codec": "wav",
"ProjectId": "0",
"SampleRate": "16000",
"PrimaryLanguage": "1",
"Speed": "1",
"EnableSubtitle": true
}
{
"Response": {
"Audio": "UklGRlR/AABXQVZFZm10IBAAAAABAAEAgD4AAAB9AAACABAAZGF0YSx9AAD+////AQD//wAAAAAAAAIAAQADAAMABgAEAAYABQAGAAUABwAIAAgACQAAE......AAgACAAEAAgADAAIAAwACAAQAAwACAAIAAgADAAMAAgACAAIAAwABAAAAAAAAAAAAAAD/////AAAAAAAA//8AAP///v/9//7//v///////v8AAP///////wAA/////wAA/////wAAAAAAAAAAAAAAAAAAAAAAAAAA",
"RequestId": "9a7a1615-3e09-4db2-8032-5c6f497f7e6a",
"SessionId": "session-1234",
"Subtitles": [
{
"Text": "Hello",
"BeginTime": 250,
"EndTime": 450,
"BeginIndex": 0,
"EndIndex": 1
},
{
"Text": "World",
"BeginTime": 450,
"EndTime": 700,
"BeginIndex": 1,
"EndIndex": 2
}
]
}
}
TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.
The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.
Error Code | Description |
---|---|
AuthFailure.InvalidAuthorization | Invalid authorization. |
InternalError.ErrorGetRoute | Invalid route. |
InternalError.ExceedMaxLimit | Traffic is throttled due to high load. |
InternalError.InternalError | Internal error. |
InvalidParameter.InvalidText | The request text contains invalid characters. |
InvalidParameterValue.AppId | Invalid AppId . See the description of AppId . |
InvalidParameterValue.AppIdNotRegistered | The APPID is not registered. Activate the service in the TTS console (https://console.tencentcloud.com/tts) first. |
InvalidParameterValue.Codec | Invalid Codec . See the description of Codec . |
InvalidParameterValue.ErrorCardinalFormat | The number part of the say-as tag of SSML is not a valid constant, which can only contain digits, ",", ".", and " " when the tag attribute is cardinal , currency , or address . |
InvalidParameterValue.InvalidText | The request text contains invalid characters, or it contains no valid characters. |
InvalidParameterValue.MissParameters | Parameter missing. |
InvalidParameterValue.ParticipleError | Error in text segmentation. |
InvalidParameterValue.PrimaryLanguage | Invalid PrimaryLanguage . See the description of PrimaryLanguage . |
InvalidParameterValue.SSMLInvalid | Invalid SSML tag. |
InvalidParameterValue.SampleRate | Invalid SampleRate . See the description of SampleRate . |
InvalidParameterValue.SessionId | Invalid SessionId . See the description of SessionId . |
InvalidParameterValue.Speed | Invalid Speed . See the description of Speed . |
InvalidParameterValue.Text | Text missing. |
InvalidParameterValue.TextEmpty | Empty text. |
InvalidParameterValue.TextNotUtf8 | The text is not encoded in UTF8. |
InvalidParameterValue.Type | Invalid Type . |
InvalidParameterValue.VoiceType | Invalid VoiceType . See the description of VoiceType . |
InvalidParameterValue.Volume | Invalid Volume . See the description of Volume . |
LimitExceeded.AccessLimit | The request frequency exceeds the limit. |
UnsupportedOperation | Unsupported operation. |
UnsupportedOperation.AccountArrears | Overdue payment exists. |
UnsupportedOperation.AuthorizationExpired | Authentication expired. |
UnsupportedOperation.AuthorizationFailed | Authentication failed. |
UnsupportedOperation.ForbiddenUse | Service prohibited. |
UnsupportedOperation.NoFreeAccount | Free tier is used up. |
UnsupportedOperation.PkgExhausted | The resource package is used up. |
UnsupportedOperation.ServerAlreadyOpen | Server opened. |
UnsupportedOperation.ServerDestoryed | The service is already terminated. |
UnsupportedOperation.ServerNotOpen | Service inactivated. |
UnsupportedOperation.ServerStopped | Service stopped. |
UnsupportedOperation.TextTooLong | The text is too long. See the description of the request parameter Text . |
문제 해결에 도움이 되었나요?