/v1/audio/speech生成語音(同步,短文字)
同步生成語音(快線):回傳 200 OK 及音訊 bytes。
同步限制:文字上限 300 個計費 credits;僅接受 voice(預設)或design 模式 — clone 會回傳 400 clone_not_supported_sync,srt: true 會回傳 400 srt_not_supported_sync(兩者均請改用非同步POST /v1/audio/jobs)。
計費:本 endpoint 為實時語音,按 ceil(credits × 1.3) 實扣(X-Credits-Charged已含倍數);實時 WebSocket(逐句串流)按 ceil(字符 × 1.5) 實扣。
快線語義(先到先得):生成池完全空閒時先會接單——接單後同一個請求內等生成完成(一般 ~5–15 秒)並直接回傳 bytes;生成池忙(前面有任務)會如實回傳 `503 {"error":"pool_cold"}`(不扣費),請改用非同步。等待超過 ~45 秒會 cooperative cancel+退款,回傳 503 sync_timeout(帶 Retry-After;X-Request-Id 留作對帳)— 保證交付請改用非同步。
請選擇恰好一種聲音模式 — 三者互斥:
voice—GET /v1/voices的預設聲線 slug(建議;所有預設聲線均已廣東話優化/香港聲線)。需要tts:generatescope。design— 以gender+age描述一個合成聲線。tts:generatescope 或細粒度tts:designscope 均可接受(二者其一即可,因此現有tts:generate金鑰無需任何更改)。clone— 以 base64reference_audio樣本複製聲線(需要tts:clonekey scope)。只需reference_audio;舊版prompt_text欄位已退役(送出會被忽略)。
同時傳送多於一個 voice / design / clone 會回傳 400 voice_mode_conflict。
請求 body · SpeechRequest (必填)
| 欄位 | 型別 | 必填 | 說明 |
|---|---|---|---|
modelstring · enum(1) · 否 | string · enum(1) | 否 | The TTS model. Currently only enum: cantogen-tts default: cantogen-tts |
voicestring · 否 | string | 否 | Preset voice slug from |
textstring · 是 | string | 是 | The text to speak (1–500 characters on the async endpoint; the sync |
pitchinteger · 否 | integer | 否 | DEPRECATED (2026-09-20) — no effect under raw audio delivery. Still accepted with unchanged range validation (−12…+12 semitones, default 0), but the value is ignored. default: 0 |
volumenumber · 否 | number | 否 | DEPRECATED (2026-09-20) — no effect under raw audio delivery. Still accepted with unchanged range validation (0–10, default 1), but the value is ignored. default: 1 |
emotionstring · enum(11) · 否 | string · enum(11) | 否 | Speaking emotion — one of the 11 prod canonical values (happy / angry / sad / surprise / fear / disgust / neutral / confused / anxious / affection / whisper). Legacy MiniMax values (fearful / disgusted / surprised / excited / gentle) are accepted and normalized. The Creator UI's Chinese emotion presets (雀躍 / 冷靜 …) are a separate gallery layer and are not API enum values. enum: happy · angry · sad · surprise · fear · disgust · neutral · confused · anxious · affection · whisper |
stylestring · 否 | string | 否 | Delivery style. Canonical values are English slugs — rhythm: steady / composed / rapid / slow / drawl / brisk / dynamic / staccato; timbre: mellow / cute / sharp / lazy / breathy / hoarse / deep / crisp / feeble / trembling; scene: corporate / promo / wedding / guide / expo / ad / tutorial / news / travel / audiobook / latenight / product / fairytale / podcast / storytelling / sports; character: animation-hero / stylish-uncle / astronaut / support-agent / boss / grandma / lottery-host / news-anchor / sage / late-dj / teacher / storyteller / market-commentator / sports-commentator / girl-next-door / smart-kid. The original Chinese preset values (明快 / 圓潤 / 講古 …) are still accepted as aliases — both are normalized internally to the same canonical value before reaching the engine. Any other free text also passes through. Merged into the engine style slot (order: style → emotion → instruction). |
instructionstring · 否 | string | 否 | Free-text delivery direction in Cantonese, Chinese or English — e.g. 「用興奮嘅語氣講,好似慶祝生日咁」. Applied after |
response_formatstring · enum(2) · 否 | string · enum(2) | 否 | Audio container format. Other formats return enum: mp3 · wav default: mp3 |
srtboolean · 否 | boolean | 否 | Also generate SRT subtitles. When default: false |
seedinteger · 否 | integer | 否 | Reserved. Accepted and validated as an integer but not yet used for reproducibility. |
sample_rateinteger · 否 | integer | 否 | Reserved. Accepted and validated as an integer but not yet applied. |
designDesignObject · 否 | DesignObject | 否 | |
cloneCloneObject · 否 | CloneObject | 否 |
curl -X POST "https://api.canto-gen.com/v1/audio/speech" \
-H "Authorization: Bearer $CANTOGEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"cantogen-tts","voice":"sum","text":"你好,歡迎使用港嘢!","response_format":"mp3"}'範例
{
"model": "cantogen-tts",
"voice": "sum",
"text": "你好,歡迎使用港嘢!",
"response_format": "mp3"
}{
"model": "cantogen-tts",
"design": {
"gender": "female",
"age": "young"
},
"text": "今日天氣幾好,一齊去行山啦。",
"style": "brisk",
"emotion": "happy"
}{
"model": "cantogen-tts",
"voice": "sum",
"text": "生日快樂!祝你心想事成!",
"instruction": "用興奮嘅語氣講,好似慶祝生日咁"
}回應
語音生成成功。回應 body 為原始音訊 bytes。
請求無效。原因請參考 error code。
{
"error": "invalid_model",
"message": "model must be \"cantogen-tts\"."
}{
"error": "voice_mode_conflict",
"message": "voice is mutually exclusive with design and clone."
}{
"error": "text_required",
"message": "text is required."
}{
"error": "text_too_long",
"message": "text exceeds 500 characters."
}{
"error": "unsupported_format",
"message": "response_format supports mp3 and wav (MVP)."
}{
"error": "invalid_emotion",
"message": "emotion must be one of: happy/angry/sad/surprise/fear/disgust/neutral/confused/anxious/affection/whisper."
}{
"error": "invalid_instruction",
"message": "instruction exceeds 500 characters."
}{
"error": "reference_audio_required",
"message": "clone.reference_audio is required."
}{
"error": "design_gender_and_age_required",
"message": "design.gender and design.age are required."
}{
"error": "invalid_srt",
"message": "srt must be a boolean."
}{
"error": "clone_not_supported_sync",
"hint": "use POST /v1/audio/jobs (async)"
}{
"error": "srt_not_supported_sync",
"hint": "use POST /v1/audio/jobs (async)"
}API 金鑰缺失、格式錯誤、無效或已過期。
{
"error": "invalid_or_expired_token"
}禁止存取 — 金鑰缺少所需 scope(clone 請求需要 tts:clone;design 請求接受 tts:generate 或 tts:design),或已達金鑰的每月 credits 上限。
{
"error": "insufficient_scope",
"scope": "tts:clone"
}{
"error": "monthly_cap_reached",
"used": 100000
}觸發速率限制(每用戶每分鐘;同一帳戶嘅所有金鑰加埋計,開多把金鑰唔會突破總額)。請等待 Retry-After 秒後重試。
{
"error": "rate_limit_exceeded",
"retry_after": 42
}同步快線不可用,按 error code 分:pool_cold=隊列忙,請求未被接受(不扣費),亦不會靜默轉用非同步;sync_generation_failed=等待期間任務失敗或取消(已自動退款);sync_timeout=同步等待超過約 45 秒 — 任務已 cooperative cancel 並於數秒內退款(回應帶 Retry-After,可稍後重試或改用非同步;X-Request-Id 留作對帳);jobs_unavailable=入隊基建暫時故障;service_unavailable=語音引擎暫時離線(維護或後端未就緒),請求未受理、不扣費(回應帶 Retry-After,預設 60 秒);rate_limit_unavailable=速率限制基建暫時不可用,為免放行未受管流量而拒絕,同樣未受理、不扣費(Retry-After 預設 5 秒)。長文字/要保證交付請改以 POST /v1/audio/jobs 提交。
{
"error": "pool_cold",
"hint": "use POST /v1/audio/jobs (async)"
}