liveBook · Manning

SpeechPrompt

As explained in Spring AI in Action

SpeechPrompt is a Spring AI request object containing text to synthesize and optional speech-generation settings.

SpeechPrompt packages text for speech synthesis and can carry optional generation settings. Passing it to SpeechModel.call() returns a SpeechResponse whose output contains the generated audio bytes. section 8.1.2

Use SpeechPrompt when speech generation requires explicit control over:

Basic prompt-based synthesis

Create a SpeechPrompt from the text to speak, call the SpeechModel, extract the response output, and wrap the resulting bytes as a Resource for an HTTP response. section 8.1.2

public Resource textToSpeech(String text) {
  SpeechPrompt speechPrompt = new SpeechPrompt(text);
  SpeechResponse response = speechModel.call(speechPrompt);
  byte[] speechBytes = response.getResult().getOutput();
  return new ByteArrayResource(speechBytes);
}

Shows the complete Java flow from SpeechPrompt construction to audio-byte extraction. section 8.1.2

How Spring AI in Action covers it

How deep it goes
Defines prompt construction, response extraction, and configurable options without descending into audio playback implementation.
Examples
Demonstrates synthesizing an answer into a Resource while selecting Nova, tts-1-hd, and AAC through speech options.
What you can do after
Apply it via SpeechModel to generate configurable audio and expose the resulting bytes from a Spring application.
How it connects
Connects SpeechPrompt with SpeechModel, SpeechResponse, and OpenAiAudioSpeechOptions for Spring AI speech synthesis.

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.