Create speech
client.audio.speech.create(SpeechCreateParams { input, model, voice, 4 more } body , RequestOptionsoptions ?): Response
POST
/audio/speechGenerates audio from the input text.
Returns the audio file content, or a stream of audio events.
The tts-1, tts-1-hd, gpt-4o-mini-tts, gpt-4o-mini-tts-2025-03-20, and
gpt-4o-mini-tts-2025-12-15 models are deprecated and scheduled to shut down
on January 6, 2027. These examples use the existing Speech API; for new
integrations, migrate to gpt-realtime-2.1-mini through the
Realtime API. See the
deprecation schedule for migration details.
Create speech
import fs from "fs";
import path from "path";
import OpenAI from "openai";
const openai = new OpenAI();
const speechFile = path.resolve("./speech.mp3");
async function main() {
const mp3 = await openai.audio.speech.create({
model: "gpt-4o-mini-tts",
voice: "alloy",
input: "Today is a wonderful day to build something people love!",
});
console.log(speechFile);
const buffer = Buffer.from(await mp3.arrayBuffer());
await fs.promises.writeFile(speechFile, buffer);
}
main();