跳至主要內容
API 參考
API 參考

Fish Audio 文字轉語音

使用 S2 Pro 模型生成語音,支持即時聲音克隆以及 mp3 或 wav 輸出。

01

概覽

使用文字轉語音端點,並從同一回應中讀取結果。

快速入門

  1. 建立 API 金鑰並將其設定為 RUNAPI_API_KEY。
  2. 傳送主體符合請求 Schema 的 POST 請求。
  3. 從成功的回應主體中讀取結果。

端點

POST /api/v1/fish_audio/text_to_speech
基礎 URL
https://runapi.ai
API 版本
v1
身份驗證
Authorization: Bearer YOUR_API_TOKEN
02

支援的模型

開啟模型頁面以查看當前定價、速率限制及商業用途詳情。

03

請求結構

JSON 內容

僅傳送此端點宣告的欄位。

s19 個欄位
bitrate_kbpsinteger
選填

MP3 位元率。WAV 輸出不接受此參數。

允許值: 64, 128, 192 預設值: 128
modelstring
必填

模型標識符。

output_formatstring
選填

輸出音訊格式。

允許值: mp3, wav 預設值: mp3
referencesarray
選填

一個臨時音色複製樣本。不能與 voice_id 同時使用。沒有樣本時可省略或使用 null、[]。

項目上限: 1
references[].audiostring
必填

可公開存取的 HTTPS 音訊 URL。排隊期間及服務提供者讀取時必須保持有效。

references[].textstring
必填

與參考音訊逐字一致的準確轉錄文字。

sample_rate_hzinteger
選填

輸出採樣率。MP3 支援 32000 及 44100 Hz;WAV 支援所有列出的數值。

允許值: 8000, 16000, 24000, 32000, 44100 預設值: 44100
textstring
必填
voice_idstring
選填
s2-pro9 個欄位
bitrate_kbpsinteger
選填

MP3 位元率。WAV 輸出不接受此參數。

允許值: 64, 128, 192 預設值: 128
modelstring
必填

模型標識符。

output_formatstring
選填

輸出音訊格式。

允許值: mp3, wav 預設值: mp3
referencesarray
選填

一個臨時音色複製樣本。不能與 voice_id 同時使用。沒有樣本時可省略或使用 null、[]。

項目上限: 1
references[].audiostring
必填

可公開存取的 HTTPS 音訊 URL。排隊期間及服務提供者讀取時必須保持有效。

references[].textstring
必填

與參考音訊逐字一致的準確轉錄文字。

sample_rate_hzinteger
選填

輸出採樣率。MP3 支援 32000 及 44100 Hz;WAV 支援所有列出的數值。

允許值: 8000, 16000, 24000, 32000, 44100 預設值: 44100
textstring
必填
voice_idstring
選填
s2.1-pro9 個欄位
bitrate_kbpsinteger
選填

MP3 位元率。WAV 輸出不接受此參數。

允許值: 64, 128, 192 預設值: 128
modelstring
必填

模型標識符。

output_formatstring
選填

輸出音訊格式。

允許值: mp3, wav 預設值: mp3
referencesarray
選填

一個臨時音色複製樣本。不能與 voice_id 同時使用。沒有樣本時可省略或使用 null、[]。

項目上限: 1
references[].audiostring
必填

可公開存取的 HTTPS 音訊 URL。排隊期間及服務提供者讀取時必須保持有效。

references[].textstring
必填

與參考音訊逐字一致的準確轉錄文字。

sample_rate_hzinteger
選填

輸出採樣率。MP3 支援 32000 及 44100 Hz;WAV 支援所有列出的數值。

允許值: 8000, 16000, 24000, 32000, 44100 預設值: 44100
textstring
必填
voice_idstring
選填

條件規則

當所有列出的條件均符合時,這些要求方才適用。

  1. 當 references present
    必填
    不接受
    voice_id
  2. 當 output_format = wav
    必填
    不接受
    bitrate_kbps
  3. 當 output_format = mp3
    必填
    不接受
  4. 當 output_format absent
    必填
    不接受
04

成功回應

HTTP 200

POST /api/v1/fish_audio/text_to_speech

回應結構
JSON
{
  "properties": {
    "audios": {
      "items": {
        "properties": {
          "format": {
            "type": "string"
          },
          "mime_type": {
            "type": "string"
          },
          "size_bytes": {
            "type": "integer"
          },
          "url": {
            "type": "string",
            "x-runapi-generated-media": true
          }
        },
        "required": [
          "url",
          "format",
          "mime_type",
          "size_bytes"
        ],
        "type": "object",
        "unevaluatedProperties": false
      },
      "type": "array"
    },
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "completed"
      ],
      "type": "string"
    }
  },
  "required": [
    "id",
    "status",
    "audios"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "audios": [
    {
      "format": "mp3",
      "mime_type": "audio/mpeg",
      "size_bytes": 128,
      "url": "https://file.runapi.ai/reference-audio.mp3"
    }
  ],
  "id": "tsk_reference_demo",
  "status": "completed"
}
05

錯誤

HTTP 401

POST /api/v1/fish_audio/text_to_speech

回應結構
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "Authentication required"
}
06

錯誤

HTTP 400

POST /api/v1/fish_audio/text_to_speech

回應結構
JSON
{
  "oneOf": [
    {
      "properties": {
        "error": {
          "description": "人類可讀的錯誤訊息。",
          "type": "string"
        }
      },
      "required": [
        "error"
      ],
      "type": "object",
      "unevaluatedProperties": false
    },
    {
      "properties": {
        "error": {
          "description": "人類可讀的驗證摘要。",
          "type": "string"
        },
        "errors": {
          "additionalProperties": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "description": "以公開請求欄位為鍵的驗證訊息,每個欄位對應一組人類可讀的字串陣列。",
          "type": "object"
        }
      },
      "required": [
        "error",
        "errors"
      ],
      "type": "object",
      "unevaluatedProperties": false
    }
  ]
}

回應範例

JSON
{
  "error": "model must be one of: s1, s2-pro, s2.1-pro"
}
07

錯誤

HTTP 402

POST /api/v1/fish_audio/text_to_speech

回應結構
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "Insufficient balance"
}
08

錯誤

HTTP 429

POST /api/v1/fish_audio/text_to_speech

回應結構
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "API key credit limit exceeded"
}
09

錯誤

HTTP 409

POST /api/v1/fish_audio/text_to_speech

回應結構
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "The request uses features that are not supported for the selected model"
}
10

錯誤

HTTP 429

POST /api/v1/fish_audio/text_to_speech

回應結構
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "Rate limit reached. Please retry later."
}
11

錯誤

HTTP 503

POST /api/v1/fish_audio/text_to_speech

回應結構
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "Service under maintenance, please try again later"
}
12

錯誤

HTTP 504

POST /api/v1/fish_audio/text_to_speech

回應結構
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "The request timed out"
}
13

已生成的程式碼範例

直接使用 cURL,或為您的語言安裝 SDK。每個範例均提交本參考中所示的已驗證請求。

安裝

Shell
pip install runapi-fish-audio
PYTHON
import os
from runapi.fish_audio import FishAudioClient

client = FishAudioClient(api_key=os.environ["RUNAPI_API_KEY"])
result = client.text_to_speech.run(
  model="s1",
  text="Welcome to RunAPI."
)