go/resources/audio/subresources/speech/index.md +0 −152 deleted
File Deleted View Diff
1# Speech
2
3## Create speech
4
5`client.Audio.Speech.New(ctx, body) (*Response, error)`
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- `body AudioSpeechNewParams`
16
17 - `Input param.Field[string]`
18
19 The text to generate audio for. The maximum length is 4096 characters.
20
21 - `Model param.Field[SpeechModel]`
22
23 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`.
24
25 - `string`
26
27 - `type SpeechModel string`
28
29 - `const SpeechModelTTS1 SpeechModel = "tts-1"`
30
31 - `const SpeechModelTTS1HD SpeechModel = "tts-1-hd"`
32
33 - `const SpeechModelGPT4oMiniTTS SpeechModel = "gpt-4o-mini-tts"`
34
35 - `const SpeechModelGPT4oMiniTTS2025_12_15 SpeechModel = "gpt-4o-mini-tts-2025-12-15"`
36
37 - `Voice param.Field[AudioSpeechNewParamsVoiceUnion]`
38
39 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).
40
41 - `string`
42
43 - `type AudioSpeechNewParamsVoiceString string`
44
45 - `const AudioSpeechNewParamsVoiceStringAlloy AudioSpeechNewParamsVoiceString = "alloy"`
46
47 - `const AudioSpeechNewParamsVoiceStringAsh AudioSpeechNewParamsVoiceString = "ash"`
48
49 - `const AudioSpeechNewParamsVoiceStringBallad AudioSpeechNewParamsVoiceString = "ballad"`
50
51 - `const AudioSpeechNewParamsVoiceStringCoral AudioSpeechNewParamsVoiceString = "coral"`
52
53 - `const AudioSpeechNewParamsVoiceStringEcho AudioSpeechNewParamsVoiceString = "echo"`
54
55 - `const AudioSpeechNewParamsVoiceStringSage AudioSpeechNewParamsVoiceString = "sage"`
56
57 - `const AudioSpeechNewParamsVoiceStringShimmer AudioSpeechNewParamsVoiceString = "shimmer"`
58
59 - `const AudioSpeechNewParamsVoiceStringVerse AudioSpeechNewParamsVoiceString = "verse"`
60
61 - `const AudioSpeechNewParamsVoiceStringMarin AudioSpeechNewParamsVoiceString = "marin"`
62
63 - `const AudioSpeechNewParamsVoiceStringCedar AudioSpeechNewParamsVoiceString = "cedar"`
64
65 - `type AudioSpeechNewParamsVoiceID struct{…}`
66
67 Custom voice reference.
68
69 - `ID string`
70
71 The custom voice ID, e.g. `voice_1234`.
72
73 - `Instructions param.Field[string]`
74
75 Control the voice of your generated audio with additional instructions. Does not work with `tts-1` or `tts-1-hd`.
76
77 - `ResponseFormat param.Field[AudioSpeechNewParamsResponseFormat]`
78
79 The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`, `wav`, and `pcm`.
80
81 - `const AudioSpeechNewParamsResponseFormatMP3 AudioSpeechNewParamsResponseFormat = "mp3"`
82
83 - `const AudioSpeechNewParamsResponseFormatOpus AudioSpeechNewParamsResponseFormat = "opus"`
84
85 - `const AudioSpeechNewParamsResponseFormatAAC AudioSpeechNewParamsResponseFormat = "aac"`
86
87 - `const AudioSpeechNewParamsResponseFormatFLAC AudioSpeechNewParamsResponseFormat = "flac"`
88
89 - `const AudioSpeechNewParamsResponseFormatWAV AudioSpeechNewParamsResponseFormat = "wav"`
90
91 - `const AudioSpeechNewParamsResponseFormatPCM AudioSpeechNewParamsResponseFormat = "pcm"`
92
93 - `Speed param.Field[float64]`
94
95 The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the default.
96
97 - `StreamFormat param.Field[AudioSpeechNewParamsStreamFormat]`
98
99 The format to stream the audio in. Supported formats are `sse` and `audio`. `sse` is not supported for `tts-1` or `tts-1-hd`.
100
101 - `const AudioSpeechNewParamsStreamFormatSSE AudioSpeechNewParamsStreamFormat = "sse"`
102
103 - `const AudioSpeechNewParamsStreamFormatAudio AudioSpeechNewParamsStreamFormat = "audio"`
104
105### Returns
106
107- `type AudioSpeechNewResponse interface{…}`
108
109### Example
110
111```go
112package main
113
114import (
115 "context"
116 "fmt"
117
118 "github.com/openai/openai-go"
119 "github.com/openai/openai-go/option"
120)
121
122func main() {
123 client := openai.NewClient(
124 option.WithAPIKey("My API Key"),
125 )
126 speech, err := client.Audio.Speech.New(context.TODO(), openai.AudioSpeechNewParams{
127 Input: "input",
128 Model: openai.SpeechModelTTS1,
129 Voice: openai.AudioSpeechNewParamsVoiceUnion{
130 OfString: openai.String("string"),
131 },
132 })
133 if err != nil {
134 panic(err.Error())
135 }
136 fmt.Printf("%+v\n", speech)
137}
138```
139
140## Domain Types
141
142### Speech Model
143
144- `type SpeechModel string`
145
146 - `const SpeechModelTTS1 SpeechModel = "tts-1"`
147
148 - `const SpeechModelTTS1HD SpeechModel = "tts-1-hd"`
149
150 - `const SpeechModelGPT4oMiniTTS SpeechModel = "gpt-4o-mini-tts"`
151
152 - `const SpeechModelGPT4oMiniTTS2025_12_15 SpeechModel = "gpt-4o-mini-tts-2025-12-15"`