Spring / Spring AI interview questions
What is the Spring AI AudioModel and how does it support speech synthesis?
Spring AI includes an AudioModel (specifically SpeechModel) abstraction for text-to-speech (TTS) generation. This covers converting text responses to spoken audio — useful for voice assistants, accessibility features, and audio content pipelines. Currently, the primary provider with TTS support in Spring AI is OpenAI, which offers the tts-1 and tts-1-hd models with multiple voices (alloy, echo, fable, onyx, nova, shimmer).
@Service
public class SpeechService {
private final SpeechModel speechModel;
public SpeechService(SpeechModel speechModel) {
this.speechModel = speechModel;
}
public byte[] synthesise(String text) {
SpeechResponse response = speechModel.call(
new SpeechPrompt(text,
OpenAiAudioSpeechOptions.builder()
.withVoice(OpenAiAudioApi.SpeechRequest.Voice.NOVA)
.withResponseFormat(OpenAiAudioApi.SpeechRequest.AudioResponseFormat.MP3)
.withSpeed(1.0f)
.build())
);
return response.getResult().getOutput(); // returns byte[] audio data
}
}The SpeechResponse carries the audio as a byte[] which you can write to a file, stream as an HTTP response, or forward to a message broker. The response format can be MP3, OPUS, AAC, FLAC, or WAV depending on the provider's supported formats.
Speech-to-text (transcription) is a separate capability covered by the AudioTranscriptionModel abstraction, also backed by OpenAI Whisper in Spring AI's current implementation.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
