> ## Documentation Index
> Fetch the complete documentation index at: https://apixo.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# CosyVoice 3.5 Flash API：用自訂音色合成語音

> CosyVoice 3.5 Flash 文字轉語音 API 在語音、複製和設計模式中使用自訂複製或設計的語音

## 概覽

CosyVoice 3.5 Flash 是阿里巴巴的音訊模型，支援文字轉語音，也能建立自訂音色。在 APIXO Playground 試用後，可依本頁範例呼叫 API。

| 功能 | 值 |
| - | - |
| 模型 ID | `cosyvoice-3-5-flash` |
| 模式 | `speech`, `clone`, `design` |
| 內建聲音 | 否 |
| 自訂音色 | 是 |
| 語音提示長度 | 1 至 20000 個字元 |
| 設計提示長度 | 1 至 500 個字元 |
| 預覽文字長度 | 1 至 200 個字元 |
| 複製音訊 URL | 正好 1 個 URL |

## 端點與身分驗證

API 基底網址：

```text theme={null}
https://api.apixo.ai/api/v1
```

| 方法 | 端點 | 用途 |
| - | - | - |
| `POST` | `/generateTask/cosyvoice-3-5-flash` | 提交演講、克隆或設計任務 |
| `GET` | `/statusTask/cosyvoice-3-5-flash?taskId={taskId}` | 查詢任務狀態並取得結果 |

每個請求都必須附上 APIXO API 金鑰：

```http theme={null}
Authorization: Bearer YOUR_API_KEY
```

送出任務時，還需設定以下請求標頭：

```http theme={null}
Content-Type: application/json
```

## 非同步請求範例

此最小請求提交克隆任務並傳回 `taskId`。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/cosyvoice-3-5-flash" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "clone",
      "prefix": "clip01",
      "audio_urls": [
        "https://example.com/reference.wav"
      ]
    }
  }'
```

成功回應：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678"
  }
}
```

請保留 `taskId`，後續輪詢結果時會用到。

## 輪詢結果

```bash theme={null}
curl -X GET "https://api.apixo.ai/api/v1/statusTask/cosyvoice-3-5-flash?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

任務處理中的回應範例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "processing",
    "voice_id": "cosyvoice-v3.5-flash-xxxx",
    "voice_status": "DEPLOYING",
    "createTime": 1767965610929
  }
}
```

成功回應：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "voice_id": "cosyvoice-v3.5-flash-xxxx",
    "voice_status": "OK",
    "resultJson": "{\"resultUrls\":[\"https://file.apixo.ai/preview.wav\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965682450,
    "costTime": 71521
  }
}
```

任務失敗時的回應範例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "UNDEPLOYED",
    "failMsg": "Voice review failed. This custom voice is unavailable (UNDEPLOYED).",
    "voice_id": "cosyvoice-v3.5-flash-xxxx",
    "voice_status": "UNDEPLOYED",
    "createTime": 1767965610929,
    "completeTime": 1767965682450
  }
}
```

等 `state` 變為 `success` 後，再解析 `resultJson`：

```javascript theme={null}
const payload = JSON.parse(data.resultJson);
const audioUrls = payload.resultUrls;
```

## 請求體

### 演講

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "speech",
    "voice": "cosyvoice-v3.5-flash-xxxx",
    "prompt": "Welcome to APIXO.",
    "format": "mp3"
  }
}
```

### 複製

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "clone",
    "prefix": "clip01",
    "audio_urls": [
      "https://example.com/reference.wav"
    ]
  }
}
```

### 設計

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "design",
    "prefix": "warm01",
    "prompt": "A bright and natural female explainer voice.",
    "preview_text": "Hello, this is the preview sample."
  }
}
```

## 參數

**request\_type** `string` *required* (default: async)

取得結果的方式。選擇 `async` 時，透過 `statusTask` 輪詢結果；選擇 `callback` 時，透過 Webhook 接收結果。

**callback\_url** `string`

當 `request_type` 為 `callback` 時必填。請提供可從網際網路存取的 HTTPS 網址，以接收任務的最終結果。詳見 [Webhook](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)。

**input** `object` *required*

CosyVoice 3.5 Flash 的輸入參數。

**屬性**

**mode** `string` *required*

工作流程類型。支援的值：`speech`、`clone`、`design`。

**voice** `string`

`speech` 所需。必須是先前創建的 `voice_id`。

**prompt** `string`

對於 `speech` 和 `design` 是必需的。在`speech`中，這是合成文字並支援1-20000字元。在`design`中，這是語音描述，支援1-500字元。

**audio\_urls** `string[]`

`clone` 所需。必須恰好包含 1 非空音訊 URL。

**preview\_text** `string`

`design` 所需。預覽產生的自訂語音的文字。支援 1-200 個字元。

**prefix** `string`

對於 `clone` 和 `design` 是必需的。必須匹配 `^[A-Za-z0-9]{1,10}$`。

**format** `string`

選填的輸出格式。已透過 `speech`。對於 `design`，APIXO 也將其用作預覽 `response_format`。如果 `design` 中省略，則預覽預設為 `wav`。

**sample\_rate** `integer`

可選取樣率。透過 `speech`，也支援克隆或設計預覽輸出。

**rate** `number`

`speech` 的可選語速控制。

**pitch** `number`

`speech` 選填的俯仰控制。

**volume** `number`

`speech` 可選音量控制。

**instruction** `string`

`speech` 的可選指令文字。不得超過 100 個字元。

**language\_hints** `string[]`

選填的語言提示。APIXO 接受字串或字串陣列，並且僅使用第一個非空項。

**enable\_ssml** `boolean`

選填，控制 `speech` 是否啟用 SSML。

**word\_timestamp\_enabled** `boolean`

支援 `speech` 的可選字時間戳切換。

**enable\_aigc\_tag** `boolean`

選填，控制 `speech` 是否加入 AIGC 標籤。

**aigc\_propagator** `string`

選填，供 `speech` 使用的 AIGC 傳播中繼資料。

**aigc\_propagate\_id** `string`

選填，供 `speech` 使用的 AIGC 傳播 ID。

**hot\_fix** `boolean`

可選的語音相容性選項。可用性可能因情境而異。

**enable\_markdown\_filter** `boolean`

選填，控制 `speech` 是否過濾 Markdown 標記。

**nsfw\_checker** `boolean` (default: false)

設為 `true` 可在支援的生成路由上啟用上游內容審核。API 預設值為 `false`。

## 回應格式

### 送出任務時的回應

任務受理後，`POST /generateTask/cosyvoice-3-5-flash` 會傳回任務 ID：

**code** `integer`

API 狀態碼。`200` 表示任務已受理。

**message** `string`

狀態說明。

**data.taskId** `string`

任務的唯一 ID，用於查詢任務狀態。

### 狀態回應欄位

**taskId** `string`

任務的唯一識別碼。

**state** `string`

目前的任務狀態，可能的值為 `pending`、`processing`、`success`、`failed`。

**resultJson** `string`

內含音訊結果 URL 的 JSON 字串。有音訊輸出時傳回。

**voice\_id** `string`

複製或設計工作流程傳回的自訂語音 ID。

**voice\_status** `string`

自訂語音狀態，例如`DEPLOYING`、`OK`或`UNDEPLOYED`。

**failCode** `string`

供程式判讀的錯誤碼，僅在 `state` 為 `failed` 時傳回。

**failMsg** `string`

失敗原因說明，僅在 `state` 為 `failed` 時傳回。

**createTime** `integer`

任務建立時的 Unix 時間戳記，單位為毫秒。

**completeTime** `integer`

任務完成時的 Unix 時間戳記，單位為毫秒。任務完成後才會傳回。

**costTime** `integer`

處理時間，以毫秒為單位。任務成功後傳回。

## Webhook 回呼模式

若希望後端自動收到最終結果，可使用回呼模式，無須輪詢。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/cosyvoice-3-5-flash" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "callback",
    "callback_url": "https://your-server.com/webhooks/apixo",
    "input": {
      "mode": "design",
      "prefix": "warm01",
      "prompt": "A calm and clear male tutorial voice.",
      "preview_text": "This is a voice preview sample."
    }
  }'
```

Webhook 的接收條件與重試規則請見 [Webhook 文件](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)。

## 計費

新提交的非 LLM 請求按 **1 點 = `$0.001`** 計費。先依用量和加購項目計算總額，再套用帳戶折扣，最後將請求總額無條件進位至整數點數。若已約定固定單價，則保留該單價的精度，不再使用標準價或另行打折；最終點數仍須進位。詳見[積分換算與進位](https://apixo.ai/docs/zh-hant/pricing.md#credit-conversion-and-rounding)。

CosyVoice 3.5 Flash 依工作流程使用不同的計費單位。

| 工作流程 | APIXO 價格 |
| - | - |
| `speech` | `$0.12 / 10K characters` |
| `clone` | `$0.002 / request` |
| `design` | `$0.03 / request` |

最新的美元費率請見 [API 價目表](https://apixo.ai/pricing/api)。

## 耗時與輪詢

實際延遲可能會因文字長度、語音路由、佇列負載以及您是否建立自訂語音而異。

| 工作流程 | 一般生成時間 | 建議首次查詢時間 | 輪詢間隔 |
| - | - | - | - |
| `speech` | 5s-30s | 任務建立 5 秒後 | 3s-5s |
| `clone` | 30s-180s | 任務建立 20 秒後 | 5s-10s |
| `design` | 30s-180s | 任務建立 20 秒後 | 5s-10s |

> [!TIP]
>
> 在生產語音建立工作流程中使用回呼模式，以避免後端在較長的 `DEPLOYING` 期間需進行輪詢。

該模型不透過APIXO公開內建系統語音。請使用透過複製或設計建立的自訂 `voice_id`。

自訂 `voice_id` 若連續 7 天未使用就會被清除。若要保留這個音色，請確保每 7 天至少用該 `voice_id` 呼叫一次 `speech`。

## 錯誤與排查

### HTTP 錯誤

| 代碼 | 含義 | 處理方式 |
| - | - | - |
| `400` | 請求主體或參數結構有誤 | 修正請求後再試 |
| `401` | 缺少 API 金鑰，或金鑰無效 | 檢查 `Authorization` 請求標頭 |
| `402` | 餘額或配額不足 | 充值或更換帳號或金鑰 |
| `403` | 金鑰或路由無權訪問該模型 | 檢查權限和路由策略 |
| `429` | 已達到速率或並行限制 | 以指數退避方式重試 |
| `500` | 伺服器錯誤 | 逐步拉長間隔後重試 |
| `502` | 服務錯誤 | 逐步拉長間隔後重試 |
| `504` | 服務超時 | 重試或使用回呼模式 |

### 任務失敗案例

| 錯誤碼 | 含義 | 處理方式 |
| - | - | - |
| `UNDEPLOYED` | 語音審核失敗，自訂語音不可用 | 使用更好的輸入音訊或不同的設計提示來建立新的語音 |
| `TASK_TIMEOUT` | 自訂語音部署在 `DEPLOYING` 中停留的時間太長 | 稍後重試 |
| `VALIDATION_ERROR` | 輸入未通過 APIXO 驗證，或 `voice_id` 對於目前使用者、活動語音服務或目標模型無效 | 重試前修復輸入 |
| `UpstreamError` | 任務因不明原因失敗 | 逐步拉長間隔後重試 |

常見的驗證規則：

* `voice` 需要用於 `speech`。APIXO 也接受遺產 `voice_id` 在請求中並將其標準化為 `voice`。
* `cosyvoice-3-5-flash` 無法使用內建系統語音。
* 自訂 `voice_id` 值必須屬於目前用戶，與活動語音服務和目標模型相容。
* 自訂 `voice_id` 若連續 7 天未使用就會被刪除。
* `audio_urls` 必須是一個只有一個非空 URL 的陣列。
* `prefix` 必須是 1-10 個字母或數字。
* `instruction` 最多只能是 100 個字元。

## MCP 整合

[完整模型 Schema](https://apixo.ai/docs/models/schemas/audio/cosyvoice-3-5-flash.json) 中的 `mcp.result` 指定結果的解析方式，`mcp.attachments` 列出可繫結檔案的欄位。這些中繼資料供用戶端整合使用，無須當作生成參數提交。附件欄位為 `audio_urls`。請保留使用者指定的檔案順序。模型參數由 API 驗證。輪詢時請帶入傳回的 `media_type`：語音合成使用 `speech`，聲音複製或設計使用 `voice`。任務成功且聲音就緒後，才能重複使用該聲音。

## 相關連結

* [生成 API 總覽](https://apixo.ai/docs/zh-hant/models.md)
* [音訊模型](https://apixo.ai/docs/zh-hant/models/audio)
* [送出生成任務](https://apixo.ai/docs/zh-hant/api-reference/generate-task.md)
* [查詢任務狀態](https://apixo.ai/docs/zh-hant/api-reference/status-task.md)
* [Webhook](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)
* [錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)
* [API定價](https://apixo.ai/pricing/api)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.