python/resources/audio/subresources/speech/index.md +0 −153 deleted
File Deleted View Diff
1# Speech
2
3## Create speech
4
5`audio.speech.create(SpeechCreateParams**kwargs) -> BinaryResponseContent`
6
7**post** `/audio/speech`
8
9Generates audio from the input text.
10
11Returns the audio file content, or a stream of audio events.
12
13### Parameters
14
15- `input: str`
16
17 The text to generate audio for. The maximum length is 4096 characters.
18
19- `model: Union[str, SpeechModel]`
20
21 One of the available [TTS models](https://platform.openai.com/docs/models#tts): `tts-1`, `tts-1-hd`, `gpt-4o-mini-tts`, or `gpt-4o-mini-tts-2025-12-15`.
22
23 - `str`
24
25 - `Literal["tts-1", "tts-1-hd", "gpt-4o-mini-tts", "gpt-4o-mini-tts-2025-12-15"]`
26
27 - `"tts-1"`
28
29 - `"tts-1-hd"`
30
31 - `"gpt-4o-mini-tts"`
32
33 - `"gpt-4o-mini-tts-2025-12-15"`
34
35- `voice: Voice`
36
37 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](https://platform.openai.com/docs/guides/text-to-speech#voice-options).
38
39 - `str`
40
41 - `Literal["alloy", "ash", "ballad", 7 more]`
42
43 - `"alloy"`
44
45 - `"ash"`
46
47 - `"ballad"`
48
49 - `"coral"`
50
51 - `"echo"`
52
53 - `"sage"`
54
55 - `"shimmer"`
56
57 - `"verse"`
58
59 - `"marin"`
60
61 - `"cedar"`
62
63 - `class VoiceID: …`
64
65 Custom voice reference.
66
67 - `id: str`
68
69 The custom voice ID, e.g. `voice_1234`.
70
71- `instructions: Optional[str]`
72
73 Control the voice of your generated audio with additional instructions. Does not work with `tts-1` or `tts-1-hd`.
74
75- `response_format: Optional[Literal["mp3", "opus", "aac", 3 more]]`
76
77 The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`, `wav`, and `pcm`.
78
79 - `"mp3"`
80
81 - `"opus"`
82
83 - `"aac"`
84
85 - `"flac"`
86
87 - `"wav"`
88
89 - `"pcm"`
90
91- `speed: Optional[float]`
92
93 The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the default.
94
95- `stream_format: Optional[Literal["sse", "audio"]]`
96
97 The format to stream the audio in. Supported formats are `sse` and `audio`. `sse` is not supported for `tts-1` or `tts-1-hd`.
98
99 - `"sse"`
100
101 - `"audio"`
102
103### Returns
104
105- `BinaryResponseContent`
106
107### Example
108
109```python
110import os
111from openai import OpenAI
112
113client = OpenAI(
114 api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
115)
116speech = client.audio.speech.create(
117 input="input",
118 model="string",
119 voice="string",
120)
121print(speech)
122content = speech.read()
123print(content)
124```
125
126### Example
127
128```python
129from pathlib import Path
130import openai
131
132speech_file_path = Path(__file__).parent / "speech.mp3"
133with openai.audio.speech.with_streaming_response.create(
134 model="gpt-4o-mini-tts",
135 voice="alloy",
136 input="The quick brown fox jumped over the lazy dog."
137) as response:
138 response.stream_to_file(speech_file_path)
139```
140
141## Domain Types
142
143### Speech Model
144
145- `Literal["tts-1", "tts-1-hd", "gpt-4o-mini-tts", "gpt-4o-mini-tts-2025-12-15"]`
146
147 - `"tts-1"`
148
149 - `"tts-1-hd"`
150
151 - `"gpt-4o-mini-tts"`
152
153 - `"gpt-4o-mini-tts-2025-12-15"`