Sync Speech Synthesis
| Protocol | WebSocket (text JSON + binary audio) |
| Gateway path | /v1/ws/tts |
| Response | Binary audio frames + text JSON control frames |
Authorization
- Security Scheme Type: http
- HTTP Authorization Scheme: Bearer API_key,Used to verify account information, can be viewed in Pay-as-you-go > API Key Management .
Connection
URL
Use the following URL to establish a WebSocket connection:
Query parameters
modelRequired
Model code. Option: u2-tts.
Handshake headers (client → gateway)
AuthorizationRequired
Bearer {api_key}
ConnectionRequired
Upgrade
UpgradeRequired
websocket
Handshake failure (WebSocket not established)
Returns HTTP 401 / 429 etc.
Session flow
- Open WebSocket connection
- Send text frame start with the full text to synthesize, plus voice_setting / audio_setting
- Receive binary audio frames in order
- Receive text control frame (end=true); this synthesis round ends
Client messages
Text frame: start
Only one start is allowed per connection. Flat JSON root object.
typestringRequired
sidstring
textstringRequired
voice_settingobjectRequired
voice_setting.voice_idstringRequired
voice_setting.speedinteger
voice_setting.volumeinteger
voice_setting.pitchinteger
voice_setting.brightinteger
voice_setting.emotionstring
voice_setting.languagestring
- `cn_female_shasha`: `zh` (Chinese), `ja` (Japanese), `ko` (Korean), `th` (Thai), `vi` (Vietnamese), `id` (Indonesian), `km` (Khmer)
- `cn_female_jiajia`: `zh` (Chinese), `id` (Indonesian), `ms` (Malay), `my` (Burmese), `lo` (Lao)
- `cn_male_chenyu`: `zh` (Chinese), `tl` (Filipino)
- `en_male_johnny`, `en_female_jane`: `en` (English)
- Other system voices: `zh` (Chinese)
voice_setting.dialectstring
- `yueyu` (Cantonese)
- `sichuan` (Sichuan dialect)
audio_settingobject
audio_setting.audio_sample_rateinteger
audio_setting.formatstring
audio_setting.channelinteger
pronunciation_dictobject
pronunciation_dict.tonestring[ ]
Server response
Binary frame: audio
- Type: WebSocket Binary
- Content: Audio chunks encoded as audio_setting.format (not Base64); concatenate in order for the full audio
Text control frame
sidstring
base_respobjectRequired
base_resp.status_codeintegerRequired
base_resp.status_msgstringRequired
endbooleanRequired
Error codes
| Business Error Code | Description | Solution |
|---|---|---|
| 100001 | Parameter error (model / voice_id / text limit / streaming not supported, etc.; common code) | Check model / voice_id / text length, etc. |
| 204001 | Sensitive words in text | Modify the text and retry |
| 204008 | Idle timeout (default 30s without activity) | Send messages in time or reconnect |
| 204011 | Missing start or duplicate start | Send start only once per connection |
| 204099 | Server internal error | Retry later; if it persists, contact support with sid |
Voice Parameter Support
Support for speed, volume, pitch, and brightness by voice ID, language, and dialect:
| Voice ID | Language | Dialect | speed | volume | pitch | bright |
|---|---|---|---|---|---|---|
| cn_female_xiaodi_warm | zh | default | ✓ | ✓ | ✓ | ✓ |
| cn_male_chenyu | zh | default | ✗ | ✓ | ✓ | ✓ |
| cn_male_chenyu | zh | yueyu | ✓ | ✓ | ✓ | ✓ |
| cn_male_chenyu | zh | sichuan | ✓ | ✓ | ✓ | ✓ |
| cn_male_chenyu | tl | default | ✗ | ✗ | ✗ | ✗ |
| en_male_johnny | en | default | ✓ | ✓ | ✓ | ✓ |
| en_female_jane | en | default | ✓ | ✓ | ✓ | ✓ |
| cn_male_chenyu_robot | zh | default | ✗ | ✓ | ✓ | ✓ |
| cn_male_chenyu_elderly | zh | default | ✗ | ✓ | ✓ | ✓ |
| cn_male_chenyu_steady | zh | default | ✗ | ✓ | ✓ | ✓ |
| cn_male_chenyu_fluent | zh | default | ✗ | ✓ | ✓ | ✓ |
| cn_female_shasha | zh, ja, ko, th, vi, id | default | ✗ | ✓ | ✓ | ✓ |
| cn_female_shasha | km | default | ✗ | ✗ | ✗ | ✗ |
| cn_female_jiajia | zh | default | ✗ | ✓ | ✓ | ✓ |
| cn_female_jiajia | id, ms, my, lo | default | ✗ | ✗ | ✗ | ✗ |
| cn_female_ruolin | zh | default | ✗ | ✓ | ✓ | ✓ |
Custom Pronunciation Rules
Use the following tags to control pronunciation and segmentation. Tag support varies by voice; see the support table below.
| Category | Tag | Description | Example | Effect |
|---|---|---|---|---|
| Number | <value> | Pronounce the digit string as a numeric value | 这是第<value>110</value>会议室 | 这是第一百一十会议室 |
| <code> | Pronounce the digit string as a code (“1” as “一”) | 这是第<code>110</code>会议室 | 这是一一零会议室 | |
| <tel> | Pronounce the digit string as a phone number (“1” as “幺”) | 会议室分机号为<tel>110</tel> | 会议室分机号为幺幺零 | |
| Phonetics | <py> | Force the engine to pronounce Chinese characters with the specified pinyin | 搜索结果为<py>wei2</py>空<py>kong1</py> | 搜索结果为(wei2)空(kong1) |
| <pname> | Correctly pronounce polyphonic characters used as surnames | 播放<pname>单田芳</pname>的评书 | 播放单(shan4)田芳的评书 | |
| Segmentation | <word> | Force word segmentation to fix incorrect splits, e.g. distinguish “(乒乓球)(拍卖)(完了)” from “(乒乓)(球拍)(卖完了)” | <word>乒乓</word><word>球拍</word><word>卖完了</word> | (乒乓)(球拍)(卖完了) |
| <phrase> | Force phrase breaks (longer pause than word) to fix incorrect phrasing, e.g. distinguish “(爸爸亲了我妈妈)(也亲了我)” from “(爸爸亲了我)(妈妈也亲了我)” | <phrase>爸爸亲了我</phrase><phrase>妈妈也亲了我</phrase> | (爸爸亲了我) (妈妈也亲了我) | |
| English | <letter> | Spell the marked English text letter by letter | 世界卫生组织的英文缩写<letter>WHO</letter> | 世界卫生组织的英文缩写是(W)(H)(O) |
| Other | <mute> | Insert a pause of the specified duration (milliseconds) | 请您再说一遍<mute>300</mute>或说取消 | 请您再说一遍(pause 300ms)或说取消 |
| <sub> | Replace the marked text with the alias attribute value when speaking | 气压的测量单位是<sub alias="毫米汞柱">mmHg</sub> | 气压的测量单位是毫米汞柱 |
Tag Support
| Voice ID | Language | Dialect | Supported Tags |
|---|---|---|---|
| cn_female_xiaodi_warm | zh | default | All supported |
| cn_male_chenyu | zh | default | Partial (value、code、tel、py、letter、sub、word) |
| cn_male_chenyu | zh | yueyu | All supported |
| cn_male_chenyu | zh | sichuan | All supported |
| cn_male_chenyu | tl | default | Not supported |
| en_male_johnny | en | default | All supported |
| en_female_jane | en | default | All supported |
| cn_male_chenyu_robot | zh | default | Partial (value、code、tel、py、letter、sub、word) |
| cn_male_chenyu_elderly | zh | default | Partial (value、code、tel、py、letter、sub、word) |
| cn_male_chenyu_steady | zh | default | Partial (value、code、tel、py、letter、sub、word) |
| cn_male_chenyu_fluent | zh | default | Partial (value、code、tel、py、letter、sub、word) |
| cn_female_shasha | zh, ja, ko, th, vi, id | default | Partial (value、code、tel、py、letter、sub、word) |
| cn_female_shasha | km | default | Not supported |
| cn_female_jiajia | zh | default | Partial (value、code、tel、py、letter、sub、word) |
| cn_female_jiajia | id, ms, my, lo | default | Not supported |
| cn_female_ruolin | zh | default | Partial (value、code、tel、py、letter、sub、word) |