Package dyntabs.ai

Class SpeakBuilder

java.lang.Object
dyntabs.ai.SpeakBuilder

public class SpeakBuilder extends Object
Turns text into spoken audio — the outbound half of the voice channel.

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 Details

    • withConfig

      public SpeakBuilder withConfig(VoiceConfig config)
      Replace the whole configuration instead of overriding single values.
      Parameters:
      config - fully built voice settings; null restores properties-based defaults
      Returns:
      this builder
    • withModel

      public SpeakBuilder withModel(String modelName)
      Name the synthesis model for this call (default VoiceConfig.DEFAULT_SPEECH_MODEL).
      Parameters:
      modelName - the provider's model id, e.g. "tts-1", "tts-1-hd"
      Returns:
      this builder
    • withVoice

      public SpeakBuilder withVoice(String voice)
      Choose the voice (default VoiceConfig.DEFAULT_VOICE).
      Parameters:
      voice - the provider's voice name, e.g. "alloy", "nova"
      Returns:
      this builder
    • withApiKey

      public SpeakBuilder withApiKey(String apiKey)
      Override the API key for this call (otherwise easyai.tts.api-key, then easyai.api-key).
      Parameters:
      apiKey - the provider API key
      Returns:
      this builder
    • withBaseUrl

      public SpeakBuilder withBaseUrl(String baseUrl)
      Override the base URL for this call (otherwise easyai.tts.base-url, then easyai.base-url).
      Parameters:
      baseUrl - the OpenAI-compatible endpoint to synthesize with
      Returns:
      this builder
    • withEventListener

      public SpeakBuilder withEventListener(EasyAIListener eventListener)
      Register a listener for the live EasyAIEvent stream, so synthesis appears in your activity timeline alongside every other EasyAI operation.

      Emits EasyAIEvent.Phase.STARTED and then EasyAIEvent.Phase.RESULT (or EasyAIEvent.Phase.ERROR) under EasyAIEvent.Source.VOICE.

      Parameters:
      eventListener - the listener (may be null to disable events)
      Returns:
      this builder
    • from

      public Speech from(String text)
      Synthesize speech for the given text.
      Parameters:
      text - the words to speak
      Returns:
      the audio together with its MIME type