語音合成

聲音克隆

對口型視頻

其他

語音合成 (HTTP)

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

語音合成接口

接口地址

POST /api/open/v1/speech/tts

請求頭

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

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

請求參數

{
  "voiceId": string,       // 必填,音色 ID
  "modelId": string,       // 可選,模型版本 ID,如 fishaudio-s21pro-flash
  "text": string,          // 必填,要轉換的文本
  "speed": number,         // 可選,語速,範圍:0.5-2.0,默認:1
  "volume": number,        // 可選,音量,範圍:-20-20,默認:0
  "format": string,        // 可選,音頻格式。可選:"mp3"、"wav"、"pcm",默認:"mp3"
  "emotion": string,       // 可選,模型支持時生效
  "language": string,      // 可選,模型支持時生效
  "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://kittaaudio.com/api/open/v1/speech/tts \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "voiceId": "your_voice_id",
    "modelId": "fishaudio-s21pro-flash",
    "text": "要轉換的文本內容",
    "speed": 1.0,
    "volume": 0,
    "format": "mp3",
    "cache": false
  }' \
  --output output.mp3

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

# MessagePack 格式 (undefined)

在線調試

狀態碼說明

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

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