Class GoogleGenAiTextToSpeechModel.Builder
java.lang.Object
dev.langchain4j.model.google.genai.GoogleGenAiTextToSpeechModel.Builder
- Enclosing class:
GoogleGenAiTextToSpeechModel
- Since:
- 1.23.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapiEndpoint(String apiEndpoint) Sets the base URL of the API.Sets the API key of the Gemini Developer API.apiVersion(@Nullable String apiVersion) The version of the API to call, for examplev1betaorv1.build()client(com.google.genai.Client client) Sets the Google GenAI client to use.customHeaders(Map<String, String> customHeaders) Sets HTTP headers added to every request.googleCredentials(com.google.auth.oauth2.GoogleCredentials googleCredentials) Sets the credentials used to call Vertex AI.Sets labels attached to every request, used by Vertex AI to break down billing.languageCode(String languageCode) Sets the language of the speech as a BCP-47 code, for examplede-DE.Sets the Google Cloud location used to call Vertex AI.logRequests(Boolean logRequests) Enables logging of the requests sent to the API.logRequestsAndResponses(Boolean logRequestsAndResponses) Enables logging of both the requests and the responses.logResponses(Boolean logResponses) Enables logging of the responses received from the API.maxRetries(Integer maxRetries) Sets how many times a failed request is retried.Sets the text-to-speech model to use, for examplegemini-3.8-flash-tts.multiSpeakerVoiceConfig(com.google.genai.types.MultiSpeakerVoiceConfig multiSpeakerVoiceConfig) Sets the voice of each speaker of a conversation.Sets the Google Cloud project used to call Vertex AI.safetySettings(List<com.google.genai.types.SafetySetting> safetySettings) Sets the safety settings applied to the text.Adds a speaker of a conversation and the prebuilt voice it speaks with, for examplespeaker("Joe", "Kore").Sets the timeout of each HTTP request to the Google GenAI API.
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
client
Sets the Google GenAI client to use. When set, the authentication and transport options of this builder are ignored.A
Clientthat you build uses the default API version of the Google GenAI SDK (v1on the Gemini Developer API), while the client that this builder creates usesapiVersion(String)(v1betaby default). Some features and model aliases are available onv1betaonly: setHttpOptions.builder().apiVersion("v1beta")on your client to use them.- 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
Sets the Google Cloud project used to call Vertex AI.- Parameters:
projectId- the project ID- Returns:
this
-
location
Sets the Google Cloud location used to call Vertex AI.- Parameters:
location- the location, for exampleglobal- Returns:
this
-
timeout
Sets the timeout of each HTTP request to the Google GenAI API. It limits the whole request: connecting, waiting for the model and receiving the response. A request that times out is retried (seemaxRetries(Integer)), and each retry gets the full timeout. Defaults to 20 minutes. Ignored whenclient(Client)is set.- Parameters:
timeout- the timeout- Returns:
this
-
modelName
Sets the text-to-speech model to use, for examplegemini-3.8-flash-tts. Required.- Parameters:
modelName- the model name- Returns:
this
-
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 aTextToSpeechRequestdoes not specify one, for exampleKoreorPuck. When no voice is set at all, the API chooses one.- Parameters:
voice- the name of a prebuilt voice- Returns:
this
-
languageCode
Sets the language of the speech as a BCP-47 code, for examplede-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 anIllegalArgumentException.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 withvoice(String)or on theTextToSpeechRequest.- Parameters:
multiSpeakerVoiceConfig- the voices of the speakers- Returns:
this
-
speaker
Adds a speaker of a conversation and the prebuilt voice it speaks with, for examplespeaker("Joe", "Kore"). Call it once per speaker; it is a shorter way to build themultiSpeakerVoiceConfig(MultiSpeakerVoiceConfig), and adds to one that is already set.- Parameters:
speaker- the name that starts the turns of this speaker in the textvoice- 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
Enables logging of the requests sent to the API.- Parameters:
logRequests- whether to log requests- Returns:
this
-
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
Sets the base URL of the API.- Parameters:
apiEndpoint- the base URL- Returns:
this
-
apiVersion
The version of the API to call, for examplev1betaorv1. When not set (null), the version set in theGOOGLE_GENAI_API_VERSIONenvironment variable is used, otherwisev1betaon the Gemini Developer API and the default of the Google GenAI SDK on Vertex AI. Ignored when a client is set withclient(...). -
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
-