Class GoogleGenAiTextToSpeechModel
java.lang.Object
dev.langchain4j.model.google.genai.GoogleGenAiTextToSpeechModel
- All Implemented Interfaces:
TextToSpeechModel
Represents a Google GenAI text-to-speech model, such as
gemini-3.8-flash-tts, using the official
com.google.genai SDK.
TextToSpeechModel model = GoogleGenAiTextToSpeechModel.builder()
.apiKey(System.getenv("GOOGLE_AI_GEMINI_API_KEY"))
.modelName("gemini-3.8-flash-tts")
.voice("Kore")
.build();
TextToSpeechResponse response = model.synthesize("Have a wonderful day!");
Raw 16-bit PCM audio (audio/L16 or audio/pcm) is wrapped in a WAV header built from the sample
rate and channel count of its MIME type, so that it can be played or saved as a WAV file. Any other audio, such as
the WAV returned by the gemini-3.8 text-to-speech models, is returned unchanged.
With GoogleGenAiTextToSpeechModel.Builder.speaker(String, String) or GoogleGenAiTextToSpeechModel.Builder.multiSpeakerVoiceConfig(MultiSpeakerVoiceConfig),
the text is read as a conversation in which
every turn starts with the name of a configured speaker followed by a colon, for example
"Joe: How is it going today, Jane?\nJane: Not too bad, how about you?", and every turn is spoken in the
voice of its speaker. Text before the first turn is rejected with an IllegalArgumentException.
- Since:
- 1.23.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbuilder()provider()synthesize(TextToSpeechRequest request) Given a text-to-speech request, synthesizes speech audio.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface TextToSpeechModel
synthesize
-
Method Details
-
builder
-
synthesize
Description copied from interface:TextToSpeechModelGiven a text-to-speech request, synthesizes speech audio.- Specified by:
synthesizein interfaceTextToSpeechModel- Parameters:
request- The speech request containing the input text and optional parameters.- Returns:
- The generated speech response.
-
provider
- Specified by:
providerin interfaceTextToSpeechModel
-