For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
メインナビゲーション

Chat Completions での音声

既存の Chat Completions アプリケーションに音声入出力を追加します。

Chat Completions エンドポイントを使ったテキストベースの LLM アプリケーションに、音声機能を追加したい場合があります。たとえば、テキスト入力に対応したチャットアプリケーションでは、modalities 配列に audio を含め、gpt-audio-1.5 などの音声モデルを使用することで、音声入出力を追加できます。

Responses API のドキュメントでは現在、 テキストと画像を入力し、テキストを出力する方法を説明しています。 この音声チャットの構成では、音声対応モデルと Chat Completions を使用してください。

プロンプトに対する人間らしい音声応答の生成
import { writeFileSync } from "node:fs";
import OpenAI from "openai";

const openai = new OpenAI();

// Generate an audio response to the given prompt
const response = await openai.chat.completions.create({
  model: "gpt-audio-1.5",
  modalities: ["text", "audio"],
  audio: { voice: "alloy", format: "wav" },
  messages: [
    {
      role: "user",
      content: "Is a golden retriever a good family dog?",
    },
  ],
  store: true,
});

// Inspect returned data
console.log(response.choices[0]);

// Write audio data to a file
writeFileSync(
  "dog.wav",
  Buffer.from(response.choices[0].message.audio.data, "base64"),
  { encoding: "utf-8" }
);