Class GoogleGenAiTextToSpeechModel

java.lang.Object
dev.langchain4j.model.google.genai.GoogleGenAiTextToSpeechModel
All Implemented Interfaces:
TextToSpeechModel

@Experimental public class GoogleGenAiTextToSpeechModel extends Object implements 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