Class GoogleGenAiAudioSpeechOptions
- All Implemented Interfaces:
TextToSpeechOptions,ModelOptions
com.google.genai).
These options map to the speechConfig field of a GenerateContentConfig
requested with the AUDIO response modality: model selects
the Gemini-TTS model (for example gemini-2.5-flash-tts), voiceName maps to speechConfig.voiceConfig.prebuiltVoiceConfig.voiceName,
replicatedVoice maps to
speechConfig.voiceConfig.replicatedVoiceConfig, languageCode to speechConfig.languageCode and speakerVoiceConfigs to
speechConfig.multiSpeakerVoiceConfig.speakerVoiceConfigs.
The Gemini-TTS models also accept natural-language steering: stylePrompt is prepended to the synthesized text, and multiSpeakerTurns is rendered as "Speaker: text" lines matching the speaker
names of getSpeakerVoiceConfigs().
The Gemini API returns 24 kHz, 16-bit, mono PCM audio. audioEncoding only selects whether the raw PCM bytes (GoogleGenAiAudioSpeechOptions.AudioEncoding.PCM) or a
WAV-wrapped version (GoogleGenAiAudioSpeechOptions.AudioEncoding.LINEAR16) are returned.
- Since:
- 2.0.2
- Author:
- Olivier Le Quellec
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe format of the audio byte stream returned by the synthesis.static final classstatic final recordA single speaker turn used for multi-speaker synthesis input.static final recordA cloned voice sample used to synthesize speech with a replicated voice (maps tospeechConfig.voiceConfig.replicatedVoiceConfig).static final recordA single speaker-to-voice mapping for multi-speaker synthesis. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final GoogleGenAiAudioSpeechOptions.AudioEncodingThe default audio encoding used for the synthesized audio.static final StringThe default Gemini-TTS model.static final StringThe default prebuilt voice.static final intThe sample rate (in hertz) of the audio returned by the Gemini-TTS models. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates a newTextToSpeechOptions.Builderto create the defaultTextToSpeechOptions.boolean@Nullable StringThe output format maps toaudioEncoding.@Nullable String@Nullable StringgetModel()Returns the model to use for text-to-speech.@Nullable DoublegetSpeed()The Gemini-TTS models do not expose a speaking-rate parameter; pacing is controlled through thestyle prompt.@Nullable String@Nullable StringgetVoice()Returns the voice to use for text-to-speech.@Nullable StringinthashCode()voidsetAudioEncoding(@Nullable GoogleGenAiAudioSpeechOptions.AudioEncoding audioEncoding) voidsetLanguageCode(@Nullable String languageCode) voidvoidsetMultiSpeakerTurns(@Nullable List<GoogleGenAiAudioSpeechOptions.MultiSpeakerTurn> multiSpeakerTurns) voidsetReplicatedVoice(@Nullable GoogleGenAiAudioSpeechOptions.ReplicatedVoice replicatedVoice) voidsetSpeakerVoiceConfigs(@Nullable List<GoogleGenAiAudioSpeechOptions.SpeakerVoiceConfig> speakerVoiceConfigs) voidsetStylePrompt(@Nullable String stylePrompt) voidsetVoiceName(@Nullable String voiceName) toString()
-
Field Details
-
DEFAULT_MODEL
The default Gemini-TTS model.- See Also:
-
DEFAULT_VOICE
The default prebuilt voice.- See Also:
-
DEFAULT_AUDIO_ENCODING
The default audio encoding used for the synthesized audio. -
OUTPUT_SAMPLE_RATE_HERTZ
public static final int OUTPUT_SAMPLE_RATE_HERTZThe sample rate (in hertz) of the audio returned by the Gemini-TTS models.- See Also:
-
-
Constructor Details
-
GoogleGenAiAudioSpeechOptions
public GoogleGenAiAudioSpeechOptions()
-
-
Method Details
-
builder
Description copied from interface:TextToSpeechOptionsCreates a newTextToSpeechOptions.Builderto create the defaultTextToSpeechOptions.- Returns:
- Returns a new
TextToSpeechOptions.Builder.
-
getModel
Description copied from interface:TextToSpeechOptionsReturns the model to use for text-to-speech.- Specified by:
getModelin interfaceTextToSpeechOptions- Returns:
- The model name.
-
setModel
-
getVoiceName
-
setVoiceName
-
getVoice
Description copied from interface:TextToSpeechOptionsReturns the voice to use for text-to-speech.- Specified by:
getVoicein interfaceTextToSpeechOptions- Returns:
- The voice identifier.
-
getReplicatedVoice
-
setReplicatedVoice
public void setReplicatedVoice(@Nullable GoogleGenAiAudioSpeechOptions.ReplicatedVoice replicatedVoice) -
getLanguageCode
-
setLanguageCode
-
getStylePrompt
-
setStylePrompt
-
getSpeakerVoiceConfigs
-
setSpeakerVoiceConfigs
public void setSpeakerVoiceConfigs(@Nullable List<GoogleGenAiAudioSpeechOptions.SpeakerVoiceConfig> speakerVoiceConfigs) -
getMultiSpeakerTurns
-
setMultiSpeakerTurns
public void setMultiSpeakerTurns(@Nullable List<GoogleGenAiAudioSpeechOptions.MultiSpeakerTurn> multiSpeakerTurns) -
getAudioEncoding
-
setAudioEncoding
-
getSpeed
The Gemini-TTS models do not expose a speaking-rate parameter; pacing is controlled through thestyle prompt.- Specified by:
getSpeedin interfaceTextToSpeechOptions- Returns:
- always
null
-
getFormat
The output format maps toaudioEncoding.- Specified by:
getFormatin interfaceTextToSpeechOptions- Returns:
- the name of the configured
GoogleGenAiAudioSpeechOptions.AudioEncoding, ornullif unset
-
equals
-
hashCode
public int hashCode() -
toString
-