liveBook · Manning

OpenAiAudioSpeechOptions

As explained in Spring AI in Action

OpenAiAudioSpeechOptions is a configuration object for selecting OpenAI text-to-speech voice, model, and audio format.

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

How Spring AI in Action covers it

How deep it goes
Explains builder-based configuration and supported values, but does not detail request internals.
Examples
Demonstrates Nova voice, tts-1-hd, and AAC output through chained builder calls.
What it assumes
Assumes familiarity with SpeechPrompt and speech-model calls while teaching the available speech options from their defaults.
What you can do after
Apply it via Spring AI to customize generated speech rather than relying on Alloy, tts-1, and MP3 defaults.
How it connects
Connects SpeechPrompt and SpeechModel with OpenAI text-to-speech voices, models, and audio response formats.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring AI in Action. The section links point to the parts of the book it draws on.