OpenAiAudioSpeechOptions configures OpenAI text-to-speech generation through a builder. Attach it to a SpeechPrompt to select the voice, model, and response format instead of accepting defaults. section 8.1.2
Configure these generation choices:
- Choose a voice such as Nova instead of the default Alloy. section 8.1.2
- Choose tts-1 for typical use or tts-1-hd for more varied audio output. section 8.1.2
- Choose AAC, FLAC, MP3, Opus, PCM, or WAV instead of the default MP3 format. section 8.1.2
Configure Nova voice, HD model, and AAC output
Create the options with OpenAiAudioSpeechOptions.builder(), call voice() with NOVA, call model("tts-1-hd"), call responseFormat() with AAC, and build the object for the speech prompt. section 8.1.2
public Resource textToSpeech(String text) {
OpenAiAudioSpeechOptions options = OpenAiAudioSpeechOptions.builder()
.voice(OpenAiAudioApi.SpeechRequest.Voice.NOVA)
.model("tts-1-hd")
.responseFormat(
OpenAiAudioApi.SpeechRequest.AudioResponseFormat.AAC)
.build();
byte[] speechBytes = speechModel.call(text);
return new ByteArrayResource(speechBytes);
}
Use the complete builder listing as a compact reference for combining voice, model, and response-format settings. section 8.1.2
