語音合成

聲音克隆

對口型視頻

其他

語音合成 (HTTP)

使用 HTTP 接口將文本轉換為語音

語音合成接口

接口地址

POST /api/open/tts

請求頭

// JSON 格式
Content-Type: application/json
Authorization: Bearer YOUR_API_TOKEN  // API Key

// MessagePack 格式
Content-Type: application/msgpack
Authorization: Bearer YOUR_API_TOKEN  // API Key

請求參數

{
  "reference_id": string,  // 必填,聲音模型 ID
  "text": string,          // 必填,要轉換的文本
  "speed": number,         // 可選,語速,範圍:0.5-2.0,默認:1
  "volume": number,        // 可選,音量,範圍:-20-20,默認:0
  "version": string,       // 可選,TTS 版本。可選:"v1"、"v2"、"s1"(傳統版本)與 "v3-turbo"、"v3-hd"(V3 版本),默認:"v1"
  "format": string,        // 可選,音頻格式。可選:"mp3"、"wav"、"pcm",默認:"mp3"
  "emotion": string,       // 可選,情緒控制(僅 V3 支持)。可選:"happy"、"sad"、"angry"、"fearful"、"disgusted"、"surprised"、"calm"、"auto",默認:"auto"
  "language": string,      // 可選,語言增強(僅 V3 支持)。可選:"auto"、"zh"、"en",默認:"auto"
  "cache": boolean         // 可選,false 返回音頻流,true 返回音頻 URL,默認:false
}

版本說明:

  • 傳統版本:v1、v2、s1(基礎語音合成功能)
  • V3版本:v3-turbo、v3-hd(支持情緒控制和語言增強等高級功能)
  • 系統會根據模型配置自動選擇對應的版本,無需手動指定

返回數據

// 成功響應 (cache=false) - 200
Content-Type: audio/mpeg
<二進制音頻數據>

// 成功響應 (cache=true) - 200
Content-Type: application/json
{
  "success": boolean,        // 是否成功
  "audio_url": string,       // 音頻文件URL
  "format": string,          // 音頻格式
  "characters_used": number, // 使用的字符數
  "quota_remaining": number  // 剩餘API積分
}

// 錯誤響應
{
  "error": string     // 錯誤提示信息
}

CURL 示例

# JSON 格式 - 傳統版本(使用 s1 版本,推薦)
curl -X POST https://kittaai.com/api/open/tts \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -d '{
    "reference_id": "your_model_id",
    "text": "要轉換的文本內容",
    "speed": 1.0,
    "volume": 0,
    "version": "s1",
    "format": "mp3",
    "cache": false
  }' \
  --output output.mp3

# JSON 格式 - V3 模型(使用 HD 版本,支持情緒控制和語言增強)
curl -X POST https://kittaai.com/api/open/tts \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -d '{
    "reference_id": "your_model_id",
    "text": "要轉換的文本內容",
    "speed": 1.0,
    "volume": 0,
    "version": "v3-hd",
    "emotion": "calm",
    "language": "zh",
    "format": "mp3",
    "cache": false
  }' \
  --output output.mp3

# MessagePack 格式 (undefined)

在線調試

狀態碼說明

狀態碼說明:
200 OK                  - 請求成功
400 Bad Request         - 請求參數錯誤
401 Unauthorized        - API Token 無效
403 Forbidden          - 禁止訪問
404 Not Found          - 資源不存在
413 Payload Too Large  - 上傳文件過大
429 Too Many Requests  - 請求頻率超限/積分不足
500 Server Error       - 服務器內部錯誤

錯誤響應格式:
{
  "error": string,      // 錯誤信息
  "details": string,    // 詳細錯誤信息(可選)
  "code": string       // 錯誤代碼(可選)
}