Class GoogleGenAiTextToSpeechModel.Builder

java.lang.Object
dev.langchain4j.model.google.genai.GoogleGenAiTextToSpeechModel.Builder
Enclosing class:
GoogleGenAiTextToSpeechModel

public static class GoogleGenAiTextToSpeechModel.Builder extends Object
Since:
1.23.0
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • client

      public GoogleGenAiTextToSpeechModel.Builder client(com.google.genai.Client client)
      Sets the Google GenAI client to use. When set, the authentication and transport options of this builder are ignored.
      Parameters:
      client - the client
      Returns:
      this
    • apiKey

      Sets the API key of the Gemini Developer API.
      Parameters:
      apiKey - the API key
      Returns:
      this
    • googleCredentials

      public GoogleGenAiTextToSpeechModel.Builder googleCredentials(com.google.auth.oauth2.GoogleCredentials googleCredentials)
      Sets the credentials used to call Vertex AI.
      Parameters:
      googleCredentials - the credentials
      Returns:
      this
    • projectId

      public GoogleGenAiTextToSpeechModel.Builder projectId(String projectId)
      Sets the Google Cloud project used to call Vertex AI.
      Parameters:
      projectId - the project ID
      Returns:
      this
    • location

      public GoogleGenAiTextToSpeechModel.Builder location(String location)
      Sets the Google Cloud location used to call Vertex AI.
      Parameters:
      location - the location, for example global
      Returns:
      this
    • timeout

      Sets the timeout of each HTTP request.
      Parameters:
      timeout - the timeout
      Returns:
      this
    • modelName

      public GoogleGenAiTextToSpeechModel.Builder modelName(String modelName)
      Sets the text-to-speech model to use, for example gemini-3.8-flash-tts. Required.
      Parameters:
      modelName - the model name
      Returns:
      this
    • maxRetries

      public GoogleGenAiTextToSpeechModel.Builder maxRetries(Integer maxRetries)
      Sets how many times a failed request is retried. Defaults to 3.
      Parameters:
      maxRetries - the maximum number of retries
      Returns:
      this
    • voice

      Sets the voice to use when a TextToSpeechRequest does not specify one, for example Kore or Puck. When no voice is set at all, the API chooses one.
      Parameters:
      voice - the name of a prebuilt voice
      Returns:
      this
    • languageCode

      public GoogleGenAiTextToSpeechModel.Builder languageCode(String languageCode)
      Sets the language of the speech as a BCP-47 code, for example de-DE. When it is not set, the language is detected from the text.
      Parameters:
      languageCode - the language code
      Returns:
      this
    • multiSpeakerVoiceConfig

      public GoogleGenAiTextToSpeechModel.Builder multiSpeakerVoiceConfig(com.google.genai.types.MultiSpeakerVoiceConfig multiSpeakerVoiceConfig)
      Sets the voice of each speaker of a conversation. The text is then split into turns: a line that starts with the name of a configured speaker followed by a colon, such as "Joe: Hello", starts a new turn spoken in that speaker's voice, and the following lines without a speaker name belong to the same turn. The text must start with a turn: text before the first one is rejected with an IllegalArgumentException.

      It requires a model that accepts a speaker per turn, such as gemini-3.8-flash-tts, and cannot be combined with a voice set with voice(String) or on the TextToSpeechRequest.

      Parameters:
      multiSpeakerVoiceConfig - the voices of the speakers
      Returns:
      this
    • speaker

      public GoogleGenAiTextToSpeechModel.Builder speaker(String speaker, String voice)
      Adds a speaker of a conversation and the prebuilt voice it speaks with, for example speaker("Joe", "Kore"). Call it once per speaker; it is a shorter way to build the multiSpeakerVoiceConfig(MultiSpeakerVoiceConfig), and adds to one that is already set.
      Parameters:
      speaker - the name that starts the turns of this speaker in the text
      voice - the name of a prebuilt voice
      Returns:
      this
    • safetySettings

      public GoogleGenAiTextToSpeechModel.Builder safetySettings(List<com.google.genai.types.SafetySetting> safetySettings)
      Sets the safety settings applied to the text.
      Parameters:
      safetySettings - the safety settings
      Returns:
      this
    • logRequests

      public GoogleGenAiTextToSpeechModel.Builder logRequests(Boolean logRequests)
      Enables logging of the requests sent to the API.
      Parameters:
      logRequests - whether to log requests
      Returns:
      this
    • logResponses

      public GoogleGenAiTextToSpeechModel.Builder logResponses(Boolean logResponses)
      Enables logging of the responses received from the API. The audio itself is not logged, only its MIME type and size.
      Parameters:
      logResponses - whether to log responses
      Returns:
      this
    • logRequestsAndResponses

      public GoogleGenAiTextToSpeechModel.Builder logRequestsAndResponses(Boolean logRequestsAndResponses)
      Enables logging of both the requests and the responses.
      Parameters:
      logRequestsAndResponses - whether to log requests and responses
      Returns:
      this
    • apiEndpoint

      public GoogleGenAiTextToSpeechModel.Builder apiEndpoint(String apiEndpoint)
      Sets the base URL of the API.
      Parameters:
      apiEndpoint - the base URL
      Returns:
      this
    • customHeaders

      public GoogleGenAiTextToSpeechModel.Builder customHeaders(Map<String,String> customHeaders)
      Sets HTTP headers added to every request.
      Parameters:
      customHeaders - the headers
      Returns:
      this
    • labels

      Sets labels attached to every request, used by Vertex AI to break down billing.
      Parameters:
      labels - the labels
      Returns:
      this
    • build