Create speech
HttpResponse audio().speech().create(SpeechCreateParamsparams , RequestOptionsrequestOptions = RequestOptions.none() )
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 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.ASH)
.build();
HttpResponse speech = client.audio().speech().create(params);
}
}