@@ -62,10 +62,11 @@ type AudioSpeechNewParams struct {
6262 Model SpeechModel `json:"model,omitzero" api:"required"`
6363 // The voice to use when generating the audio. Supported built-in voices are
6464 // `alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`, `onyx`, `nova`, `sage`,
65- // `shimmer`, `verse`, `marin`, and `cedar`. Previews of the voices are available
66- // in the
65+ // `shimmer`, `verse`, `marin`, and `cedar`. You may also provide a custom voice
66+ // object with an `id`, for example `{ "id": "voice_1234" }`. Previews of the
67+ // voices are available in the
6768 // [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).
68- Voice AudioSpeechNewParamsVoice `json:"voice,omitzero" api:"required"`
69+ Voice AudioSpeechNewParamsVoiceUnion `json:"voice,omitzero" api:"required"`
6970 // Control the voice of your generated audio with additional instructions. Does not
7071 // work with `tts-1` or `tts-1-hd`.
7172 Instructions param.Opt [string ] `json:"instructions,omitzero"`
@@ -93,26 +94,68 @@ func (r *AudioSpeechNewParams) UnmarshalJSON(data []byte) error {
9394 return apijson .UnmarshalRoot (data , r )
9495}
9596
96- // The voice to use when generating the audio. Supported built-in voices are
97- // `alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`, `onyx`, `nova`, `sage`,
98- // `shimmer`, `verse`, `marin`, and `cedar`. Previews of the voices are available
99- // in the
100- // [Text to speech guide](https://platform.openai.com/docs/guides/text-to-speech#voice-options).
101- type AudioSpeechNewParamsVoice string
97+ // Only one field can be non-zero.
98+ //
99+ // Use [param.IsOmitted] to confirm if a field is set.
100+ type AudioSpeechNewParamsVoiceUnion struct {
101+ OfString param.Opt [string ] `json:",omitzero,inline"`
102+ // Check if union is this variant with
103+ // !param.IsOmitted(union.OfAudioSpeechNewsVoiceString)
104+ OfAudioSpeechNewsVoiceString param.Opt [string ] `json:",omitzero,inline"`
105+ OfAudioSpeechNewsVoiceID * AudioSpeechNewParamsVoiceID `json:",omitzero,inline"`
106+ paramUnion
107+ }
108+
109+ func (u AudioSpeechNewParamsVoiceUnion ) MarshalJSON () ([]byte , error ) {
110+ return param .MarshalUnion (u , u .OfString , u .OfAudioSpeechNewsVoiceString , u .OfAudioSpeechNewsVoiceID )
111+ }
112+ func (u * AudioSpeechNewParamsVoiceUnion ) UnmarshalJSON (data []byte ) error {
113+ return apijson .UnmarshalRoot (data , u )
114+ }
115+
116+ func (u * AudioSpeechNewParamsVoiceUnion ) asAny () any {
117+ if ! param .IsOmitted (u .OfString ) {
118+ return & u .OfString .Value
119+ } else if ! param .IsOmitted (u .OfAudioSpeechNewsVoiceString ) {
120+ return & u .OfAudioSpeechNewsVoiceString
121+ } else if ! param .IsOmitted (u .OfAudioSpeechNewsVoiceID ) {
122+ return u .OfAudioSpeechNewsVoiceID
123+ }
124+ return nil
125+ }
126+
127+ type AudioSpeechNewParamsVoiceString string
102128
103129const (
104- AudioSpeechNewParamsVoiceAlloy AudioSpeechNewParamsVoice = "alloy"
105- AudioSpeechNewParamsVoiceAsh AudioSpeechNewParamsVoice = "ash"
106- AudioSpeechNewParamsVoiceBallad AudioSpeechNewParamsVoice = "ballad"
107- AudioSpeechNewParamsVoiceCoral AudioSpeechNewParamsVoice = "coral"
108- AudioSpeechNewParamsVoiceEcho AudioSpeechNewParamsVoice = "echo"
109- AudioSpeechNewParamsVoiceSage AudioSpeechNewParamsVoice = "sage"
110- AudioSpeechNewParamsVoiceShimmer AudioSpeechNewParamsVoice = "shimmer"
111- AudioSpeechNewParamsVoiceVerse AudioSpeechNewParamsVoice = "verse"
112- AudioSpeechNewParamsVoiceMarin AudioSpeechNewParamsVoice = "marin"
113- AudioSpeechNewParamsVoiceCedar AudioSpeechNewParamsVoice = "cedar"
130+ AudioSpeechNewParamsVoiceStringAlloy AudioSpeechNewParamsVoiceString = "alloy"
131+ AudioSpeechNewParamsVoiceStringAsh AudioSpeechNewParamsVoiceString = "ash"
132+ AudioSpeechNewParamsVoiceStringBallad AudioSpeechNewParamsVoiceString = "ballad"
133+ AudioSpeechNewParamsVoiceStringCoral AudioSpeechNewParamsVoiceString = "coral"
134+ AudioSpeechNewParamsVoiceStringEcho AudioSpeechNewParamsVoiceString = "echo"
135+ AudioSpeechNewParamsVoiceStringSage AudioSpeechNewParamsVoiceString = "sage"
136+ AudioSpeechNewParamsVoiceStringShimmer AudioSpeechNewParamsVoiceString = "shimmer"
137+ AudioSpeechNewParamsVoiceStringVerse AudioSpeechNewParamsVoiceString = "verse"
138+ AudioSpeechNewParamsVoiceStringMarin AudioSpeechNewParamsVoiceString = "marin"
139+ AudioSpeechNewParamsVoiceStringCedar AudioSpeechNewParamsVoiceString = "cedar"
114140)
115141
142+ // Custom voice reference.
143+ //
144+ // The property ID is required.
145+ type AudioSpeechNewParamsVoiceID struct {
146+ // The custom voice ID, e.g. `voice_1234`.
147+ ID string `json:"id" api:"required"`
148+ paramObj
149+ }
150+
151+ func (r AudioSpeechNewParamsVoiceID ) MarshalJSON () (data []byte , err error ) {
152+ type shadow AudioSpeechNewParamsVoiceID
153+ return param .MarshalObject (r , (* shadow )(& r ))
154+ }
155+ func (r * AudioSpeechNewParamsVoiceID ) UnmarshalJSON (data []byte ) error {
156+ return apijson .UnmarshalRoot (data , r )
157+ }
158+
116159// The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`,
117160// `wav`, and `pcm`.
118161type AudioSpeechNewParamsResponseFormat string
0 commit comments