Passer directement au contenu principal

Ce navigateur n’est plus pris en charge.

Effectuez une mise à niveau vers Microsoft Edge pour tirer parti des dernières fonctionnalités, des mises à jour de sécurité et du support technique.

Télécharger Microsoft Edge Plus d’informations sur Internet Explorer et Microsoft Edge
microsoft-foundry.rest.security.o-auth2-auth

Audio

Create a speech

POST /openai/v1/audio/speech

Creates a speech from the supplied request.

Corps de la demande

The request body.

Content-Type: application/json
model string | enum obligatoire

One of the available TTS models: tts-1, tts-1-hd, gpt-4o-mini-tts, or gpt-4o-mini-tts-2025-12-15.

Un des éléments suivants :
string
enum
tts-1tts-1-hdgpt-4o-mini-ttsgpt-4o-mini-tts-2025-12-15
input string obligatoire

The text to generate audio for. The maximum length is 4096 characters.

instructions string

Control the voice of your generated audio with additional instructions. Does not work with tts-1 or tts-1-hd.

voice OpenAI.VoiceIdsShared | enum | object obligatoire

The voice to use when generating the audio. Supported built-in voices are alloy, ash, ballad, coral, echo, fable, onyx, nova, sage, shimmer, verse, marin, and cedar. You may also provide a custom voice object with an id, for example { "id": "voice_1234" }. Previews of the voices are available in the Text to speech guide. Custom voices must be created from audio samples. Voices created from text prompts are supported only in Live.

Un des éléments suivants :
Un des éléments suivants :
string
enum
alloyashballadcoralechosageshimmerversemarincedar
enum
fableonyxnova
id string obligatoire
response_format enum

The format to audio in. Supported formats are mp3, opus, aac, flac, wav, and pcm.

mp3opusaacflacwavpcm
speed number
stream_format enum

The format to stream the audio in. Supported formats are sse and audio. sse is not supported for tts-1 or tts-1-hd.

sseaudio

Réponses

The request has succeeded.

En-têtes

Transfer-Encoding string

The TransferEncoding header.

Corps

Content-Type: application/octet-stream

Client error

Corps

Content-Type: application/json
error OpenAI.Error obligatoire
code string | null obligatoire
message string obligatoire
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Un des éléments suivants :
string
enum
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string

The public explanation for this block.

steer OpenAI._MisalignmentSteer
message string obligatoire

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

Corps

Content-Type: application/json
error OpenAI.Error obligatoire
code string | null obligatoire
message string obligatoire
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Un des éléments suivants :
string
enum
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string

The public explanation for this block.

steer OpenAI._MisalignmentSteer
message string obligatoire

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Requête

curl https://api.openai.com/v1/audio/speech \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini-tts",
    "input": "The quick brown fox jumped over the lazy dog.",
    "voice": "alloy"
  }' \
  --output speech.mp3
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),  # This is the default and can be omitted
)
speech = client.audio.speech.create(
    input="input",
    model="tts-1",
    voice="alloy",
)
print(speech)
content = speech.read()
print(content)
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();
using System;
using System.IO;

using OpenAI.Audio;

AudioClient client = new(
    model: "gpt-4o-mini-tts",
    apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY")
);

BinaryData speech = client.GenerateSpeech(
    text: "The quick brown fox jumped over the lazy dog.",
    voice: GeneratedSpeechVoice.Alloy
);

using FileStream stream = File.OpenWrite("speech.mp3");
speech.ToStream().CopyTo(stream);
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
});

const speech = await client.audio.speech.create({
  input: 'input',
  model: 'tts-1',
  voice: 'alloy',
});

console.log(speech);

const content = await speech.blob();
console.log(content);
package main

import (
    "context"
    "fmt"

    "github.com/openai/openai-go"
    "github.com/openai/openai-go/option"
)

func main() {
    client := openai.NewClient(
        option.WithAPIKey("My API Key"),
    )
    speech, err := client.Audio.Speech.New(context.TODO(), openai.AudioSpeechNewParams{
        Input: "input",
        Model: openai.SpeechModelTTS1,
        Voice: openai.AudioSpeechNewParamsVoiceUnion{
            OfAudioSpeechNewsVoiceString2: openai.String("alloy"),
        },
    })
    if err != nil {
        panic(err.Error())
    }
    fmt.Printf("%+v
", speech)
}
package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.http.HttpResponse;
import com.openai.models.audio.speech.SpeechCreateParams;
import com.openai.models.audio.speech.SpeechModel;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.fromEnv();

        SpeechCreateParams params = SpeechCreateParams.builder()
            .input("input")
            .model(SpeechModel.TTS_1)
            .voice(SpeechCreateParams.Voice.UnionMember1.ALLOY)
            .build();
        HttpResponse speech = client.audio().speech().create(params);
    }
}
require "openai"

openai = OpenAI::Client.new(api_key: "My API Key")

speech = openai.audio.speech.create(input: "input", model: :"tts-1", voice: :alloy)

puts(speech)

Requête

curl https://api.openai.com/v1/audio/speech \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini-tts",
    "input": "The quick brown fox jumped over the lazy dog.",
    "voice": "alloy",
    "stream_format": "sse"
  }'
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
});

const speech = await client.audio.speech.create({
  input: 'input',
  model: 'tts-1',
  voice: 'alloy',
});

console.log(speech);

const content = await speech.blob();
console.log(content);
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),  # This is the default and can be omitted
)
speech = client.audio.speech.create(
    input="input",
    model="tts-1",
    voice="alloy",
)
print(speech)
content = speech.read()
print(content)
package main

import (
    "context"
    "fmt"

    "github.com/openai/openai-go"
    "github.com/openai/openai-go/option"
)

func main() {
    client := openai.NewClient(
        option.WithAPIKey("My API Key"),
    )
    speech, err := client.Audio.Speech.New(context.TODO(), openai.AudioSpeechNewParams{
        Input: "input",
        Model: openai.SpeechModelTTS1,
        Voice: openai.AudioSpeechNewParamsVoiceUnion{
            OfAudioSpeechNewsVoiceString2: openai.String("alloy"),
        },
    })
    if err != nil {
        panic(err.Error())
    }
    fmt.Printf("%+v
", speech)
}
package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.core.http.HttpResponse;
import com.openai.models.audio.speech.SpeechCreateParams;
import com.openai.models.audio.speech.SpeechModel;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.fromEnv();

        SpeechCreateParams params = SpeechCreateParams.builder()
            .input("input")
            .model(SpeechModel.TTS_1)
            .voice(SpeechCreateParams.Voice.UnionMember1.ALLOY)
            .build();
        HttpResponse speech = client.audio().speech().create(params);
    }
}
require "openai"

openai = OpenAI::Client.new(api_key: "My API Key")

speech = openai.audio.speech.create(input: "input", model: :"tts-1", voice: :alloy)

puts(speech)
fr-fr
Vos choix en matière de confidentialité
  • Clause d’exclusion de responsabilité sur l’IA
  • Versions antérieures
  • Blog
  • Collaboration
  • Confidentialité
  • Confidentialité de la santé des consommateurs
  • Conditions d’utilisation
  • Accessibilité
  • Marques
  • © Microsoft 2026