OpenAI 音声フォーマット
OpenAI 音声フォーマット
Section titled “OpenAI 音声フォーマット”本ページの概要
公式ドキュメント
OpenAI Audio
OpenAI 音声 API は、主に次の 3 つの機能を提供します:
- テキスト読み上げ(TTS)- テキストを自然な音声に変換する
- 音声認識(STT)- 音声を文字起こししてテキストに変換する
- 音声翻訳 - 英語以外の音声を英語のテキストに翻訳する
💡 リクエスト例
Section titled “💡 リクエスト例”テキスト読み上げ ✅
Section titled “テキスト読み上げ ✅”curl https://4All API地址/v1/audio/speech \ -H "Authorization: Bearer $NEWAPI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "tts-1", "input": "你好,世界!", "voice": "alloy" }' \ --output speech.mp3音声認識 ✅
Section titled “音声認識 ✅”curl https://4All API地址/v1/audio/transcriptions \ -H "Authorization: Bearer $NEWAPI_API_KEY" \ -H "Content-Type: multipart/form-data" \ -F file="@/path/to/file/audio.mp3" \ -F model="whisper-1"レスポンス例:
{ "text": "你好,世界!"}音声翻訳 ✅
Section titled “音声翻訳 ✅”curl https://4All API地址/v1/audio/translations \ -H "Authorization: Bearer $NEWAPI_API_KEY" \ -H "Content-Type: multipart/form-data" \ -F file="@/path/to/file/chinese.mp3" \ -F model="whisper-1"レスポンス例:
{ "text": "Hello, world!"}📮 リクエスト
Section titled “📮 リクエスト”エンドポイント
Section titled “エンドポイント”テキスト読み上げ
Section titled “テキスト読み上げ”POST /v1/audio/speechテキストを音声に変換します。
POST /v1/audio/transcriptions音声を入力言語のテキストに文字起こしします。
POST /v1/audio/translations音声を英語のテキストに翻訳します。
API キー認証を行うには、リクエストヘッダーに次の内容を含めてください:
Authorization: Bearer $NEWAPI_API_KEYここで $NEWAPI_API_KEY はあなたの API キーです。
リクエストボディのパラメータ
Section titled “リクエストボディのパラメータ”テキスト読み上げ
Section titled “テキスト読み上げ”- 型: 文字列
- 必須: はい
- 取れる値: tts-1, tts-1-hd
- 説明: 使用する TTS モデル
- 型: 文字列
- 必須: はい
- 最大長: 4096 文字
- 説明: 音声に変換するテキスト
- 型: 文字列
- 必須: はい
- 取れる値: alloy, echo, fable, onyx, nova, shimmer
- 説明: 音声生成時に使用する声
response_format
Section titled “response_format”- 型: 文字列
- 必須: いいえ
- デフォルト値: mp3
- 取れる値: mp3, opus, aac, flac, wav, pcm
- 説明: 音声の出力形式
- 型: 数値
- 必須: いいえ
- デフォルト値: 1.0
- 範囲: 0.25 - 4.0
- 説明: 生成音声の速度
- 型: ファイル
- 必須: はい
- 対応形式: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm
- 説明: 文字起こしする音声ファイル
- 型: 文字列
- 必須: はい
- 現時点で対応: whisper-1
- 説明: 使用するモデル ID
language
Section titled “language”- 型: 文字列
- 必須: いいえ
- 形式: ISO-639-1(例: “en”)
- 説明: 音声の言語。指定すると精度が向上します
prompt
Section titled “prompt”- 型: 文字列
- 必須: いいえ
- 説明: モデルの文体を指示したり、直前の音声の続きとして使うテキスト
response_format
Section titled “response_format”- 型: 文字列
- 必須: いいえ
- デフォルト値: json
- 取れる値: json, text, srt, verbose_json, vtt
- 説明: 出力形式
temperature
Section titled “temperature”- 型: 数値
- 必須: いいえ
- デフォルト値: 0
- 範囲: 0 - 1
- 説明: サンプリング温度。値が高いほど出力はランダムになります
timestamp_granularities
Section titled “timestamp_granularities”- 型: 配列
- 必須: いいえ
- デフォルト値: segment
- 取れる値: word, segment
- 説明: 文字起こしのタイムスタンプ粒度
- 型: ファイル
- 必須: はい
- 対応形式: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, webm
- 説明: 翻訳する音声ファイル
- 型: 文字列
- 必須: はい
- 現時点で対応: whisper-1
- 説明: 使用するモデル ID
prompt
Section titled “prompt”- 型: 文字列
- 必須: いいえ
- 説明: モデルの文体を指示する英語テキスト
response_format
Section titled “response_format”- 型: 文字列
- 必須: いいえ
- デフォルト値: json
- 取れる値: json, text, srt, verbose_json, vtt
- 説明: 出力形式
temperature
Section titled “temperature”- 型: 数値
- 必須: いいえ
- デフォルト値: 0
- 範囲: 0 - 1
- 説明: サンプリング温度。値が高いほど出力はランダムになります
📥 レスポンス
Section titled “📥 レスポンス”成功レスポンス
Section titled “成功レスポンス”テキスト読み上げ
Section titled “テキスト読み上げ”バイナリの音声ファイル内容が返されます。
基本 JSON 形式
Section titled “基本 JSON 形式”{ "text": "文字起こしされたテキスト内容"}詳細 JSON 形式
Section titled “詳細 JSON 形式”{ "task": "transcribe", "language": "english", "duration": 8.47, "text": "完全な文字起こしテキスト", "segments": [ { "id": 0, "seek": 0, "start": 0.0, "end": 3.32, "text": "分割された文字起こしテキスト", "tokens": [50364, 440, 7534], "temperature": 0.0, "avg_logprob": -0.286, "compression_ratio": 1.236, "no_speech_prob": 0.009 } ]}{ "text": "翻訳後の英語テキスト"}エラーレスポンス
Section titled “エラーレスポンス”リクエストに問題がある場合、API はエラー応答オブジェクトを返し、HTTP ステータスコードは 4XX-5XX の範囲になります。
よくあるエラーコード
Section titled “よくあるエラーコード”- 400 Bad Request : リクエストパラメータが無効
- 401 Unauthorized : API キーが無効、または未指定
- 429 Too Many Requests : API 呼び出し制限を超過
- 500 Internal Server Error : サーバー内部エラー
エラーレスポンス例:
{ "error": { "message": "文件格式不支持", "type": "invalid_request_error", "param": "file", "code": "invalid_file_format" }}