@mastra/mcp-docs-server 0.13.12-alpha.2 → 0.13.12-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +34 -34
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +29 -29
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +44 -44
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +23 -23
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +33 -33
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +38 -38
- package/.docs/organized/changelogs/%40mastra%2Frag.md +23 -23
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +34 -34
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +24 -24
- package/.docs/organized/changelogs/create-mastra.md +9 -9
- package/.docs/organized/changelogs/mastra.md +42 -42
- package/.docs/organized/code-examples/agent.md +75 -11
- package/.docs/raw/deployment/server-deployment.mdx +57 -27
- package/.docs/raw/deployment/serverless-platforms/cloudflare-deployer.mdx +4 -7
- package/.docs/raw/frameworks/servers/express.mdx +135 -143
- package/.docs/raw/reference/agents/agent.mdx +1 -1
- package/.docs/raw/reference/agents/getDefaultVNextStreamOptions.mdx +1 -1
- package/.docs/raw/reference/agents/streamVNext.mdx +1 -1
- package/.docs/raw/reference/deployer/cloudflare.mdx +20 -131
- package/.docs/raw/reference/memory/Memory.mdx +1 -1
- package/.docs/raw/reference/voice/google-gemini-live.mdx +629 -0
- package/.docs/raw/voice/overview.mdx +21 -33
- package/.docs/raw/workflows/suspend-and-resume.mdx +2 -2
- package/package.json +4 -4
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Reference: Google Gemini Live Voice | Voice Providers | Mastra Docs"
|
|
3
|
+
description: "Documentation for the GeminiLiveVoice class, providing real-time multimodal voice interactions using Google's Gemini Live API with support for both Gemini API and Vertex AI."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Google Gemini Live Voice
|
|
7
|
+
|
|
8
|
+
The GeminiLiveVoice class provides real-time voice interaction capabilities using Google's Gemini Live API. It supports bidirectional audio streaming, tool calling, session management, and both standard Google API and Vertex AI authentication methods.
|
|
9
|
+
|
|
10
|
+
## Usage Example
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { GeminiLiveVoice } from "@mastra/voice-google-gemini-live";
|
|
14
|
+
import { playAudio, getMicrophoneStream } from "@mastra/node-audio";
|
|
15
|
+
|
|
16
|
+
// Initialize with Gemini API (using API key)
|
|
17
|
+
const voice = new GeminiLiveVoice({
|
|
18
|
+
apiKey: process.env.GOOGLE_API_KEY, // Required for Gemini API
|
|
19
|
+
model: "gemini-2.0-flash-exp",
|
|
20
|
+
speaker: "Puck", // Default voice
|
|
21
|
+
debug: true,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Or initialize with Vertex AI (using OAuth)
|
|
25
|
+
const voiceWithVertexAI = new GeminiLiveVoice({
|
|
26
|
+
vertexAI: true,
|
|
27
|
+
project: "your-gcp-project",
|
|
28
|
+
location: "us-central1",
|
|
29
|
+
serviceAccountKeyFile: "/path/to/service-account.json",
|
|
30
|
+
model: "gemini-2.0-flash-exp",
|
|
31
|
+
speaker: "Puck",
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Or use the VoiceConfig pattern (recommended for consistency with other providers)
|
|
35
|
+
const voiceWithConfig = new GeminiLiveVoice({
|
|
36
|
+
speechModel: {
|
|
37
|
+
name: "gemini-2.0-flash-exp",
|
|
38
|
+
apiKey: process.env.GOOGLE_API_KEY,
|
|
39
|
+
},
|
|
40
|
+
speaker: "Puck",
|
|
41
|
+
realtimeConfig: {
|
|
42
|
+
model: "gemini-2.0-flash-exp",
|
|
43
|
+
apiKey: process.env.GOOGLE_API_KEY,
|
|
44
|
+
options: {
|
|
45
|
+
debug: true,
|
|
46
|
+
sessionConfig: {
|
|
47
|
+
interrupts: { enabled: true },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Establish connection (required before using other methods)
|
|
54
|
+
await voice.connect();
|
|
55
|
+
|
|
56
|
+
// Set up event listeners
|
|
57
|
+
voice.on("speaker", (audioStream) => {
|
|
58
|
+
// Handle audio stream (NodeJS.ReadableStream)
|
|
59
|
+
playAudio(audioStream);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
voice.on("writing", ({ text, role }) => {
|
|
63
|
+
// Handle transcribed text
|
|
64
|
+
console.log(`${role}: ${text}`);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
voice.on("turnComplete", ({ timestamp }) => {
|
|
68
|
+
// Handle turn completion
|
|
69
|
+
console.log("Turn completed at:", timestamp);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Convert text to speech
|
|
73
|
+
await voice.speak("Hello, how can I help you today?", {
|
|
74
|
+
speaker: "Charon", // Override default voice
|
|
75
|
+
responseModalities: ["AUDIO", "TEXT"],
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Process audio input
|
|
79
|
+
const microphoneStream = getMicrophoneStream();
|
|
80
|
+
await voice.send(microphoneStream);
|
|
81
|
+
|
|
82
|
+
// Update session configuration
|
|
83
|
+
await voice.updateSessionConfig({
|
|
84
|
+
speaker: "Kore",
|
|
85
|
+
instructions: "Be more concise in your responses",
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// When done, disconnect
|
|
89
|
+
await voice.disconnect();
|
|
90
|
+
// Or use the synchronous wrapper
|
|
91
|
+
voice.close();
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Configuration
|
|
95
|
+
|
|
96
|
+
### Constructor Options
|
|
97
|
+
|
|
98
|
+
<PropertiesTable
|
|
99
|
+
content={[
|
|
100
|
+
{
|
|
101
|
+
name: "apiKey",
|
|
102
|
+
type: "string",
|
|
103
|
+
description:
|
|
104
|
+
"Google API key for Gemini API authentication. Required unless using Vertex AI.",
|
|
105
|
+
isOptional: true,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: "model",
|
|
109
|
+
type: "GeminiVoiceModel",
|
|
110
|
+
description: "The model ID to use for real-time voice interactions.",
|
|
111
|
+
isOptional: true,
|
|
112
|
+
defaultValue: "'gemini-2.0-flash-exp'",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: "speaker",
|
|
116
|
+
type: "GeminiVoiceName",
|
|
117
|
+
description: "Default voice ID for speech synthesis.",
|
|
118
|
+
isOptional: true,
|
|
119
|
+
defaultValue: "'Puck'",
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: "vertexAI",
|
|
123
|
+
type: "boolean",
|
|
124
|
+
description: "Use Vertex AI instead of Gemini API for authentication.",
|
|
125
|
+
isOptional: true,
|
|
126
|
+
defaultValue: "false",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: "project",
|
|
130
|
+
type: "string",
|
|
131
|
+
description: "Google Cloud project ID (required for Vertex AI).",
|
|
132
|
+
isOptional: true,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: "location",
|
|
136
|
+
type: "string",
|
|
137
|
+
description: "Google Cloud region for Vertex AI.",
|
|
138
|
+
isOptional: true,
|
|
139
|
+
defaultValue: "'us-central1'",
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "serviceAccountKeyFile",
|
|
143
|
+
type: "string",
|
|
144
|
+
description:
|
|
145
|
+
"Path to service account JSON key file for Vertex AI authentication.",
|
|
146
|
+
isOptional: true,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: "serviceAccountEmail",
|
|
150
|
+
type: "string",
|
|
151
|
+
description:
|
|
152
|
+
"Service account email for impersonation (alternative to key file).",
|
|
153
|
+
isOptional: true,
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: "instructions",
|
|
157
|
+
type: "string",
|
|
158
|
+
description: "System instructions for the model.",
|
|
159
|
+
isOptional: true,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: "sessionConfig",
|
|
163
|
+
type: "GeminiSessionConfig",
|
|
164
|
+
description: "Session configuration including interrupt and context settings.",
|
|
165
|
+
isOptional: true,
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: "debug",
|
|
169
|
+
type: "boolean",
|
|
170
|
+
description: "Enable debug logging for troubleshooting.",
|
|
171
|
+
isOptional: true,
|
|
172
|
+
defaultValue: "false",
|
|
173
|
+
},
|
|
174
|
+
]}
|
|
175
|
+
/>
|
|
176
|
+
|
|
177
|
+
### Session Configuration
|
|
178
|
+
|
|
179
|
+
<PropertiesTable
|
|
180
|
+
content={[
|
|
181
|
+
{
|
|
182
|
+
name: "interrupts",
|
|
183
|
+
type: "object",
|
|
184
|
+
description: "Interrupt handling configuration.",
|
|
185
|
+
isOptional: true,
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
name: "interrupts.enabled",
|
|
189
|
+
type: "boolean",
|
|
190
|
+
description: "Enable interrupt handling.",
|
|
191
|
+
isOptional: true,
|
|
192
|
+
defaultValue: "true",
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: "interrupts.allowUserInterruption",
|
|
196
|
+
type: "boolean",
|
|
197
|
+
description: "Allow user to interrupt model responses.",
|
|
198
|
+
isOptional: true,
|
|
199
|
+
defaultValue: "true",
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
name: "contextCompression",
|
|
203
|
+
type: "boolean",
|
|
204
|
+
description: "Enable automatic context compression.",
|
|
205
|
+
isOptional: true,
|
|
206
|
+
defaultValue: "false",
|
|
207
|
+
},
|
|
208
|
+
]}
|
|
209
|
+
/>
|
|
210
|
+
|
|
211
|
+
## Methods
|
|
212
|
+
|
|
213
|
+
### connect()
|
|
214
|
+
|
|
215
|
+
Establishes a connection to the Gemini Live API. Must be called before using speak, listen, or send methods.
|
|
216
|
+
|
|
217
|
+
<PropertiesTable
|
|
218
|
+
content={[
|
|
219
|
+
{
|
|
220
|
+
name: "runtimeContext",
|
|
221
|
+
type: "object",
|
|
222
|
+
description: "Optional runtime context for the connection.",
|
|
223
|
+
isOptional: true,
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
name: "returns",
|
|
227
|
+
type: "Promise<void>",
|
|
228
|
+
description: "Promise that resolves when the connection is established.",
|
|
229
|
+
},
|
|
230
|
+
]}
|
|
231
|
+
/>
|
|
232
|
+
|
|
233
|
+
### speak()
|
|
234
|
+
|
|
235
|
+
Converts text to speech and sends it to the model. Can accept either a string or a readable stream as input.
|
|
236
|
+
|
|
237
|
+
<PropertiesTable
|
|
238
|
+
content={[
|
|
239
|
+
{
|
|
240
|
+
name: "input",
|
|
241
|
+
type: "string | NodeJS.ReadableStream",
|
|
242
|
+
description: "Text or text stream to convert to speech.",
|
|
243
|
+
isOptional: false,
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
name: "options",
|
|
247
|
+
type: "GeminiLiveVoiceOptions",
|
|
248
|
+
description: "Optional speech configuration.",
|
|
249
|
+
isOptional: true,
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: "options.speaker",
|
|
253
|
+
type: "GeminiVoiceName",
|
|
254
|
+
description: "Voice ID to use for this specific speech request.",
|
|
255
|
+
isOptional: true,
|
|
256
|
+
defaultValue: "Constructor's speaker value",
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
name: "options.languageCode",
|
|
260
|
+
type: "string",
|
|
261
|
+
description: "Language code for the response.",
|
|
262
|
+
isOptional: true,
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
name: "options.responseModalities",
|
|
266
|
+
type: "('AUDIO' | 'TEXT')[]",
|
|
267
|
+
description: "Response modalities to receive from the model.",
|
|
268
|
+
isOptional: true,
|
|
269
|
+
defaultValue: "['AUDIO', 'TEXT']",
|
|
270
|
+
},
|
|
271
|
+
]}
|
|
272
|
+
/>
|
|
273
|
+
|
|
274
|
+
Returns: `Promise<void>` (responses are emitted via `speaker` and `writing` events)
|
|
275
|
+
|
|
276
|
+
### listen()
|
|
277
|
+
|
|
278
|
+
Processes audio input for speech recognition. Takes a readable stream of audio data and returns the transcribed text.
|
|
279
|
+
|
|
280
|
+
<PropertiesTable
|
|
281
|
+
content={[
|
|
282
|
+
{
|
|
283
|
+
name: "audioStream",
|
|
284
|
+
type: "NodeJS.ReadableStream",
|
|
285
|
+
description: "Audio stream to transcribe.",
|
|
286
|
+
isOptional: false,
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
name: "options",
|
|
290
|
+
type: "GeminiLiveVoiceOptions",
|
|
291
|
+
description: "Optional listening configuration.",
|
|
292
|
+
isOptional: true,
|
|
293
|
+
},
|
|
294
|
+
]}
|
|
295
|
+
/>
|
|
296
|
+
|
|
297
|
+
Returns: `Promise<string>` - The transcribed text
|
|
298
|
+
|
|
299
|
+
### send()
|
|
300
|
+
|
|
301
|
+
Streams audio data in real-time to the Gemini service for continuous audio streaming scenarios like live microphone input.
|
|
302
|
+
|
|
303
|
+
<PropertiesTable
|
|
304
|
+
content={[
|
|
305
|
+
{
|
|
306
|
+
name: "audioData",
|
|
307
|
+
type: "NodeJS.ReadableStream | Int16Array",
|
|
308
|
+
description: "Audio stream or buffer to send to the service.",
|
|
309
|
+
isOptional: false,
|
|
310
|
+
},
|
|
311
|
+
]}
|
|
312
|
+
/>
|
|
313
|
+
|
|
314
|
+
Returns: `Promise<void>`
|
|
315
|
+
|
|
316
|
+
### updateSessionConfig()
|
|
317
|
+
|
|
318
|
+
Updates the session configuration dynamically. This can be used to modify voice settings, speaker selection, and other runtime configurations.
|
|
319
|
+
|
|
320
|
+
<PropertiesTable
|
|
321
|
+
content={[
|
|
322
|
+
{
|
|
323
|
+
name: "config",
|
|
324
|
+
type: "Partial<GeminiLiveVoiceConfig>",
|
|
325
|
+
description: "Configuration updates to apply.",
|
|
326
|
+
isOptional: false,
|
|
327
|
+
},
|
|
328
|
+
]}
|
|
329
|
+
/>
|
|
330
|
+
|
|
331
|
+
Returns: `Promise<void>`
|
|
332
|
+
|
|
333
|
+
### addTools()
|
|
334
|
+
|
|
335
|
+
Adds a set of tools to the voice instance. Tools allow the model to perform additional actions during conversations. When GeminiLiveVoice is added to an Agent, any tools configured for the Agent will automatically be available to the voice interface.
|
|
336
|
+
|
|
337
|
+
<PropertiesTable
|
|
338
|
+
content={[
|
|
339
|
+
{
|
|
340
|
+
name: "tools",
|
|
341
|
+
type: "ToolsInput",
|
|
342
|
+
description: "Tools configuration to equip.",
|
|
343
|
+
isOptional: false,
|
|
344
|
+
},
|
|
345
|
+
]}
|
|
346
|
+
/>
|
|
347
|
+
|
|
348
|
+
Returns: `void`
|
|
349
|
+
|
|
350
|
+
### addInstructions()
|
|
351
|
+
|
|
352
|
+
Adds or updates system instructions for the model.
|
|
353
|
+
|
|
354
|
+
<PropertiesTable
|
|
355
|
+
content={[
|
|
356
|
+
{
|
|
357
|
+
name: "instructions",
|
|
358
|
+
type: "string",
|
|
359
|
+
description: "System instructions to set.",
|
|
360
|
+
isOptional: true,
|
|
361
|
+
},
|
|
362
|
+
]}
|
|
363
|
+
/>
|
|
364
|
+
|
|
365
|
+
Returns: `void`
|
|
366
|
+
|
|
367
|
+
### answer()
|
|
368
|
+
|
|
369
|
+
Triggers a response from the model. This method is primarily used internally when integrated with an Agent.
|
|
370
|
+
|
|
371
|
+
<PropertiesTable
|
|
372
|
+
content={[
|
|
373
|
+
{
|
|
374
|
+
name: "options",
|
|
375
|
+
type: "Record<string, unknown>",
|
|
376
|
+
description: "Optional parameters for the answer request.",
|
|
377
|
+
isOptional: true,
|
|
378
|
+
},
|
|
379
|
+
]}
|
|
380
|
+
/>
|
|
381
|
+
|
|
382
|
+
Returns: `Promise<void>`
|
|
383
|
+
|
|
384
|
+
### getSpeakers()
|
|
385
|
+
|
|
386
|
+
Returns a list of available voice speakers for the Gemini Live API.
|
|
387
|
+
|
|
388
|
+
Returns: `Promise<Array<{ voiceId: string; description?: string }>>`
|
|
389
|
+
|
|
390
|
+
### disconnect()
|
|
391
|
+
|
|
392
|
+
Disconnects from the Gemini Live session and cleans up resources. This is the async method that properly handles cleanup.
|
|
393
|
+
|
|
394
|
+
Returns: `Promise<void>`
|
|
395
|
+
|
|
396
|
+
### close()
|
|
397
|
+
|
|
398
|
+
Synchronous wrapper for disconnect(). Calls disconnect() internally without awaiting.
|
|
399
|
+
|
|
400
|
+
Returns: `void`
|
|
401
|
+
|
|
402
|
+
### on()
|
|
403
|
+
|
|
404
|
+
Registers an event listener for voice events.
|
|
405
|
+
|
|
406
|
+
<PropertiesTable
|
|
407
|
+
content={[
|
|
408
|
+
{
|
|
409
|
+
name: "event",
|
|
410
|
+
type: "string",
|
|
411
|
+
description: "Name of the event to listen for.",
|
|
412
|
+
isOptional: false,
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
name: "callback",
|
|
416
|
+
type: "Function",
|
|
417
|
+
description: "Function to call when the event occurs.",
|
|
418
|
+
isOptional: false,
|
|
419
|
+
},
|
|
420
|
+
]}
|
|
421
|
+
/>
|
|
422
|
+
|
|
423
|
+
Returns: `void`
|
|
424
|
+
|
|
425
|
+
### off()
|
|
426
|
+
|
|
427
|
+
Removes a previously registered event listener.
|
|
428
|
+
|
|
429
|
+
<PropertiesTable
|
|
430
|
+
content={[
|
|
431
|
+
{
|
|
432
|
+
name: "event",
|
|
433
|
+
type: "string",
|
|
434
|
+
description: "Name of the event to stop listening to.",
|
|
435
|
+
isOptional: false,
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
name: "callback",
|
|
439
|
+
type: "Function",
|
|
440
|
+
description: "The specific callback function to remove.",
|
|
441
|
+
isOptional: false,
|
|
442
|
+
},
|
|
443
|
+
]}
|
|
444
|
+
/>
|
|
445
|
+
|
|
446
|
+
Returns: `void`
|
|
447
|
+
|
|
448
|
+
## Events
|
|
449
|
+
|
|
450
|
+
The GeminiLiveVoice class emits the following events:
|
|
451
|
+
|
|
452
|
+
<PropertiesTable
|
|
453
|
+
content={[
|
|
454
|
+
{
|
|
455
|
+
name: "speaker",
|
|
456
|
+
type: "event",
|
|
457
|
+
description:
|
|
458
|
+
"Emitted when audio data is received from the model. Callback receives a NodeJS.ReadableStream.",
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
name: "speaking",
|
|
462
|
+
type: "event",
|
|
463
|
+
description:
|
|
464
|
+
"Emitted with audio metadata. Callback receives { audioData?: Int16Array, sampleRate?: number }.",
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
name: "writing",
|
|
468
|
+
type: "event",
|
|
469
|
+
description:
|
|
470
|
+
"Emitted when transcribed text is available. Callback receives { text: string, role: 'assistant' | 'user' }.",
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
name: "session",
|
|
474
|
+
type: "event",
|
|
475
|
+
description:
|
|
476
|
+
"Emitted on session state changes. Callback receives { state: 'connecting' | 'connected' | 'disconnected' | 'disconnecting' | 'updated', config?: object }.",
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
name: "turnComplete",
|
|
480
|
+
type: "event",
|
|
481
|
+
description:
|
|
482
|
+
"Emitted when a conversation turn is completed. Callback receives { timestamp: number }.",
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
name: "toolCall",
|
|
486
|
+
type: "event",
|
|
487
|
+
description:
|
|
488
|
+
"Emitted when the model requests a tool call. Callback receives { name: string, args: object, id: string }.",
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
name: "usage",
|
|
492
|
+
type: "event",
|
|
493
|
+
description:
|
|
494
|
+
"Emitted with token usage information. Callback receives { inputTokens: number, outputTokens: number, totalTokens: number, modality: string }.",
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
name: "error",
|
|
498
|
+
type: "event",
|
|
499
|
+
description:
|
|
500
|
+
"Emitted when an error occurs. Callback receives { message: string, code?: string, details?: unknown }.",
|
|
501
|
+
},
|
|
502
|
+
|
|
503
|
+
{
|
|
504
|
+
name: "interrupt",
|
|
505
|
+
type: "event",
|
|
506
|
+
description:
|
|
507
|
+
"Interrupt events. Callback receives { type: 'user' | 'model', timestamp: number }.",
|
|
508
|
+
},
|
|
509
|
+
]}
|
|
510
|
+
/>
|
|
511
|
+
|
|
512
|
+
## Available Models
|
|
513
|
+
|
|
514
|
+
The following Gemini Live models are available:
|
|
515
|
+
|
|
516
|
+
- `gemini-2.0-flash-exp` (default)
|
|
517
|
+
- `gemini-2.0-flash-exp-image-generation`
|
|
518
|
+
- `gemini-2.0-flash-live-001`
|
|
519
|
+
- `gemini-live-2.5-flash-preview-native-audio`
|
|
520
|
+
- `gemini-2.5-flash-exp-native-audio-thinking-dialog`
|
|
521
|
+
- `gemini-live-2.5-flash-preview`
|
|
522
|
+
- `gemini-2.6.flash-preview-tts`
|
|
523
|
+
|
|
524
|
+
## Available Voices
|
|
525
|
+
|
|
526
|
+
The following voice options are available:
|
|
527
|
+
|
|
528
|
+
- `Puck` (default): Conversational, friendly
|
|
529
|
+
- `Charon`: Deep, authoritative
|
|
530
|
+
- `Kore`: Neutral, professional
|
|
531
|
+
- `Fenrir`: Warm, approachable
|
|
532
|
+
|
|
533
|
+
## Authentication Methods
|
|
534
|
+
|
|
535
|
+
### Gemini API (Development)
|
|
536
|
+
|
|
537
|
+
The simplest method using an API key from [Google AI Studio](https://makersuite.google.com/app/apikey):
|
|
538
|
+
|
|
539
|
+
```typescript
|
|
540
|
+
const voice = new GeminiLiveVoice({
|
|
541
|
+
apiKey: "your-api-key", // Required for Gemini API
|
|
542
|
+
model: "gemini-2.0-flash-exp",
|
|
543
|
+
});
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
### Vertex AI (Production)
|
|
547
|
+
|
|
548
|
+
For production use with OAuth authentication and Google Cloud Platform:
|
|
549
|
+
|
|
550
|
+
```typescript
|
|
551
|
+
// Using service account key file
|
|
552
|
+
const voice = new GeminiLiveVoice({
|
|
553
|
+
vertexAI: true,
|
|
554
|
+
project: "your-gcp-project",
|
|
555
|
+
location: "us-central1",
|
|
556
|
+
serviceAccountKeyFile: "/path/to/service-account.json",
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
// Using Application Default Credentials
|
|
560
|
+
const voice = new GeminiLiveVoice({
|
|
561
|
+
vertexAI: true,
|
|
562
|
+
project: "your-gcp-project",
|
|
563
|
+
location: "us-central1",
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
// Using service account impersonation
|
|
567
|
+
const voice = new GeminiLiveVoice({
|
|
568
|
+
vertexAI: true,
|
|
569
|
+
project: "your-gcp-project",
|
|
570
|
+
location: "us-central1",
|
|
571
|
+
serviceAccountEmail: "service-account@project.iam.gserviceaccount.com",
|
|
572
|
+
});
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
## Advanced Features
|
|
576
|
+
|
|
577
|
+
### Session Management
|
|
578
|
+
|
|
579
|
+
The Gemini Live API supports session resumption for handling network interruptions:
|
|
580
|
+
|
|
581
|
+
```typescript
|
|
582
|
+
voice.on("sessionHandle", ({ handle, expiresAt }) => {
|
|
583
|
+
// Store session handle for resumption
|
|
584
|
+
saveSessionHandle(handle, expiresAt);
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
// Resume a previous session
|
|
588
|
+
const voice = new GeminiLiveVoice({
|
|
589
|
+
sessionConfig: {
|
|
590
|
+
enableResumption: true,
|
|
591
|
+
maxDuration: "2h",
|
|
592
|
+
},
|
|
593
|
+
});
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
### Tool Calling
|
|
597
|
+
|
|
598
|
+
Enable the model to call functions during conversations:
|
|
599
|
+
|
|
600
|
+
```typescript
|
|
601
|
+
import { z } from 'zod';
|
|
602
|
+
|
|
603
|
+
voice.addTools({
|
|
604
|
+
weather: {
|
|
605
|
+
description: "Get weather information",
|
|
606
|
+
parameters: z.object({
|
|
607
|
+
location: z.string(),
|
|
608
|
+
}),
|
|
609
|
+
execute: async ({ location }) => {
|
|
610
|
+
const weather = await getWeather(location);
|
|
611
|
+
return weather;
|
|
612
|
+
},
|
|
613
|
+
},
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
voice.on("toolCall", ({ name, args, id }) => {
|
|
617
|
+
console.log(`Tool called: ${name} with args:`, args);
|
|
618
|
+
});
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
## Notes
|
|
622
|
+
|
|
623
|
+
- The Gemini Live API uses WebSockets for real-time communication
|
|
624
|
+
- Audio is processed as 16kHz PCM16 for input and 24kHz PCM16 for output
|
|
625
|
+
- The voice instance must be connected with `connect()` before using other methods
|
|
626
|
+
- Always call `close()` when done to properly clean up resources
|
|
627
|
+
- Vertex AI authentication requires appropriate IAM permissions (`aiplatform.user` role)
|
|
628
|
+
- Session resumption allows recovery from network interruptions
|
|
629
|
+
- The API supports real-time interactions with text and audio
|
|
@@ -625,6 +625,8 @@ const micStream = getMicrophoneStream();
|
|
|
625
625
|
await voiceAgent.voice.send(micStream);
|
|
626
626
|
```
|
|
627
627
|
|
|
628
|
+
Visit the [Google Gemini Live Reference](/reference/voice/google-gemini-live) for more information on the Google Gemini Live voice provider.
|
|
629
|
+
|
|
628
630
|
</Tabs.Tab>
|
|
629
631
|
</Tabs>
|
|
630
632
|
|
|
@@ -665,38 +667,6 @@ Visit the [OpenAI Voice Reference](/reference/voice/openai) for more information
|
|
|
665
667
|
</Tabs.Tab>
|
|
666
668
|
<Tabs.Tab>
|
|
667
669
|
```typescript
|
|
668
|
-
// Google Gemini Live Voice Configuration
|
|
669
|
-
import { GeminiLiveVoice } from '@mastra/voice-google-gemini-live';
|
|
670
|
-
|
|
671
|
-
const voice = new GeminiLiveVoice({
|
|
672
|
-
// Live API
|
|
673
|
-
apiKey: process.env.GOOGLE_API_KEY,
|
|
674
|
-
model: 'gemini-2.0-flash-exp',
|
|
675
|
-
speaker: 'Puck',
|
|
676
|
-
debug: true,
|
|
677
|
-
// Vertex AI alternative:
|
|
678
|
-
// vertexAI: true,
|
|
679
|
-
// project: 'your-gcp-project',
|
|
680
|
-
// location: 'us-central1',
|
|
681
|
-
// serviceAccountKeyFile: '/path/to/service-account.json',
|
|
682
|
-
// sessionConfig: {
|
|
683
|
-
// vad: { enabled: true, sensitivity: 0.5, silenceDurationMs: 1000 },
|
|
684
|
-
// interrupts: { enabled: true, allowUserInterruption: true },
|
|
685
|
-
// contextCompression: false,
|
|
686
|
-
// }
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
// Per-turn overrides
|
|
690
|
-
await voice.speak('Hello', {
|
|
691
|
-
languageCode: 'en-US',
|
|
692
|
-
responseModalities: ['AUDIO'] as any,
|
|
693
|
-
speaker: 'Puck',
|
|
694
|
-
});
|
|
695
|
-
```
|
|
696
|
-
|
|
697
|
-
</Tabs.Tab>
|
|
698
|
-
<Tabs.Tab>
|
|
699
|
-
```typescript
|
|
700
670
|
// Azure Voice Configuration
|
|
701
671
|
const voice = new AzureVoice({
|
|
702
672
|
speechModel: {
|
|
@@ -774,7 +744,7 @@ const voice = new GoogleVoice({
|
|
|
774
744
|
});
|
|
775
745
|
```
|
|
776
746
|
|
|
777
|
-
Visit the [
|
|
747
|
+
Visit the [Google Voice Reference](/reference/voice/google) for more information on the Google voice provider.
|
|
778
748
|
|
|
779
749
|
</Tabs.Tab>
|
|
780
750
|
<Tabs.Tab>
|
|
@@ -888,6 +858,22 @@ const voice = new OpenAIRealtimeVoice({
|
|
|
888
858
|
|
|
889
859
|
For more information on the OpenAI Realtime voice provider, refer to the [OpenAI Realtime Voice Reference](/reference/voice/openai-realtime).
|
|
890
860
|
|
|
861
|
+
</Tabs.Tab>
|
|
862
|
+
<Tabs.Tab>
|
|
863
|
+
```typescript
|
|
864
|
+
// Google Gemini Live Voice Configuration
|
|
865
|
+
const voice = new GeminiLiveVoice({
|
|
866
|
+
speechModel: {
|
|
867
|
+
name: "gemini-2.0-flash-exp", // Example model name
|
|
868
|
+
apiKey: process.env.GOOGLE_API_KEY,
|
|
869
|
+
},
|
|
870
|
+
speaker: "Puck", // Example speaker name
|
|
871
|
+
// Google Gemini Live is a realtime bidirectional API without separate speech and listening models
|
|
872
|
+
});
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
Visit the [Google Gemini Live Reference](/reference/voice/google-gemini-live) for more information on the Google Gemini Live voice provider.
|
|
876
|
+
|
|
891
877
|
</Tabs.Tab>
|
|
892
878
|
</Tabs>
|
|
893
879
|
|
|
@@ -949,8 +935,10 @@ For more information on the CompositeVoice, refer to the [CompositeVoice Referen
|
|
|
949
935
|
- [CompositeVoice](../../reference/voice/composite-voice.mdx)
|
|
950
936
|
- [MastraVoice](../../reference/voice/mastra-voice.mdx)
|
|
951
937
|
- [OpenAI Voice](../../reference/voice/openai.mdx)
|
|
938
|
+
- [OpenAI Realtime Voice](../../reference/voice/openai-realtime.mdx)
|
|
952
939
|
- [Azure Voice](../../reference/voice/azure.mdx)
|
|
953
940
|
- [Google Voice](../../reference/voice/google.mdx)
|
|
941
|
+
- [Google Gemini Live Voice](../../reference/voice/google-gemini-live.mdx)
|
|
954
942
|
- [Deepgram Voice](../../reference/voice/deepgram.mdx)
|
|
955
943
|
- [PlayAI Voice](../../reference/voice/playai.mdx)
|
|
956
944
|
- [Voice Examples](../../examples/voice/text-to-speech.mdx)
|