---
title: Fish Audio 文字轉語音 | RunAPI
description: 使用文字轉語音端點，以在同一回應中接收結果。
url: https://runapi.ai/zh-TW/docs/api/fish-audio/text-to-speech.md
canonical: https://runapi.ai/zh-TW/docs/api/fish-audio/text-to-speech
locale: zh-TW
---

> HTML 版本: https://runapi.ai/zh-TW/docs/api/fish-audio/text-to-speech
> 代理程式網站索引: https://runapi.ai/llms.txt

# Fish Audio 文字轉語音

## 概覽

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

### 快速入門

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

## 端點

POST /api/v1/fish_audio/text_to_speech

基礎 URL: https://runapi.ai

API 版本: v1

身分驗證: Authorization: Bearer YOUR_API_TOKEN

## 支援的模型

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

- [s1](https://runapi.ai/zh-TW/models/fish-audio/s1)
- [s2-pro](https://runapi.ai/zh-TW/models/fish-audio/s2-pro)
- [s2.1-pro](https://runapi.ai/zh-TW/models/fish-audio/s2.1-pro)

## 請求綱要

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

### s1

```json
{
  "bitrate_kbps": {
    "default": 128,
    "description": "MP3 位元率。WAV 輸出不接受此參數。",
    "enum": [
      64,
      128,
      192
    ],
    "type": "integer"
  },
  "model": {
    "description": "模型 slug。",
    "required": true,
    "type": "string"
  },
  "output_format": {
    "default": "mp3",
    "description": "輸出音訊格式。",
    "enum": [
      "mp3",
      "wav"
    ],
    "type": "string"
  },
  "references": {
    "description": "此請求的行內參考音訊樣本。",
    "items": {
      "properties": {
        "audio": {
          "description": "Base64 編碼的原始音訊位元組。",
          "required": true,
          "type": "string"
        },
        "text": {
          "description": "參考音訊的確切逐字稿。",
          "required": true,
          "type": "string"
        }
      },
      "type": "object"
    },
    "type": "array"
  },
  "sample_rate_hz": {
    "default": 44100,
    "description": "輸出取樣率。MP3 支援 32000 與 44100 Hz；WAV 支援所有列出的值。",
    "enum": [
      8000,
      16000,
      24000,
      32000,
      44100
    ],
    "type": "integer"
  },
  "text": {
    "required": true,
    "type": "string"
  },
  "voice_id": {
    "type": "string"
  }
}
```

### s2-pro

```json
{
  "bitrate_kbps": {
    "default": 128,
    "description": "MP3 位元率。WAV 輸出不接受此參數。",
    "enum": [
      64,
      128,
      192
    ],
    "type": "integer"
  },
  "model": {
    "description": "模型 slug。",
    "required": true,
    "type": "string"
  },
  "output_format": {
    "default": "mp3",
    "description": "輸出音訊格式。",
    "enum": [
      "mp3",
      "wav"
    ],
    "type": "string"
  },
  "references": {
    "description": "此請求的行內參考音訊樣本。",
    "items": {
      "properties": {
        "audio": {
          "description": "Base64 編碼的原始音訊位元組。",
          "required": true,
          "type": "string"
        },
        "text": {
          "description": "參考音訊的確切逐字稿。",
          "required": true,
          "type": "string"
        }
      },
      "type": "object"
    },
    "type": "array"
  },
  "sample_rate_hz": {
    "default": 44100,
    "description": "輸出取樣率。MP3 支援 32000 與 44100 Hz；WAV 支援所有列出的值。",
    "enum": [
      8000,
      16000,
      24000,
      32000,
      44100
    ],
    "type": "integer"
  },
  "text": {
    "required": true,
    "type": "string"
  },
  "voice_id": {
    "type": "string"
  }
}
```

### s2.1-pro

```json
{
  "bitrate_kbps": {
    "default": 128,
    "description": "MP3 位元率。WAV 輸出不接受此參數。",
    "enum": [
      64,
      128,
      192
    ],
    "type": "integer"
  },
  "model": {
    "description": "模型 slug。",
    "required": true,
    "type": "string"
  },
  "output_format": {
    "default": "mp3",
    "description": "輸出音訊格式。",
    "enum": [
      "mp3",
      "wav"
    ],
    "type": "string"
  },
  "references": {
    "description": "此請求的行內參考音訊樣本。",
    "items": {
      "properties": {
        "audio": {
          "description": "Base64 編碼的原始音訊位元組。",
          "required": true,
          "type": "string"
        },
        "text": {
          "description": "參考音訊的確切逐字稿。",
          "required": true,
          "type": "string"
        }
      },
      "type": "object"
    },
    "type": "array"
  },
  "sample_rate_hz": {
    "default": 44100,
    "description": "輸出取樣率。MP3 支援 32000 與 44100 Hz；WAV 支援所有列出的值。",
    "enum": [
      8000,
      16000,
      24000,
      32000,
      44100
    ],
    "type": "integer"
  },
  "text": {
    "required": true,
    "type": "string"
  },
  "voice_id": {
    "type": "string"
  }
}
```

#### 條件規則

當所有列出的條件均符合時，這些需求即適用。

- **當**: `output_format` = `wav`; **不接受**: `bitrate_kbps`
- **當**: `output_format` = `mp3`
- **當**: `output_format` = `{"present" => false}`

## 成功回應

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"
    },
    "billing": {
      "properties": {
        "refund": {
          "oneOf": [
            {
              "properties": {
                "refunded_at": {
                  "type": "string"
                }
              },
              "required": [
                "refunded_at"
              ],
              "type": "object",
              "unevaluatedProperties": false
            },
            {
              "enum": [
                null
              ]
            }
          ]
        },
        "reservation": {
          "oneOf": [
            {
              "properties": {
                "amount_cents": {
                  "type": "integer"
                }
              },
              "required": [
                "amount_cents"
              ],
              "type": "object",
              "unevaluatedProperties": false
            },
            {
              "enum": [
                null
              ]
            }
          ]
        },
        "settlement": {
          "oneOf": [
            {
              "properties": {
                "amount_micro_cents": {
                  "type": "integer"
                },
                "charged_amount_cents": {
                  "type": "integer"
                }
              },
              "required": [
                "charged_amount_cents",
                "amount_micro_cents"
              ],
              "type": "object",
              "unevaluatedProperties": false
            },
            {
              "enum": [
                null
              ]
            }
          ]
        }
      },
      "required": [
        "reservation",
        "settlement",
        "refund"
      ],
      "type": "object",
      "unevaluatedProperties": false
    },
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "completed"
      ],
      "type": "string"
    }
  },
  "required": [
    "id",
    "status",
    "audios",
    "billing"
  ],
  "type": "object",
  "unevaluatedProperties": false
}
```

### 回應範例

```json
{
  "audios": [
    {
      "format": "mp3",
      "mime_type": "audio/mpeg",
      "size_bytes": 128,
      "url": "https://file.runapi.ai/reference-audio.mp3"
    }
  ],
  "billing": {
    "refund": null,
    "reservation": null,
    "settlement": null
  },
  "id": "tsk_reference_demo",
  "status": "completed"
}
```

## 錯誤

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"
}
```

## 錯誤

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"
}
```

## 錯誤

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"
}
```

## 錯誤

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"
}
```

## 錯誤

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"
}
```

## 錯誤

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."
}
```

## 錯誤

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"
}
```

## 錯誤

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"
}
```

## 產生的程式碼範例

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

### curl

```curl
curl -X POST https://runapi.ai/api/v1/fish_audio/text_to_speech \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{"model":"s1","text":"Welcome to RunAPI."}'
```

### javascript

#### 安裝

```bash
npm install @runapi.ai/fish-audio
```

```javascript
import { FishAudioClient } from "@runapi.ai/fish-audio";

const client = new FishAudioClient({ apiKey: process.env.RUNAPI_API_KEY });
const result = await client.textToSpeech.run({
  "model": "s1",
  "text": "Welcome to RunAPI."
});
```

### python

#### 安裝

```bash
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."
)
```

### go

#### 安裝

```bash
go get github.com/runapi-ai/fish-audio-sdk/go@latest
```

```go
package main

import (
  "context"
  "log"
  "os"

  "github.com/runapi-ai/core-sdk/go/option"
  fishaudio "github.com/runapi-ai/fish-audio-sdk/go/fishaudio"
)

func main() {
  client, err := fishaudio.NewClient(option.WithAPIKey(os.Getenv("RUNAPI_API_KEY")))
  if err != nil {
    log.Fatal(err)
  }

  result, err := client.TextToSpeech.Run(context.Background(), fishaudio.TextToSpeechParams{
    Model: "s1",
    Text: "Welcome to RunAPI.",
  })
  if err != nil {
    log.Fatal(err)
  }
  _ = result
}
```

### ruby

#### 安裝

```bash
gem install runapi-fish-audio
```

```ruby
require "runapi/fish_audio"

client = RunApi::FishAudio::Client.new(api_key: ENV.fetch("RUNAPI_API_KEY"))
result = client.text_to_speech.run(
  model: "s1",
  text: "Welcome to RunAPI."
)
```

### java

#### 安裝

```kotlin
implementation("ai.runapi:runapi-fish-audio")
```

```java
import ai.runapi.fishaudio.FishAudioClient;
import ai.runapi.fishaudio.types.TextToSpeechParams;
import ai.runapi.fishaudio.types.TextToSpeechResponse;

public final class Example {
  public static void main(String[] args) {
    FishAudioClient client = FishAudioClient.builder()
        .apiKey(System.getenv("RUNAPI_API_KEY"))
        .build();
    TextToSpeechResponse result = client.textToSpeech().run(
        TextToSpeechParams.builder()
        .model("s1")
        .text("Welcome to RunAPI.")
            .build()
    );
  }
}
```

### php

#### 安裝

```bash
composer require runapi-ai/fish-audio
```

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use RunApi\Core\ClientOptions;
use RunApi\FishAudio\FishAudioClient;

$client = new FishAudioClient(new ClientOptions(apiKey: getenv('RUNAPI_API_KEY')));
$result = $client->textToSpeech->run([
  "model" => "s1",
  "text" => "Welcome to RunAPI."
]);
```

## 相關指南

- [身分驗證](https://runapi.ai/zh-TW/docs/guides/authentication.md)
- [快速入門](https://runapi.ai/zh-TW/docs/guides/task-api/quickstart.md)

---

## RunAPI 的更多內容

- [首頁](https://runapi.ai/zh-TW/.md)
- [模型目錄](https://runapi.ai/zh-TW/models.md)
- [價格](https://runapi.ai/zh-TW/pricing.md)
- [提供商](https://runapi.ai/zh-TW/models)
- [文件](https://runapi.ai/zh-TW/docs/guides)
- [SDK](https://runapi.ai/zh-TW/sdk.md)
- [CLI](https://runapi.ai/zh-TW/cli.md)
- [MCP Server](https://runapi.ai/zh-TW/mcp.md)
- [Claude Code 與 Cursor](https://runapi.ai/zh-TW/claude-code-vs-cursor.md)
- [Cursor API 設定](https://runapi.ai/zh-TW/cursor-api-setup.md)
- [RunAPI 與 OpenRouter](https://runapi.ai/zh-TW/openrouter-alternative.md)
- [企業版](https://runapi.ai/zh-TW/contact.md)
- [聯絡我們](https://runapi.ai/zh-TW/contact.md)
- [服務條款](https://runapi.ai/zh-TW/terms.md)
- [隱私權](https://runapi.ai/zh-TW/privacy.md)
- [代理程式網站索引](https://runapi.ai/llms.txt)

聯絡我們: contact@runapi.ai

## 結構化資料

```json
[
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-TW",
    "@type": "WebSite",
    "name": "RunAPI",
    "url": "https://runapi.ai/zh-TW",
    "potentialAction": {
      "@type": "SearchAction",
      "target": {
        "@type": "EntryPoint",
        "urlTemplate": "https://runapi.ai/zh-TW/models?q={search_term_string}"
      },
      "query-input": "required name=search_term_string"
    }
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-TW",
    "@type": "Organization",
    "name": "RunAPI",
    "url": "https://runapi.ai/zh-TW",
    "logo": {
      "@type": "ImageObject",
      "url": "https://runapi.ai/zh-TWicon.svg"
    },
    "sameAs": [
      "https://github.com/runapi-ai"
    ]
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "zh-TW",
    "@type": "TechArticle",
    "headline": "Fish Audio 文字轉語音",
    "description": "使用文字轉語音端點，以在同一回應中接收結果。",
    "url": "https://runapi.ai/zh-TW/docs/api/fish-audio/text-to-speech",
    "mainEntityOfPage": "https://runapi.ai/zh-TW/docs/api/fish-audio/text-to-speech"
  }
]
```
