Zu Hauptinhalt wechseln

Dieser Browser wird nicht mehr unterstützt.

Führen Sie ein Upgrade auf Microsoft Edge durch, um die neuesten Features, Sicherheitsupdates und den technischen Support zu nutzen.

Microsoft Edge herunterladen Weitere Informationen zu Internet Explorer und 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.

Anforderungstext

The request body.

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

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

Eines der folgenden Elemente:
string
enum
tts-1tts-1-hdgpt-4o-mini-ttsgpt-4o-mini-tts-2025-12-15
input string Erforderlich

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 Erforderlich

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.

Eines der folgenden Elemente:
Eines der folgenden Elemente:
string
enum
alloyashballadcoralechosageshimmerversemarincedar
enum
fableonyxnova
id string Erforderlich
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

Antworten

The request has succeeded.

Header

Transfer-Encoding string

The TransferEncoding header.

Text

Content-Type: application/octet-stream

Client error

Text

Content-Type: application/json
error OpenAI.Error Erforderlich
code string | null Erforderlich
message string Erforderlich
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Eines der folgenden Elemente:
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 Erforderlich

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

Text

Content-Type: application/json
error OpenAI.Error Erforderlich
code string | null Erforderlich
message string Erforderlich
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Eines der folgenden Elemente:
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 Erforderlich

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Anfordern

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)

Anfordern

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)
de-de
Ihre Datenschutzoptionen
  • KI-Haftungsausschluss
  • Frühere Versionen
  • Blog
  • Mitwirken
  • Datenschutz
  • Consumer Health Privacy
  • Nutzungsbedingungen
  • Impressum
  • Marken
  • © Microsoft 2026