Sync Speech Synthesis

Provides synchronous text-to-speech over the WebSocket protocol with streaming audio output.
WSS/v1/ws/tts
ProtocolWebSocket (text JSON + binary audio)
Gateway path/v1/ws/tts
ResponseBinary audio frames + text JSON control frames

Authorization

AuthorizationstringheaderRequired
HTTP: Bearer Auth

Connection

URL

Use the following URL to establish a WebSocket connection:

wss://{gateway-host}/v1/ws/tts?model={model_id}

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

  1. Open WebSocket connection
  2. Send text frame start with the full text to synthesize, plus voice_setting / audio_setting
  3. Receive binary audio frames in order
  4. 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

Request stage. Fixed value: start

sidstring

Optional client session ID, echoed in the response. Generated by the server if omitted

textstringRequired

Text to synthesize. Length must be less than 500 characters

voice_settingobjectRequired

Basic voice settings

voice_setting.voice_idstringRequired

Voice ID, obtainable via the query available voices API

voice_setting.speedinteger

Speed range [0, 100], default 50.
See Voice Parameter Support for details.

voice_setting.volumeinteger

Volume range [0, 100], default 50.
See Voice Parameter Support for details.

voice_setting.pitchinteger

Pitch range [0, 100], default 50.
See Voice Parameter Support for details.

voice_setting.brightinteger

Brightness range [0, 100], default 50.
See Voice Parameter Support for details.

voice_setting.emotionstring

Pronunciation emotion. Optional values: happy, angry, depressed, whisper, loudly, neutral. Currently only supported by cn_male_chenyu when language is Chinese and dialect is default.

voice_setting.languagestring

Pronunciation language. Optional values: zh, ja, ko, th, vi, id, ms, my, lo, km, tl, en. Default: zh.
Supported languages by voice:
  • `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

Pronunciation dialect. Optional values: default, yueyu, sichuan. Default: default.
Currently, only `cn_male_chenyu` supports the following dialects:
  • `yueyu` (Cantonese)
  • `sichuan` (Sichuan dialect)

audio_settingobject

Audio output settings

audio_setting.audio_sample_rateinteger

Sample rate, enum [8000, 16000, 24000, 32000], default 32000

audio_setting.formatstring

Output format, enum [mp3, pcm], default mp3

audio_setting.channelinteger

Number of channels, enum [1], default 1

pronunciation_dictobject

Custom pronunciation rules

pronunciation_dict.tonestring[ ]

Pronunciation/phonetic replacement rules, example: ["Liangshan/Liang<py>liang2</py>shan"].
See Custom Pronunciation Rules for tag details and support.

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

Same as start.sid when provided by the client

base_respobjectRequired

Status code and details of this request

base_resp.status_codeintegerRequired

Status code, 0 means success

base_resp.status_msgstringRequired

Status details; success when "success"

endbooleanRequired

true when this synthesis round ends

Error codes

Business Error CodeDescriptionSolution
100001Parameter error (model / voice_id / text limit / streaming not supported, etc.; common code)Check model / voice_id / text length, etc.
204001Sensitive words in textModify the text and retry
204008Idle timeout (default 30s without activity)Send messages in time or reconnect
204011Missing start or duplicate startSend start only once per connection
204099Server internal errorRetry 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 IDLanguageDialectspeedvolumepitchbright
cn_female_xiaodi_warmzhdefault✓✓✓✓
cn_male_chenyuzhdefault✗✓✓✓
cn_male_chenyuzhyueyu✓✓✓✓
cn_male_chenyuzhsichuan✓✓✓✓
cn_male_chenyutldefault✗✗✗✗
en_male_johnnyendefault✓✓✓✓
en_female_janeendefault✓✓✓✓
cn_male_chenyu_robotzhdefault✗✓✓✓
cn_male_chenyu_elderlyzhdefault✗✓✓✓
cn_male_chenyu_steadyzhdefault✗✓✓✓
cn_male_chenyu_fluentzhdefault✗✓✓✓
cn_female_shashazh, ja, ko, th, vi, iddefault✗✓✓✓
cn_female_shashakmdefault✗✗✗✗
cn_female_jiajiazhdefault✗✓✓✓
cn_female_jiajiaid, ms, my, lodefault✗✗✗✗
cn_female_ruolinzhdefault✗✓✓✓

Custom Pronunciation Rules

Use the following tags to control pronunciation and segmentation. Tag support varies by voice; see the support table below.

CategoryTagDescriptionExampleEffect
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 IDLanguageDialectSupported Tags
cn_female_xiaodi_warmzhdefaultAll supported
cn_male_chenyuzhdefaultPartial (value、code、tel、py、letter、sub、word)
cn_male_chenyuzhyueyuAll supported
cn_male_chenyuzhsichuanAll supported
cn_male_chenyutldefaultNot supported
en_male_johnnyendefaultAll supported
en_female_janeendefaultAll supported
cn_male_chenyu_robotzhdefaultPartial (value、code、tel、py、letter、sub、word)
cn_male_chenyu_elderlyzhdefaultPartial (value、code、tel、py、letter、sub、word)
cn_male_chenyu_steadyzhdefaultPartial (value、code、tel、py、letter、sub、word)
cn_male_chenyu_fluentzhdefaultPartial (value、code、tel、py、letter、sub、word)
cn_female_shashazh, ja, ko, th, vi, iddefaultPartial (value、code、tel、py、letter、sub、word)
cn_female_shashakmdefaultNot supported
cn_female_jiajiazhdefaultPartial (value、code、tel、py、letter、sub、word)
cn_female_jiajiaid, ms, my, lodefaultNot supported
cn_female_ruolinzhdefaultPartial (value、code、tel、py、letter、sub、word)