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
