Create speech
client.Audio.Speech.New(ctx, body) (*Response, error)
POST
/audio/speechGenerates audio from the input text.
Returns the audio file content, or a stream of audio events.
The tts-1, tts-1-hd, gpt-4o-mini-tts, gpt-4o-mini-tts-2025-03-20, and
gpt-4o-mini-tts-2025-12-15 models are deprecated and scheduled to shut down
on January 6, 2027. These examples use the existing Speech API; for new
integrations, migrate to gpt-realtime-2.1-mini through the
Realtime API. See the
deprecation schedule for migration details.
Create speech
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.SpeechModel("tts-1"),
Voice: openai.AudioSpeechNewParamsVoiceUnion{
OfAudioSpeechNewsVoiceString2: openai.String("ash"),
},
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", speech)
}