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

Chat Completions での音声入出力

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

Chat Completions エンドポイントを使った既存のテキストベースの LLM アプリケーションには、音声機能を追加できます。たとえば、テキスト入力に対応したチャットアプリケーションに音声入出力を追加するには、audio を modalities 配列に含め、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" }
);