CosyVoice 的 HTTP 非即時語音合成介面,包含非串流和 SSE 串流呼叫、請求參數及回應欄位。
介面位址
將 YOUR_WORKSPACE_ID 替換為對應地區的業務空間 ID,並使用同地區的 API Key。
- 華北 2(北京)
POST https://YOUR_WORKSPACE_ID.cn-beijing.maas.aliyuncs.com/api/v1/services/audio/tts/SpeechSynthesizer請求標頭
| 參數 | 類型 | 必選 | 說明 |
|---|---|---|---|
Authorization | string | 必選 | 驗證權杖,格式為 Bearer <your_api_key>。 |
Content-Type | string | 必選 | 固定為 application/json。 |
X-DashScope-SSE | string | 可選 | 串流輸出時設定為 enable;未設定時傳回完整結果。 |
呼叫範例
- 非串流
- 串流
SSE 事件可能包含多行
data:。合併同一事件的所有 data: 行後解析 JSON;將音訊區塊按事件順序 Base64 解碼並串接。結束幀的 output.finish_reason 為 stop,並傳回完整音訊 URL。請求主體
| 參數 | 類型 | 必選 | 預設值 | 說明 |
|---|---|---|---|---|
model | string | 必選 | — | 語音合成模型 ID。支援模型與地區請參見非即時語音合成。 |
input | object | 必選 | — | 輸入參數物件。 |
input.text | string | 必選 | — | 待合成文字。使用 SSML 時同時設定 enable_ssml=true;LaTeX 輸入無需額外設定。支援範圍、標籤和語法請參見 SSML 與 LaTeX。 |
input.voice | string | 必選 | — | 音色 ID。系統音色參見音色清單;自訂音色透過聲音複製或聲音設計建立,並使用綁定的目標模型合成。 |
input.format | string | 可選 | mp3 | 音訊編碼格式。可選 mp3、pcm、wav、opus。 |
input.sample_rate | integer | 可選 | 22050 | 音訊取樣率(Hz)。可選 8000、12000、16000、22050、24000、44100、48000。format=opus 時僅支援 8000、12000、16000、24000、48000。 |
input.volume | integer | 可選 | 50 | 音量,取值範圍 [0, 100]。 |
input.rate | float | 可選 | 1.0 | 語速,取值範圍 [0.5, 2.0]。 |
input.bit_rate | integer | 可選 | 32 | 音訊位元率(kbps),取值範圍 [6, 510];僅在 format=opus 時生效。 |
input.pitch | float | 可選 | 1.0 | 音調,取值範圍 [0.5, 2.0]。 |
input.enable_ssml | boolean | 可選 | — | 是否啟用 SSML。模型、音色和介面限制請參見使用限制。 |
input.word_timestamp_enabled | boolean | 可選 | false | 是否傳回字級時間戳記,僅用於串流輸出。支援 cosyvoice-v3.5-plus、cosyvoice-v3.5-flash、cosyvoice-v3-flash、cosyvoice-v3-plus、cosyvoice-v2 的複製音色,以及音色清單中標記支援的系統音色。其他模型的複製音色不支援。 |
input.seed | integer | 可選 | 0 | 隨機種子,取值範圍 [0, 65535]。模型版本、文字、音色和其他參數相同時,使用相同 seed 可重現相同合成結果。 |
input.language_hints | array[string] | 可選 | — | 合成目標語言,目前僅處理陣列的第一個元素。此參數與複製樣本的來源語言無關。數字、縮寫、符號或小語種發音不符合預期時可設定,語言代碼見下方清單。複製來源語言參見聲音複製 API。 |
input.instruction | string | 可選 | — | 控制方言、情感或角色等合成效果的指令。適用模型、音色與寫法參見指令控制。 |
input.enable_aigc_tag | boolean | 可選 | false | 是否在 WAV、MP3、Opus 音訊中嵌入 AIGC 隱性標識。僅 cosyvoice-v3-flash、cosyvoice-v3-plus、cosyvoice-v2 支援。 |
input.aigc_propagator | string | 可選 | 阿里雲 UID | 隱性標識的 ContentPropagator 欄位,用於標識傳播者;僅在 enable_aigc_tag=true 時生效。僅 cosyvoice-v3-flash、cosyvoice-v3-plus、cosyvoice-v2 支援。 |
input.aigc_propagate_id | string | 可選 | 本次請求的 Request ID | 隱性標識的 PropagateID 欄位,用於標識本次傳播行為;僅在 enable_aigc_tag=true 時生效。僅 cosyvoice-v3-flash、cosyvoice-v3-plus、cosyvoice-v2 支援。 |
input.hot_fix | object | 可選 | — | 文字熱修復。pronunciation 自訂指定詞語的發音,replace 在合成前替換指定文字。cosyvoice-v2 不支援。 |
input.enable_markdown_filter | boolean | 可選 | false | 是否在合成前過濾 Markdown 標記。僅 cosyvoice-v3-flash 的複製音色支援。 |
語言代碼
zh:中文en:英語fr:法語de:德語ja:日語ko:韓語ru:俄語pt:葡萄牙語th:泰語id:印尼語vi:越南語es:西班牙語it:義大利語ms:馬來語fil:菲律賓語ar:阿拉伯語
回應主體
| 參數 | 類型 | 說明 |
|---|---|---|
request_id | string | 本次請求的唯一識別碼。 |
output | object | 模型輸出物件。 |
output.finish_reason | string | 任務停止原因。null 表示合成中,stop 表示合成結束。 |
output.type | string | 僅串流輸出傳回。sentence-begin 表示句子開始;sentence-synthesis 表示音訊區塊,同一句可包含多個區塊;sentence-end 表示句子結束並傳回用量資訊。音訊區塊與資料幀一一對應,按順序附加至同一檔案。 |
output.original_text | string | 使用者輸入文字切分後的句子內容;最後一句可能沒有此欄位。 |
output.sentence | object | 句子資訊。 |
output.sentence.index | integer | 句子編號,從 0 開始。 |
output.sentence.words | array | 句子中的字及其時間戳記資訊。 |
output.sentence.words[].text | string | 字。 |
output.sentence.words[].begin_index | integer | 字在句子中的開始位置,從 0 開始。 |
output.sentence.words[].end_index | integer | 字在句子中的結束位置,從 1 開始。 |
output.sentence.words[].begin_time | integer | 字對應音訊的開始時間戳記(毫秒)。 |
output.sentence.words[].end_time | integer | 字對應音訊的結束時間戳記(毫秒)。 |
output.audio | object | 合成音訊物件。 |
output.audio.data | string | 串流輸出的 Base64 音訊區塊;非串流輸出時為空。 |
output.audio.url | string | 完整音訊檔案的 URL,有效期 24 小時。 |
output.audio.id | string | 合成音訊的識別碼。 |
output.audio.expires_at | integer | url 的到期時間戳記。 |
usage | object | 用量資訊。 |
usage.characters | integer | 累計計費字元數。 |
- 非串流
- 串流