Class SpeakBuilder
The shortest useful form
Speech speech = EasyAI.speak().from("Order ORD-004 has been delivered.");
return Response.ok(speech.bytes()).type(speech.mimeType()).build();
Model, voice, key and base URL come from easyai.properties, defaulting to your chat
settings — so, as with ListenBuilder, the common case needs no new configuration
(see VoiceConfig).
Server-side speech vs. the browser's own
A browser can already speak text for free via the Web Speech API, and for a desktop app that is often the right answer. Synthesizing on the server earns its keep when you need a consistent voice across browsers and devices, a language the client has no voice installed for, or audio you can store, attach and replay — a recorded confirmation, an accessibility narration, an outbound notification. This is the path for those; it returns the bytes and leaves playback entirely up to you.
Overriding per call
Speech speech = EasyAI.speak()
.withModel("tts-1-hd")
.withVoice("nova")
.withEventListener(e -> log.info("{}", e))
.from(answer);
Analogy: a voice-over artist. You hand over the script and get back a recording — the artist neither writes the script nor decides when it is played.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionSynthesize speech for the given text.withApiKey(String apiKey) Override the API key for this call (otherwiseeasyai.tts.api-key, theneasyai.api-key).withBaseUrl(String baseUrl) Override the base URL for this call (otherwiseeasyai.tts.base-url, theneasyai.base-url).withConfig(VoiceConfig config) Replace the whole configuration instead of overriding single values.withEventListener(EasyAIListener eventListener) Register a listener for the liveEasyAIEventstream, so synthesis appears in your activity timeline alongside every other EasyAI operation.Name the synthesis model for this call (defaultVoiceConfig.DEFAULT_SPEECH_MODEL).Choose the voice (defaultVoiceConfig.DEFAULT_VOICE).
-
Method Details
-
withConfig
Replace the whole configuration instead of overriding single values.- Parameters:
config- fully built voice settings;nullrestores properties-based defaults- Returns:
- this builder
-
withModel
Name the synthesis model for this call (defaultVoiceConfig.DEFAULT_SPEECH_MODEL).- Parameters:
modelName- the provider's model id, e.g."tts-1","tts-1-hd"- Returns:
- this builder
-
withVoice
Choose the voice (defaultVoiceConfig.DEFAULT_VOICE).- Parameters:
voice- the provider's voice name, e.g."alloy","nova"- Returns:
- this builder
-
withApiKey
Override the API key for this call (otherwiseeasyai.tts.api-key, theneasyai.api-key).- Parameters:
apiKey- the provider API key- Returns:
- this builder
-
withBaseUrl
Override the base URL for this call (otherwiseeasyai.tts.base-url, theneasyai.base-url).- Parameters:
baseUrl- the OpenAI-compatible endpoint to synthesize with- Returns:
- this builder
-
withEventListener
Register a listener for the liveEasyAIEventstream, so synthesis appears in your activity timeline alongside every other EasyAI operation.Emits
EasyAIEvent.Phase.STARTEDand thenEasyAIEvent.Phase.RESULT(orEasyAIEvent.Phase.ERROR) underEasyAIEvent.Source.VOICE.- Parameters:
eventListener- the listener (may benullto disable events)- Returns:
- this builder
-
from
Synthesize speech for the given text.- Parameters:
text- the words to speak- Returns:
- the audio together with its MIME type
-