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

# 音声を作成

> 入力テキストから音声を生成します

## リクエストボディ

**同期リクエストのタイムアウト:** この非チャットエンドポイントは、ルーティング先モデルの処理完了を待ちます。大きな入力、長い音声、大きなバッチは一般的な 30s のクライアント既定値を超えることがあるため、HTTP クライアントのタイムアウトは少なくとも `120s` に設定してください。

サポートされる任意フィールドはモデルファミリーによって異なります。TokenLab はルーティング前にこのフィールド行列を検証します。OpenAI TTS は `voice`、`instructions`、`response_format`、`stream_format`、`speed` を受け付けます。MiniMax speech は `voice`、`voice_id`、`response_format`、`stream_format`、`speed` を受け付けます。Gemini TTS は `prompt`、`language_code`、`voice`、`response_format`、`stream_format`、`speed`、`temperature` を受け付けます。より狭い Vidu/Kling 系 TTS ルートでは `input` と `stream_format` のみを受け付ける場合があります。`user` を含む未知のトップレベルフィールドは無視されず、`400 unsupported_parameter` を返します。

<ParamField body="model" type="string" default="tts-1">
  TTS モデル。例: `tts-1`、`gpt-4o-mini-tts`、`speech-02-hd`、`gemini-2.5-flash-tts`。現在の候補は `GET /v1/models?recommended_for=tts` で確認してください。
</ParamField>

<ParamField body="input" type="string" required>
  音声を生成する対象のテキストです。最大 4096 文字。
</ParamField>

<ParamField body="voice" type="string | object">
  音声セレクター。`nova` などの組み込み音声、`Kore` などの Gemini 音声、または互換カスタム音声向けに `{ "id": "voice-id" }` のようなオブジェクトを渡します。
</ParamField>

<ParamField body="voice_id" type="string">
  MiniMax 互換 speech モデル向けのプロバイダー native 音声セレクターです。
</ParamField>

<ParamField body="instructions" type="string">
  対応する OpenAI 互換 TTS モデルで使える、任意のスタイルまたは読み上げ指示です。
</ParamField>

<ParamField body="prompt" type="string">
  Gemini TTS モデル向けの任意の話し方スタイル prompt です。
</ParamField>

<ParamField body="language_code" type="string">
  Gemini、xAI、互換 TTS ルート向けの任意の言語コードです。例: `en-US`。
</ParamField>

<ParamField body="response_format" type="string">
  音声形式。一般的な値は `mp3`、`opus`、`aac`、`flac`、`wav`、`pcm` です。サポート値はモデルファミリーによって異なります。
</ParamField>

<ParamField body="stream_format" type="string" default="audio">
  TokenLab の配信形式: `audio` または `sse`。`tts-1` と `tts-1-hd` は `stream_format=sse` をサポートしません。
</ParamField>

<ParamField body="speed" type="number">
  対応するモデルファミリーで使える読み上げ速度です（0.25 ～ 4.0）。
</ParamField>

<ParamField body="temperature" type="number">
  Gemini 互換 TTS ルートのサンプリング temperature です（0 ～ 2）。
</ParamField>

## レスポンス

要求された形式の音声ファイルを返します。

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.tokenlab.sh/v1/audio/speech" \
    -H "Authorization: Bearer sk-your-api-key" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "tts-1-hd",
      "voice": "nova",
      "input": "Hello, welcome to TokenLab!"
    }' \
    --output speech.mp3
  ```

  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="sk-your-api-key",
      base_url="https://api.tokenlab.sh/v1"
  )

  response = client.audio.speech.create(
      model="tts-1-hd",
      voice="nova",
      input="Hello, welcome to TokenLab!"
  )

  response.stream_to_file("speech.mp3")
  ```

  ```javascript JavaScript theme={null}
  import OpenAI from 'openai';
  import fs from 'fs';

  const client = new OpenAI({
    apiKey: 'sk-your-api-key',
    baseURL: 'https://api.tokenlab.sh/v1'
  });

  const response = await client.audio.speech.create({
    model: 'tts-1-hd',
    voice: 'nova',
    input: 'Hello, welcome to TokenLab!'
  });

  const buffer = Buffer.from(await response.arrayBuffer());
  fs.writeFileSync('speech.mp3', buffer);
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://api.tokenlab.sh/v1/audio/speech');

  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POST => true,
      CURLOPT_HTTPHEADER => [
          'Content-Type: application/json',
          'Authorization: Bearer sk-your-api-key'
      ],
      CURLOPT_POSTFIELDS => json_encode([
          'model' => 'tts-1-hd',
          'voice' => 'nova',
          'input' => 'Hello, welcome to TokenLab!'
      ])
  ]);

  $audio = curl_exec($ch);
  curl_close($ch);

  file_put_contents('speech.mp3', $audio);
  ```
</RequestExample>

## 音声音声サンプル

| Voice     | 説明                |
| --------- | ----------------- |
| `alloy`   | ニュートラルでバランスの取れた音声 |
| `ash`     | 落ち着いた、抑制の効いた音声    |
| `ballad`  | メロディックで表現力豊かな音声   |
| `coral`   | 温かみがあり、親しみやすい音声   |
| `echo`    | 温かみのある、会話的な音声     |
| `fable`   | 表現力があり、物語調の音声     |
| `nova`    | 親しみやすく、明瞭な音声      |
| `onyx`    | 深みがあり、威厳のある音声     |
| `sage`    | 賢明で、思慮深い音声        |
| `shimmer` | 柔らかく、穏やかな音声       |
| `verse`   | ダイナミックで汎用性の高い音声   |

## レスポンス例

<ResponseExample>
  ```binary 200 OK theme={null}
  <binary audio data>
  ```
</ResponseExample>

## 重要フィールド

<ResponseField name="Content-Type" type="string">API が返す event または message type です。</ResponseField>
<ResponseField name="body" type="binary">生のレスポンス body です。JSON として解析せず直接保存してください。</ResponseField>
