Ir al contenido principal

Este explorador ya no se admite.

Actualice a Microsoft Edge para aprovechar las características y actualizaciones de seguridad más recientes, y disponer de soporte técnico.

Descargar Microsoft Edge Más información sobre Internet Explorer y 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.

Cuerpo de la solicitud

The request body.

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

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

Cualquiera de las siguientes:
string
enum
tts-1tts-1-hdgpt-4o-mini-ttsgpt-4o-mini-tts-2025-12-15
input string requerido

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 requerido

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.

Cualquiera de las siguientes:
Cualquiera de las siguientes:
string
enum
alloyashballadcoralechosageshimmerversemarincedar
enum
fableonyxnova
id string requerido
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

Respuestas

The request has succeeded.

Encabezados

Transfer-Encoding string

The TransferEncoding header.

Cuerpo

Content-Type: application/octet-stream

Client error

Cuerpo

Content-Type: application/json
error OpenAI.Error requerido
code string | null requerido
message string requerido
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Cualquiera de las siguientes:
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 requerido

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

Cuerpo

Content-Type: application/json
error OpenAI.Error requerido
code string | null requerido
message string requerido
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Cualquiera de las siguientes:
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 requerido

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Solicitar

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)

Solicitar

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)
es-es
Sus opciones de privacidad
  • Declinación de responsabilidades de IA
  • Versiones anteriores
  • Blog
  • Contribuir
  • Privacidad
  • Privacidad de estado del consumidor
  • Términos de uso
  • Marcas comerciales
  • © Microsoft 2026