Skip to content

feat(js): Support speech configuration for Gemini TTS models #3016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions js/plugins/googleai/src/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,59 @@ const SafetySettingsSchema = z.object({
]),
});

const VoiceConfigSchema = z
.object({
prebuiltVoiceConfig: z
.object({
// TODO: Make this an array of objects so we can also specify the description
// for each voiceName.
voiceName: z
.union([
z.enum([
'Zephyr',
'Puck',
'Charon',
'Kore',
'Fenrir',
'Leda',
'Orus',
'Aoede',
'Callirrhoe',
'Autonoe',
'Enceladus',
'Iapetus',
'Umbriel',
'Algieba',
'Despina',
'Erinome',
'Algenib',
'Rasalgethi',
'Laomedeia',
'Achernar',
'Alnilam',
'Schedar',
'Gacrux',
'Pulcherrima',
'Achird',
'Zubenelgenubi',
'Vindemiatrix',
'Sadachbia',
'Sadaltager',
'Sulafat',
]),
// To allow any new string values
z.string(),
])
.describe('Name of the preset voice to use')
.optional(),
})
.describe('Configuration for the prebuilt speaker to use')
.passthrough()
.optional(),
})
.describe('Configuration for the voice to use')
.passthrough();

export const GeminiConfigSchema = GenerationCommonConfigSchema.extend({
apiKey: z
.string()
Expand Down Expand Up @@ -142,6 +195,35 @@ export const GeminiConfigSchema = GenerationCommonConfigSchema.extend({
}).passthrough();
export type GeminiConfig = z.infer<typeof GeminiConfigSchema>;

export const GeminiTtsConfigSchema = GeminiConfigSchema.extend({
speechConfig: z
.object({
voiceConfig: VoiceConfigSchema.optional(),
multiSpeakerVoiceConfig: z
.object({
speakerVoiceConfigs: z
.array(
z
.object({
speaker: z.string().describe('Name of the speaker to use'),
voiceConfig: VoiceConfigSchema,
})
.describe(
'Configuration for a single speaker in a multi speaker setup'
)
.passthrough()
)
.describe('Configuration for all the enabled speaker voices'),
})
.describe('Configuration for multi-speaker setup')
.passthrough()
.optional(),
})
.describe('Speech generation config')
.passthrough()
.optional(),
}).passthrough();

export const gemini10Pro = modelRef({
name: 'googleai/gemini-1.0-pro',
info: {
Expand Down Expand Up @@ -305,6 +387,23 @@ export const gemini25FlashPreview0417 = modelRef({
configSchema: GeminiConfigSchema,
});

export const gemini25FlashPreviewTts = modelRef({
name: 'googleai/gemini-2.5-flash-preview-tts',
info: {
label: 'Google AI - Gemini 2.5 Flash Preview TTS',
versions: [],
supports: {
multiturn: false,
media: false,
tools: false,
toolChoice: false,
systemRole: false,
constrained: 'no-tools',
},
},
configSchema: GeminiTtsConfigSchema,
});

export const gemini25ProExp0325 = modelRef({
name: 'googleai/gemini-2.5-pro-exp-03-25',
info: {
Expand Down Expand Up @@ -354,6 +453,7 @@ export const SUPPORTED_V15_MODELS = {
'gemini-2.5-pro-exp-03-25': gemini25ProExp0325,
'gemini-2.5-pro-preview-03-25': gemini25ProPreview0325,
'gemini-2.5-flash-preview-04-17': gemini25FlashPreview0417,
'gemini-2.5-flash-preview-tts': gemini25FlashPreviewTts,
};

export const GENERIC_GEMINI_MODEL = modelRef({
Expand Down