Content | Description |
Voice types | Supports Chinese and English voices. For voice IDs, see the Voice List page. You can set the corresponding voice ID via the VoiceType API parameter. |
Supported Scenarios | General, customer service, emotional, reading, news, and so on. For details, see the Voice List page. |
Audio properties | Sampling rate: 8000Hz, 16000Hz, 24000Hz (partially supported; see the Voice List page for details). Sampling precision: 16 bits Channels: mono |
Audio formats | pcm,mp3 |
Request protocol | wss protocol |
Request URL | wss://tts.cloud.tencent.com/stream_wsv2?{request parameters} |
API authentication | |
Response format | Audio information is returned as raw binary data via binary-type frames, enabling playback while receiving. text information is returned as JSON-format data (such as status codes, timestamps, and server events) via text-type frames. |
Concurrency limit | By default, a single account is limited to 20 concurrent streams (shared with the real-time TTS API). If you need to increase the concurrency limit, contact your business manager for consultation. |
Call limits | 1. Within a single streaming session, the total number of synthesized characters must not exceed 10,000 characters. 2. The input stream can continuously send text for synthesis. If no text is sent for more than 10 minutes, the server will synthesize the cached text normally and then close the connection. 3. Parameters such as speech rate, volume, and emotion can only be set before the input stream is enabled. |
Text limits | 1. Streaming synthesis text does not support SSML tags. 2. Upon receiving streaming synthesis text, the server caches it, then synthesizes it after sentence segmentation. The punctuation marks used for segmentation include full-width symbols . ; ? !, half-width symbols ; ? !, and line breaks. 3. Text synthesis relies on sentence completeness. Ensure that the synthesized text contains correct punctuation, especially at the end of the text. Otherwise, the text may be cached for an extended period without being synthesized. |
Field Name | Type | Description |
code | Integer | Status code. 0 indicates normal, and a non-zero value indicates an error has occurred. |
message | String | Error description. It displays the specific cause of the error when an error occurs. This text may be frequently updated or changed as business evolves or user experience is optimized. |
session_id | String | The unique ID for this session. It is generated and assigned to the call parameters by the client during the handshake phase. |
request_id | String | The unique ID for this session. It is automatically generated by the server and returned with the text message. |
message_id | String | The unique ID for this message. |
result | Result | The TTS text timestamp. |
ready | Integer | READY event: A value of 1 for this field indicates that the server is initialized, and the client can start sending text synthesis requests. |
final | Integer | FINAL event: A value of 1 for this field indicates that text synthesis is complete, and the client must actively close the WebSocket connection upon receiving it. |
heartbeat | Integer | HEARTBEAT event: A value of 1 for this field indicates a heartbeat packet, which can be ignored by the client upon receipt. |
Field Name | Type | Description |
subtitles | Subtitle Array | The word list for the current passage, with the Subtitle struct format as follows: Text: A String-type field containing the content of the character. BeginTime: An Integer-type field indicating the start time of the character within the entire audio stream. EndTime: An Integer-type field indicating the end time of the character within the entire audio stream. BeginIndex: An Integer-type field indicating the start position of the character within the entire text, starting from 0. EndIndex: An Integer-type field indicating the end position of the character within the entire text, starting from 0. Phoneme: A String-type field containing the phoneme of the character. (Note: This field may return null, indicating that no valid value can be obtained.) |
wss://tts.cloud.tencent.com/stream_wsv2?{request_parameters}
key1=value2&key2=value2...(Both keys and values must be URL-encoded)
Parameter Name | Required | Type | Description |
Action | Yes | String | The name of the API to call. Value: TextToStreamAudioWSv2 (case-sensitive). |
AppId | Yes | Integer | The AppId of the account. Ensure that the data type of this field is int. |
AccountArea | No | Integer | International account identifier. Value: 0: Indicates a domestic account (default). 1: Indicates an international account. |
SecretId | Yes | String | |
Timestamp | Yes | Integer | The current UNIX timestamp, which records the time when the API request is initiated. For example, 1529223702. If it differs too much from the current time, a signature expiration error will occur. |
Expired | Yes | Integer | The validity period of the signature. It is a value that conforms to the UNIX Epoch timestamp specification, measured in seconds. Expired must be greater than Timestamp, and (Expired - Timestamp) must be less than 90 days. |
SessionId | Yes | String | The globally unique identifier for TTS. One WebSocket connection corresponds to one identifier. It is generated by the user (UUID is recommended) and can be up to 128 bits in length. |
VoiceType | No | Integer | The voice ID. Supports Chinese and English voices. For the complete list of voice IDs, see the Voice List. Attention: If you are using the one-sentence version of VRS, enter the fixed value "200000000". |
FastVoiceType | No | String | The voice ID for one-shot VRS. Required when a one-shot VRS voice is used. |
Volume | No | Float | Volume. Range: [-10, 10], corresponding to the volume level. The default value is 0, which represents the normal volume level. A larger value indicates a higher volume. |
Speed | No | Float | Speech rate. Range: [-2, 6], corresponding to different speech rates: -2: Indicates 0.6 times. -1: Indicates 0.8 times. 0: Indicates 1.0 times (default). 1: Indicates 1.2 times. 2: Indicates 1.5 times. 6: Indicates 2.5 times. If you need a more granular speech rate, you can keep two decimal places, for example, 0.5/1.25/2.81, and so on. |
SampleRate | No | Integer | Audio sample rate 24000: 24k (supported by some voices; see the Voice List for details). 16000: 16k (default) 8000:8k |
Codec | Yes | String | Returned audio format pcm: Returns binary pcm audio (default). mp3: Returns binary mp3 audio. |
EnableSubtitle | No | Boolean | Whether to enable the timestamp feature. The default value is false. |
SegmentRate | No | Integer | Sentence segmentation sensitivity threshold. Value range: [0,1,2]. Default value: 0. A larger value makes sentence segmentation less likely to occur, and the model tends to segment sentences only based on punctuation marks. It is recommended not to adjust this parameter arbitrarily, as doing so may affect the synthesis quality. |
Signature | Yes | String | API signature parameter. |
Action=TextToStreamAudioWSv2&AppId=130046****&Codec=pcm&EnableSubtitle=True&Expired=1688697305&SampleRate=16000&SecretId=*****XcaKs2w4vZw5zTCrHRM7dOwre9*****&SessionId=b78ae3ba-1ba5-11ee-a106-768645a5c72a&Speed=0&Timestamp=1688610905&VoiceType=101001&Volume=0
Request method (GET) + Domain address (tts.cloud.tencent.com/stream_wsv2) + Request parameters (?Action=TextToStreamAudioWSv2&other parameters...)
GETtts.cloud.tencent.com/stream_wsv2?Action=TextToStreamAudioWSv2&AppId=130046****&Codec=pcm&EnableSubtitle=True&Expired=1688697305&SampleRate=16000&SecretId=*****XcaKs2w4vZw5zTCrHRM7dOwre9*****&SessionId=b78ae3ba-1ba5-11ee-a106-768645a5c72a&Speed=0&Timestamp=1688610905&VoiceType=101001&Volume=0
SecretKey=*****SkqpeHgqmSz*****, encrypt it using the HMAC-SHA1 algorithm and then perform base64 encoding:Base64Encode(HmacSha1("GETtts.cloud.tencent.com/stream_wsv2?Action=TextToStreamAudioWSv2&AppId=130046****&Codec=pcm&EnableSubtitle=True&Expired=1688697305&SampleRate=16000&SecretId=*****XcaKs2w4vZw5zTCrHRM7dOwre9*****&SessionId=b78ae3ba-1ba5-11ee-a106-768645a5c72a&Speed=0&Timestamp=1688610905&VoiceType=101001&Volume=0", "*****SkqpeHgqmSz*****"))
d2BGEmCjNFHCaTTMc8Xu2mmpXlc=
wss://tts.cloud.tencent.com/stream_wsv2?Action=TextToStreamAudioWSv2&AppId=130046****&Codec=pcm&EnableSubtitle=True&Expired=1688697305&SampleRate=16000&SecretId=*****XcaKs2w4vZw5zTCrHRM7dOwre9*****&SessionId=b78ae3ba-1ba5-11ee-a106-768645a5c72a&Speed=0&Timestamp=1688610905&VoiceType=101001&Volume=0&Signature=4Lv%2Bk6y6v5VRT/iBFPU%2BGyfeiy0%3D
{"code":0,"message":"success","session_id":"e042008c-1019-11ee-8b49-6c92bf65e6fe","request_id":"b028dfe6-d7af-4d25-b61d-dcae685aa81f","message_id":"f81c0771-5606-478e-9560-555a5717ea25","final":0,"result":{"subtitles":null}}
{"code":0,"message":"success","session_id":"da916680-31f8-11ef-997c-52540037edd7","request_id":"1bc1bab3-170d-4443-8685-238ce6bb6420","message_id":"b211e1d5-a742-4f65-8a11-af1f0757383e","final":0,"ready":1,"heartbeat":0,"result":{"subtitles":null}}
{"session_id": "381665d8-31f6-11ef-894a-52540037edd7", "message_id": "3b46df26-31f6-11ef-894a-52540037edd7", "action": "ACTION_SYNTHESIS", "data": "\\u5355\\u662f\\u5468\\u56f4\\u77ed\\u77ed\\u7684\\u6ce5\\u5899\\u6839\\u4e00\\u5e26\\uff0c\\u5c31\\u6709\\u65e0\\u9650\\u8da3\\u5473\\u3002"}
{"code":0,"message":"success","session_id":"659f1260-101a-11ee-959d-6c92bf65e6fe","request_id":"20ebf801-53ee-4a58-96ab-c63e0f16044a","message_id":"8d4a2f2b-3b15-445c-933b-74b6b44cd882","final":0,"result":{"subtitles":[{"Text":"Welcome","BeginTime":250,"EndTime":570,"BeginIndex":0,"EndIndex":1,"Phoneme":"huan1"},{"Text":"to","BeginTime":570,"EndTime":770,"BeginIndex":1,"EndIndex":2,"Phoneme":"ying2"},{"Text":"Tencent","BeginTime":770,"EndTime":1020,"BeginIndex":2,"EndIndex":3,"Phoneme":"shi3"},{"Text":"Cloud","BeginTime":1020,"EndTime":1270,"BeginIndex":3,"EndIndex":4,"Phoneme":"yong4"}]}}
{"code":10001,"message":"Invalid parameter (Please check your parameter VoiceType)","session_id":"b6b10dc0-101a-11ee-9e72-6c92bf65e6fe","request_id":"a2edbe4f-c12f-48e6-8810-fda7a0992f79","message_id":"da63be2f-d44e-4f3b-a2d7-0b19a3748d23","final":0,"result":{"subtitles":null}}
{"code":0,"message":"success","session_id":"da916680-31f8-11ef-997c-52540037edd7","request_id":"1bc1bab3-170d-4443-8685-238ce6bb6420","message_id":"a985e1d5-a742-4f65-8a11-af1f07574237","final":0,"ready":0,"heartbeat":1,"result":{"subtitles":null}}
{"session_id": "da916680-31f8-11ef-997c-52540037edd7", "message_id": "de674bee-31f8-11ef-997c-52540037edd7", "action": "ACTION_COMPLETE", "data": ""}
{"code":0,"message":"success","session_id":"dbb8417e-101a-11ee-840e-6c92bf65e6fe","request_id":"99207183-3bda-42de-a1f4-6d8838122ad3","message_id":"d56a3fed-0dd6-4dc6-b434-416ae1b69f0f","final":1,"ready":0,"heartbeat":0,"result":{"subtitles":null}}

Command | Term | data | Description |
ACTION_SYNTHESIS | Text synthesis command | Text to synthesize | After receiving the READY event, the client can continuously call this instruction to send text for synthesis. The interval between sending two synthesis instructions must be less than or equal to 10 minutes. If a send timeout occurs, the server returns a timeout error (error code 10009, for notification only and can be ignored). After normally synthesizing the cached text, it notifies the client to close the connection. |
ACTION_COMPLETE | Synthesis completion command | Empty string | After sending all text, the client sends this instruction to notify the server that text transmission is complete. |
ACTION_RESET | Clear cache command | Empty string | The synthesis service receives text sent by the client, caches it, and then performs synthesis in batches. After receiving the RESET instruction, the server side clears the text in the cache that has not yet been synthesized. Attention: When an instruction is received, any text that is already in the synthesis process will not be affected. |
{"session_id": "dbb8417e-101a-11ee-840e-6c92bf65e6fe", // The unique session id, passed in by the client when establishing the connection."message_id": "3b46df26-31f6-11ef-894a-52540037edd7", // The unique id for this message."action": "ACTION_SYNTHESIS", // The instruction type."data": "" // The instruction data.}
{"code": 0, // The error code."message": "success", // The error message."session_id": "dbb8417e-101a-11ee-840e-6c92bf65e6fe", // The unique session id, passed in by the client when establishing the connection."request_id": "99207183-3bda-42de-a1f4-6d8838122ad3", // The unique session id, generated by the server and returned with the message."message_id": "d56a3fed-0dd6-4dc6-b434-416ae1b69f0f", // The unique id for this message."final": 1, // The event type."ready": 0,"heartbeat": 0,"result": { // A server event. This field can be ignored."subtitles": null}}
Value | Description |
10001 | Invalid parameter. For details, refer to the message field. |
10002 | Concurrent call limit exceeded for the account. |
10003 | Authentication Failure |
10004 | Client data upload timeout. |
10005 | Client connection disconnected |
10006 | Streaming input text contains SSML. |
10007 | Streaming input text exceeds the maximum length limit. |
10008 | The streaming input text channel is closed. |
10009 | The streaming input text was not sent due to a timeout. The server will close the connection normally after synthesis is complete. |
Value | Description |
20000 | Backend Error |
20001 | Backend service processing failed. |
20002 | Backend engine synthesis failure. |
20003 | Backend engine synthesis timeout. |
피드백