> ## 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.

# 翻訳を作成

> 音声を英語テキストに翻訳します

## 概要

サポートされている任意の言語の音声を英語テキストに翻訳します。文字起こしとは異なり、この endpoint は入力言語に関係なく常に英語テキストを出力します。

## リクエストボディ

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

<ParamField body="file" type="file" required>
  翻訳する音声ファイル。サポートされている形式: `flac`, `mp3`, `mp4`, `mpeg`, `mpga`, `m4a`, `ogg`, `wav`, `webm`。最大ファイルサイズは 25 MB です。
</ParamField>

<ParamField body="model" type="string" default="whisper-1">
  使用する model。現在は `whisper-1` のみサポートされています。
</ParamField>

<ParamField body="prompt" type="string">
  model のスタイルを誘導したり、前のセグメントの続きを生成したりするための任意のテキストです。英語である必要があります。
</ParamField>

<ParamField body="response_format" type="string" default="json">
  出力の形式。オプション: `json`, `text`, `srt`, `verbose_json`, `vtt`。
</ParamField>

<ParamField body="temperature" type="number">
  0 から 1 の間の sampling temperature。0.8 のような高い値ではよりランダムな出力が生成され、0.2 のような低い値ではより集中的で決定論的な出力になります。
</ParamField>

## レスポンス

<ResponseField name="text" type="string">
  英語に翻訳されたテキスト。
</ResponseField>

`verbose_json` 形式では、レスポンスには以下も含まれます:

<ResponseField name="language" type="string">
  入力音声の検出された言語。
</ResponseField>

<ResponseField name="duration" type="number">
  入力音声の長さ（秒）。
</ResponseField>

<ResponseField name="segments" type="array">
  タイムスタンプ付きの翻訳済みテキストのセグメント。
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.tokenlab.sh/v1/audio/translations" \
    -H "Authorization: Bearer sk-your-api-key" \
    -F "file=@german_audio.mp3" \
    -F "model=whisper-1"
  ```

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

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

  with open("german_audio.mp3", "rb") as audio_file:
      response = client.audio.translations.create(
          model="whisper-1",
          file=audio_file
      )

  print(response.text)
  ```

  ```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.translations.create({
    model: 'whisper-1',
    file: fs.createReadStream('german_audio.mp3')
  });

  console.log(response.text);
  ```

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

  $file = new CURLFile('german_audio.mp3', 'audio/mpeg', 'german_audio.mp3');

  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POST => true,
      CURLOPT_HTTPHEADER => [
          'Authorization: Bearer sk-your-api-key'
      ],
      CURLOPT_POSTFIELDS => [
          'file' => $file,
          'model' => 'whisper-1'
      ]
  ]);

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

  $data = json_decode($response, true);
  echo $data['text'];
  ```
</RequestExample>

<ResponseExample>
  ```json json theme={null}
  {
    "text": "Hello, my name is Wolfgang and I come from Germany. Where are you from?"
  }
  ```

  ```json verbose_json theme={null}
  {
    "task": "translate",
    "language": "german",
    "duration": 8.470000267028809,
    "text": "Hello, my name is Wolfgang and I come from Germany. Where are you from?",
    "segments": [
      {
        "id": 0,
        "seek": 0,
        "start": 0.0,
        "end": 4.0,
        "text": " Hello, my name is Wolfgang and I come from Germany.",
        "tokens": [50364, 2425, 11, 452, 1315, 307, 25329, 293, 286, 808, 490, 5765, 13, 50564],
        "temperature": 0.0,
        "avg_logprob": -0.45,
        "compression_ratio": 1.0,
        "no_speech_prob": 0.0
      }
    ]
  }
  ```
</ResponseExample>

## 翻訳と文字起こしの違い

| 機能                 | 翻訳           | 文字起こし   |
| ------------------ | ------------ | ------- |
| 出力言語               | 常に英語         | 入力と同じ   |
| ユースケース             | 外国語の音声を英語に変換 | 元の言語を保持 |
| language parameter | 該当なし         | 任意のヒント  |

<Note>
  翻訳 endpoint はソース言語を自動的に検出し、英語に翻訳します。文字起こしの `language` parameter は無視されます。
</Note>
