liveBook · Manning

SpeechModel

As explained in Spring AI in Action

SpeechModel is a Spring AI model interface that converts text into synthesized speech audio.

SpeechModel is Spring AI’s abstraction for converting text into synthesized speech audio. Inject it into a service, pass text to call(), and wrap the returned audio bytes in a Resource. section 8.1.2

A minimal text-to-speech flow:

  • Inject SpeechModel through the service constructor. section 8.1.2
  • Call speechModel.call(text) to obtain audio bytes, then return a ByteArrayResource. section 8.1.2
  • Expose the Resource from a handler producing audio/mpeg so clients receive an audio file. section 8.1.2

Voice-enabled question answering

A controller transcribes an uploaded question, obtains an answer from a board-game service, passes the answer to textToSpeech(), and returns the generated audio. An HTTPie request can save the response as answer.mp3. section 8.1.2

How Spring AI in Action covers it

How deep it goes
Explains constructor injection, call(), byte-to-Resource conversion, response negotiation, and configurable voice, model, and format options.
Examples
Uses a board-game voice service, an audio question endpoint, HTTPie, and an answer.mp3 output file.
What it assumes
Assumes familiarity with Spring services, controllers, Resource, and audio transcription while demonstrating the speech-generation implementation.
What you can do after
Build it from scratch by injecting SpeechModel and returning synthesized audio through a Spring controller.
How it connects
Connects text-to-speech with audio transcription, Spring AI, OpenAI, Resource responses, and HTTP content negotiation.

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.