@mastra/voice-google-gemini-live 0.0.0-add-libsql-changeset-20250910154739
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/CHANGELOG.md +159 -0
- package/LICENSE.md +15 -0
- package/README.md +459 -0
- package/dist/index.cjs +2788 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +436 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2786 -0
- package/dist/index.js.map +1 -0
- package/dist/managers/AudioStreamManager.d.ts +207 -0
- package/dist/managers/AudioStreamManager.d.ts.map +1 -0
- package/dist/managers/AuthManager.d.ts +57 -0
- package/dist/managers/AuthManager.d.ts.map +1 -0
- package/dist/managers/ConnectionManager.d.ts +57 -0
- package/dist/managers/ConnectionManager.d.ts.map +1 -0
- package/dist/managers/ContextManager.d.ts +73 -0
- package/dist/managers/ContextManager.d.ts.map +1 -0
- package/dist/managers/EventManager.d.ts +64 -0
- package/dist/managers/EventManager.d.ts.map +1 -0
- package/dist/managers/SessionManager.d.ts +84 -0
- package/dist/managers/SessionManager.d.ts.map +1 -0
- package/dist/managers/index.d.ts +12 -0
- package/dist/managers/index.d.ts.map +1 -0
- package/dist/types.d.ts +319 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/errors.d.ts +17 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/package.json +66 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# @mastra/voice-google-gemini-live
|
|
2
|
+
|
|
3
|
+
## 0.0.0-add-libsql-changeset-20250910154739
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`b4379f7`](https://github.com/mastra-ai/mastra/commit/b4379f703fd74474f253420e8c3a684f2c4b2f8e), [`d34aaa1`](https://github.com/mastra-ai/mastra/commit/d34aaa1da5d3c5f991740f59e2fe6d28d3e2dd91), [`b2babfa`](https://github.com/mastra-ai/mastra/commit/b2babfa9e75b22f2759179e71d8473f6dc5421ed), [`d8c3ba5`](https://github.com/mastra-ai/mastra/commit/d8c3ba516f4173282d293f7e64769cfc8738d360), [`6424c7e`](https://github.com/mastra-ai/mastra/commit/6424c7ec38b6921d66212431db1e0958f441b2a7), [`db94750`](https://github.com/mastra-ai/mastra/commit/db94750a41fd29b43eb1f7ce8e97ba8b9978c91b), [`a66a371`](https://github.com/mastra-ai/mastra/commit/a66a3716b00553d7f01842be9deb34f720b10fab), [`69fc3cd`](https://github.com/mastra-ai/mastra/commit/69fc3cd0fd814901785bdcf49bf536ab1e7fd975)]:
|
|
8
|
+
- @mastra/core@0.0.0-add-libsql-changeset-20250910154739
|
|
9
|
+
|
|
10
|
+
## 0.10.10
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 376913a: Update peerdeps
|
|
15
|
+
- Updated dependencies [8fbf79e]
|
|
16
|
+
- Updated dependencies [fd83526]
|
|
17
|
+
- Updated dependencies [d0b90ab]
|
|
18
|
+
- Updated dependencies [6f5eb7a]
|
|
19
|
+
- Updated dependencies [a01cf14]
|
|
20
|
+
- Updated dependencies [a9e50ee]
|
|
21
|
+
- Updated dependencies [5397eb4]
|
|
22
|
+
- Updated dependencies [c9f4e4a]
|
|
23
|
+
- Updated dependencies [0acbc80]
|
|
24
|
+
- @mastra/core@0.16.0
|
|
25
|
+
|
|
26
|
+
## 0.10.10-alpha.0
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- 376913a: Update peerdeps
|
|
31
|
+
- Updated dependencies [8fbf79e]
|
|
32
|
+
- @mastra/core@0.16.0-alpha.1
|
|
33
|
+
|
|
34
|
+
## 0.10.9
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- ab48c97: dependencies updates:
|
|
39
|
+
- Updated dependency [`zod@^3.25.76` ↗︎](https://www.npmjs.com/package/zod/v/3.25.76) (from `^3.25.67`, in `dependencies`)
|
|
40
|
+
- Updated dependency [`zod-to-json-schema@^3.24.6` ↗︎](https://www.npmjs.com/package/zod-to-json-schema/v/3.24.6) (from `^3.23.5`, in `dependencies`)
|
|
41
|
+
- de3cbc6: Update the `package.json` file to include additional fields like `repository`, `homepage` or `files`.
|
|
42
|
+
- f0dfcac: updated core peerdep
|
|
43
|
+
- Updated dependencies [ab48c97]
|
|
44
|
+
- Updated dependencies [85ef90b]
|
|
45
|
+
- Updated dependencies [aedbbfa]
|
|
46
|
+
- Updated dependencies [ff89505]
|
|
47
|
+
- Updated dependencies [637f323]
|
|
48
|
+
- Updated dependencies [de3cbc6]
|
|
49
|
+
- Updated dependencies [c19bcf7]
|
|
50
|
+
- Updated dependencies [4474d04]
|
|
51
|
+
- Updated dependencies [183dc95]
|
|
52
|
+
- Updated dependencies [a1111e2]
|
|
53
|
+
- Updated dependencies [b42a961]
|
|
54
|
+
- Updated dependencies [61debef]
|
|
55
|
+
- Updated dependencies [9beaeff]
|
|
56
|
+
- Updated dependencies [29de0e1]
|
|
57
|
+
- Updated dependencies [f643c65]
|
|
58
|
+
- Updated dependencies [00c74e7]
|
|
59
|
+
- Updated dependencies [fef7375]
|
|
60
|
+
- Updated dependencies [e3d8fea]
|
|
61
|
+
- Updated dependencies [45e4d39]
|
|
62
|
+
- Updated dependencies [9eee594]
|
|
63
|
+
- Updated dependencies [7149d8d]
|
|
64
|
+
- Updated dependencies [822c2e8]
|
|
65
|
+
- Updated dependencies [979912c]
|
|
66
|
+
- Updated dependencies [7dcf4c0]
|
|
67
|
+
- Updated dependencies [4106a58]
|
|
68
|
+
- Updated dependencies [ad78bfc]
|
|
69
|
+
- Updated dependencies [0302f50]
|
|
70
|
+
- Updated dependencies [6ac697e]
|
|
71
|
+
- Updated dependencies [74db265]
|
|
72
|
+
- Updated dependencies [0ce418a]
|
|
73
|
+
- Updated dependencies [af90672]
|
|
74
|
+
- Updated dependencies [8387952]
|
|
75
|
+
- Updated dependencies [7f3b8da]
|
|
76
|
+
- Updated dependencies [905352b]
|
|
77
|
+
- Updated dependencies [599d04c]
|
|
78
|
+
- Updated dependencies [56041d0]
|
|
79
|
+
- Updated dependencies [3412597]
|
|
80
|
+
- Updated dependencies [5eca5d2]
|
|
81
|
+
- Updated dependencies [f2cda47]
|
|
82
|
+
- Updated dependencies [5de1555]
|
|
83
|
+
- Updated dependencies [cfd377a]
|
|
84
|
+
- Updated dependencies [1ed5a3e]
|
|
85
|
+
- @mastra/core@0.15.3
|
|
86
|
+
|
|
87
|
+
## 0.10.9-alpha.2
|
|
88
|
+
|
|
89
|
+
### Patch Changes
|
|
90
|
+
|
|
91
|
+
- [#7394](https://github.com/mastra-ai/mastra/pull/7394) [`f0dfcac`](https://github.com/mastra-ai/mastra/commit/f0dfcac4458bdf789b975e2d63e984f5d1e7c4d3) Thanks [@NikAiyer](https://github.com/NikAiyer)! - updated core peerdep
|
|
92
|
+
|
|
93
|
+
- Updated dependencies [[`7149d8d`](https://github.com/mastra-ai/mastra/commit/7149d8d4bdc1edf0008e0ca9b7925eb0b8b60dbe)]:
|
|
94
|
+
- @mastra/core@0.15.3-alpha.7
|
|
95
|
+
|
|
96
|
+
## 0.10.9-alpha.1
|
|
97
|
+
|
|
98
|
+
### Patch Changes
|
|
99
|
+
|
|
100
|
+
- [#7343](https://github.com/mastra-ai/mastra/pull/7343) [`de3cbc6`](https://github.com/mastra-ai/mastra/commit/de3cbc61079211431bd30487982ea3653517278e) Thanks [@LekoArts](https://github.com/LekoArts)! - Update the `package.json` file to include additional fields like `repository`, `homepage` or `files`.
|
|
101
|
+
|
|
102
|
+
- Updated dependencies [[`85ef90b`](https://github.com/mastra-ai/mastra/commit/85ef90bb2cd4ae4df855c7ac175f7d392c55c1bf), [`de3cbc6`](https://github.com/mastra-ai/mastra/commit/de3cbc61079211431bd30487982ea3653517278e)]:
|
|
103
|
+
- @mastra/core@0.15.3-alpha.5
|
|
104
|
+
|
|
105
|
+
## 0.10.9-alpha.0
|
|
106
|
+
|
|
107
|
+
### Patch Changes
|
|
108
|
+
|
|
109
|
+
- [#5816](https://github.com/mastra-ai/mastra/pull/5816) [`ab48c97`](https://github.com/mastra-ai/mastra/commit/ab48c979098ea571faf998a55d3a00e7acd7a715) Thanks [@dane-ai-mastra](https://github.com/apps/dane-ai-mastra)! - dependencies updates:
|
|
110
|
+
- Updated dependency [`zod@^3.25.76` ↗︎](https://www.npmjs.com/package/zod/v/3.25.76) (from `^3.25.67`, in `dependencies`)
|
|
111
|
+
- Updated dependency [`zod-to-json-schema@^3.24.6` ↗︎](https://www.npmjs.com/package/zod-to-json-schema/v/3.24.6) (from `^3.23.5`, in `dependencies`)
|
|
112
|
+
- Updated dependencies [[`ab48c97`](https://github.com/mastra-ai/mastra/commit/ab48c979098ea571faf998a55d3a00e7acd7a715), [`ff89505`](https://github.com/mastra-ai/mastra/commit/ff895057c8c7e91a5535faef46c5e5391085ddfa), [`183dc95`](https://github.com/mastra-ai/mastra/commit/183dc95596f391b977bd1a2c050b8498dac74891), [`a1111e2`](https://github.com/mastra-ai/mastra/commit/a1111e24e705488adfe5e0a6f20c53bddf26cb22), [`61debef`](https://github.com/mastra-ai/mastra/commit/61debefd80ad3a7ed5737e19df6a23d40091689a), [`9beaeff`](https://github.com/mastra-ai/mastra/commit/9beaeffa4a97b1d5fd01a7f8af8708b16067f67c), [`9eee594`](https://github.com/mastra-ai/mastra/commit/9eee594e35e0ca2a650fcc33fa82009a142b9ed0), [`979912c`](https://github.com/mastra-ai/mastra/commit/979912cfd180aad53287cda08af771df26454e2c), [`7dcf4c0`](https://github.com/mastra-ai/mastra/commit/7dcf4c04f44d9345b1f8bc5d41eae3f11ac61611), [`ad78bfc`](https://github.com/mastra-ai/mastra/commit/ad78bfc4ea6a1fff140432bf4f638e01af7af668), [`0ce418a`](https://github.com/mastra-ai/mastra/commit/0ce418a1ccaa5e125d4483a9651b635046152569), [`8387952`](https://github.com/mastra-ai/mastra/commit/838795227b4edf758c84a2adf6f7fba206c27719), [`5eca5d2`](https://github.com/mastra-ai/mastra/commit/5eca5d2655788863ea0442a46c9ef5d3c6dbe0a8)]:
|
|
113
|
+
- @mastra/core@0.15.3-alpha.4
|
|
114
|
+
|
|
115
|
+
## 0.10.8
|
|
116
|
+
|
|
117
|
+
### Patch Changes
|
|
118
|
+
|
|
119
|
+
- [`c6113ed`](https://github.com/mastra-ai/mastra/commit/c6113ed7f9df297e130d94436ceee310273d6430) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix peerdpes for @mastra/core
|
|
120
|
+
|
|
121
|
+
- Updated dependencies []:
|
|
122
|
+
- @mastra/core@0.15.2
|
|
123
|
+
|
|
124
|
+
## 0.10.7
|
|
125
|
+
|
|
126
|
+
### Patch Changes
|
|
127
|
+
|
|
128
|
+
- dd512a2: Integrates Google Gemini Live API into the Mastra framework
|
|
129
|
+
- Updated dependencies [227c7e6]
|
|
130
|
+
- Updated dependencies [12cae67]
|
|
131
|
+
- Updated dependencies [fd3a3eb]
|
|
132
|
+
- Updated dependencies [6faaee5]
|
|
133
|
+
- Updated dependencies [4232b14]
|
|
134
|
+
- Updated dependencies [a89de7e]
|
|
135
|
+
- Updated dependencies [5a37d0c]
|
|
136
|
+
- Updated dependencies [4bde0cb]
|
|
137
|
+
- Updated dependencies [cf4f357]
|
|
138
|
+
- Updated dependencies [ad888a2]
|
|
139
|
+
- Updated dependencies [481751d]
|
|
140
|
+
- Updated dependencies [2454423]
|
|
141
|
+
- Updated dependencies [194e395]
|
|
142
|
+
- Updated dependencies [a722c0b]
|
|
143
|
+
- Updated dependencies [c30bca8]
|
|
144
|
+
- Updated dependencies [3b5fec7]
|
|
145
|
+
- Updated dependencies [a8f129d]
|
|
146
|
+
- @mastra/core@0.14.0
|
|
147
|
+
|
|
148
|
+
## 0.10.7-alpha.0
|
|
149
|
+
|
|
150
|
+
### Patch Changes
|
|
151
|
+
|
|
152
|
+
- dd512a2: Integrates Google Gemini Live API into the Mastra framework
|
|
153
|
+
- Updated dependencies [6faaee5]
|
|
154
|
+
- Updated dependencies [4232b14]
|
|
155
|
+
- Updated dependencies [a89de7e]
|
|
156
|
+
- Updated dependencies [cf4f357]
|
|
157
|
+
- Updated dependencies [a722c0b]
|
|
158
|
+
- Updated dependencies [3b5fec7]
|
|
159
|
+
- @mastra/core@0.14.0-alpha.1
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Apache License 2.0
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
# @mastra/voice-google-gemini-live
|
|
2
|
+
|
|
3
|
+
Google Gemini Live API integration for Mastra, providing real-time multimodal voice interactions with advanced capabilities including video input, tool calling, and session management.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mastra/voice-google-gemini-live
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Configuration
|
|
12
|
+
|
|
13
|
+
The module supports two authentication methods:
|
|
14
|
+
|
|
15
|
+
### Option 1: Gemini API (Recommended for development)
|
|
16
|
+
|
|
17
|
+
Use an API key from [Google AI Studio](https://makersuite.google.com/app/apikey):
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Set environment variable
|
|
21
|
+
GOOGLE_API_KEY=your_api_key
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Option 2: Vertex AI (Recommended for production)
|
|
25
|
+
|
|
26
|
+
Use OAuth authentication with Google Cloud Platform. There are multiple ways to authenticate:
|
|
27
|
+
|
|
28
|
+
#### Application Default Credentials (ADC)
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Install gcloud CLI and authenticate
|
|
32
|
+
gcloud auth application-default login
|
|
33
|
+
|
|
34
|
+
# Set project ID
|
|
35
|
+
GOOGLE_CLOUD_PROJECT=your_project_id
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### Service Account Key File
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# Set path to service account JSON
|
|
42
|
+
GOOGLE_APPLICATION_CREDENTIALS=path/to/service-account.json
|
|
43
|
+
GOOGLE_CLOUD_PROJECT=your_project_id
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
#### Service Account in Code
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
const voice = new GeminiLiveVoice({
|
|
50
|
+
vertexAI: true,
|
|
51
|
+
project: 'your-gcp-project',
|
|
52
|
+
location: 'us-central1',
|
|
53
|
+
serviceAccountKeyFile: '/path/to/service-account.json',
|
|
54
|
+
// OR use service account email for impersonation
|
|
55
|
+
serviceAccountEmail: 'service-account@project.iam.gserviceaccount.com',
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Required Permissions for Vertex AI
|
|
60
|
+
|
|
61
|
+
When using Vertex AI, ensure your service account or user has these IAM roles:
|
|
62
|
+
|
|
63
|
+
- `aiplatform.user` or specific permissions:
|
|
64
|
+
- `aiplatform.endpoints.predict`
|
|
65
|
+
- `aiplatform.models.predict`
|
|
66
|
+
|
|
67
|
+
## Usage
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { GeminiLiveVoice } from '@mastra/voice-google-gemini-live';
|
|
71
|
+
|
|
72
|
+
// Initialize with Gemini API
|
|
73
|
+
const voice = new GeminiLiveVoice({
|
|
74
|
+
apiKey: 'your-api-key', // Optional, can use GOOGLE_API_KEY env var
|
|
75
|
+
model: 'gemini-2.0-flash-live-001',
|
|
76
|
+
speaker: 'Puck', // Default voice
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// OR initialize with Vertex AI (recommended for production)
|
|
80
|
+
const voice = new GeminiLiveVoice({
|
|
81
|
+
vertexAI: true,
|
|
82
|
+
project: 'your-project-id',
|
|
83
|
+
model: 'gemini-2.0-flash-live-001',
|
|
84
|
+
speaker: 'Puck',
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Connect to the Live API
|
|
88
|
+
await voice.connect();
|
|
89
|
+
|
|
90
|
+
// Listen for responses
|
|
91
|
+
voice.on('speaking', ({ audioData }) => {
|
|
92
|
+
// Handle audio response as Int16Array
|
|
93
|
+
playAudio(audioData);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Or subscribe to a concatenated audio stream per response
|
|
97
|
+
voice.on('speaker', audioStream => {
|
|
98
|
+
audioStream.pipe(playbackDevice);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
voice.on('writing', ({ text, role }) => {
|
|
102
|
+
// Handle transcribed text
|
|
103
|
+
console.log(`${role}: ${text}`);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Send text to speech
|
|
107
|
+
await voice.speak('Hello from Mastra!');
|
|
108
|
+
|
|
109
|
+
// Send audio stream
|
|
110
|
+
const microphoneStream = getMicrophoneStream();
|
|
111
|
+
await voice.send(microphoneStream);
|
|
112
|
+
|
|
113
|
+
// When done, disconnect
|
|
114
|
+
voice.disconnect();
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## API Reference
|
|
118
|
+
|
|
119
|
+
### Constructor
|
|
120
|
+
|
|
121
|
+
**`new GeminiLiveVoice(options?: GeminiLiveVoiceConfig)`**
|
|
122
|
+
|
|
123
|
+
Creates a new GeminiLiveVoice instance.
|
|
124
|
+
|
|
125
|
+
**Parameters:**
|
|
126
|
+
|
|
127
|
+
- `options` (optional): Configuration object
|
|
128
|
+
- `apiKey?: string` - Google API key (falls back to GOOGLE_API_KEY env var)
|
|
129
|
+
- `model?: GeminiVoiceModel` - Model to use (default: 'gemini-2.0-flash-exp')
|
|
130
|
+
- `speaker?: GeminiVoiceName` - Voice to use (default: 'Puck')
|
|
131
|
+
- `vertexAI?: boolean` - Use Vertex AI instead of Gemini API
|
|
132
|
+
- `project?: string` - Google Cloud project ID (required for Vertex AI)
|
|
133
|
+
- `location?: string` - Google Cloud region (default: 'us-central1')
|
|
134
|
+
- `serviceAccountKeyFile?: string` - Path to service account JSON key file
|
|
135
|
+
- `serviceAccountEmail?: string` - Service account email for impersonation
|
|
136
|
+
- `instructions?: string` - System instructions for the model
|
|
137
|
+
- `tools?: GeminiToolConfig[]` - Tools available to the model
|
|
138
|
+
- `sessionConfig?: GeminiSessionConfig` - Session configuration
|
|
139
|
+
- `audioConfig?: Partial<AudioConfig>` - Audio configuration
|
|
140
|
+
- `debug?: boolean` - Enable debug logging
|
|
141
|
+
|
|
142
|
+
### Connection Management
|
|
143
|
+
|
|
144
|
+
**`async connect(): Promise<void>`**
|
|
145
|
+
|
|
146
|
+
Establishes connection to the Gemini Live API. Must be called before using other methods.
|
|
147
|
+
|
|
148
|
+
**Returns:** Promise that resolves when connection is established
|
|
149
|
+
|
|
150
|
+
**Throws:** Error if connection fails or authentication is invalid
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
**`async disconnect(): Promise<void>`**
|
|
155
|
+
|
|
156
|
+
Disconnects from the Gemini Live API and cleans up resources.
|
|
157
|
+
|
|
158
|
+
**Returns:** Promise that resolves when disconnection is complete
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
**`getConnectionState(): 'disconnected' | 'connected'`**
|
|
163
|
+
|
|
164
|
+
Gets the current connection state.
|
|
165
|
+
|
|
166
|
+
**Returns:** Current connection state
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
**`isConnected(): boolean`**
|
|
171
|
+
|
|
172
|
+
Checks if currently connected to the API.
|
|
173
|
+
|
|
174
|
+
**Returns:** true if connected, false otherwise
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
Connection lifecycle transitions such as "connecting", "disconnecting", and "updated" are emitted via the `session` event:
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
voice.on('session', data => {
|
|
182
|
+
// data.state is one of: 'connecting' | 'connected' | 'disconnected' | 'disconnecting' | 'updated'
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Audio and Speech
|
|
187
|
+
|
|
188
|
+
**`async speak(input: string | NodeJS.ReadableStream, options?: GeminiLiveVoiceOptions): Promise<void>`**
|
|
189
|
+
|
|
190
|
+
Converts text to speech and sends it to the model.
|
|
191
|
+
|
|
192
|
+
**Parameters:**
|
|
193
|
+
|
|
194
|
+
- `input: string | NodeJS.ReadableStream` - Text to convert to speech
|
|
195
|
+
- `options?: GeminiLiveVoiceOptions` - Optional speech options
|
|
196
|
+
- `speaker?: GeminiVoiceName` - Override the default speaker
|
|
197
|
+
- `languageCode?: string` - Language code for the response
|
|
198
|
+
- `responseModalities?: ('AUDIO' | 'TEXT')[]` - Response modalities
|
|
199
|
+
|
|
200
|
+
**Returns:** Promise<void> (responses are emitted via `speaker` and `writing` events)
|
|
201
|
+
|
|
202
|
+
**Throws:** Error if not connected or input is empty
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
**`async send(audioData: NodeJS.ReadableStream | Int16Array): Promise<void>`**
|
|
207
|
+
|
|
208
|
+
Sends audio data for real-time processing.
|
|
209
|
+
|
|
210
|
+
**Parameters:**
|
|
211
|
+
|
|
212
|
+
- `audioData: NodeJS.ReadableStream | Int16Array` - Audio data to send
|
|
213
|
+
|
|
214
|
+
**Returns:** Promise that resolves when audio is sent
|
|
215
|
+
|
|
216
|
+
**Throws:** Error if not connected or audio format is invalid
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
**`async listen(audioStream: NodeJS.ReadableStream, options?: GeminiLiveVoiceOptions): Promise<string>`**
|
|
221
|
+
|
|
222
|
+
Processes audio stream for speech-to-text transcription.
|
|
223
|
+
|
|
224
|
+
**Parameters:**
|
|
225
|
+
|
|
226
|
+
- `audioStream: NodeJS.ReadableStream` - Audio stream to transcribe
|
|
227
|
+
- `options?: GeminiLiveVoiceOptions` - Optional transcription options
|
|
228
|
+
|
|
229
|
+
**Returns:** Promise that resolves to transcribed text
|
|
230
|
+
|
|
231
|
+
**Throws:** Error if not connected, audio format is invalid, or transcription fails
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
**`getCurrentSpeakerStream(): NodeJS.ReadableStream | null`**
|
|
236
|
+
|
|
237
|
+
Gets the current concatenated audio stream for the active response.
|
|
238
|
+
|
|
239
|
+
**Returns:** ReadableStream of concatenated audio chunks, or null if no active stream
|
|
240
|
+
|
|
241
|
+
### Session Management
|
|
242
|
+
|
|
243
|
+
**`async updateSessionConfig(config: Partial<GeminiLiveVoiceConfig>): Promise<void>`**
|
|
244
|
+
|
|
245
|
+
Updates session configuration during an active session.
|
|
246
|
+
|
|
247
|
+
**Parameters:**
|
|
248
|
+
|
|
249
|
+
- `config: Partial<GeminiLiveVoiceConfig>` - Configuration to update
|
|
250
|
+
- `speaker?: GeminiVoiceName` - Change voice/speaker
|
|
251
|
+
- `instructions?: string` - Update system instructions
|
|
252
|
+
- `tools?: GeminiToolConfig[]` - Update available tools
|
|
253
|
+
- `sessionConfig?: GeminiSessionConfig` - Update session settings (e.g. `vad`, `interrupts`, `contextCompression`)
|
|
254
|
+
|
|
255
|
+
**Returns:** Promise that resolves when configuration is updated
|
|
256
|
+
|
|
257
|
+
**Throws:** Error if not connected or update fails
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
**`async resumeSession(handle: string): Promise<void>`**
|
|
262
|
+
|
|
263
|
+
Resumes a previous session using a session handle.
|
|
264
|
+
|
|
265
|
+
**Parameters:**
|
|
266
|
+
|
|
267
|
+
- `handle: string` - Session handle from previous session
|
|
268
|
+
|
|
269
|
+
**Returns:** Promise that resolves when session is resumed
|
|
270
|
+
|
|
271
|
+
**Note:** Session resumption is not yet fully implemented for Gemini Live API
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
**`getSessionHandle(): string | undefined`**
|
|
276
|
+
|
|
277
|
+
Gets the current session handle for resumption.
|
|
278
|
+
|
|
279
|
+
**Returns:** Session handle string, or undefined if not available
|
|
280
|
+
|
|
281
|
+
**Note:** Session handles are not yet fully supported by Gemini Live API
|
|
282
|
+
|
|
283
|
+
### Voice and Model Information
|
|
284
|
+
|
|
285
|
+
**`async getSpeakers(): Promise<Array<{ voiceId: string; description?: string }>>`**
|
|
286
|
+
|
|
287
|
+
Gets available speakers/voices.
|
|
288
|
+
|
|
289
|
+
**Returns:** Promise that resolves to array of available voices with descriptions
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
**`async getListener(): Promise<{ enabled: boolean }>`**
|
|
294
|
+
|
|
295
|
+
Checks if listening capabilities are enabled.
|
|
296
|
+
|
|
297
|
+
**Returns:** Promise that resolves to listening status
|
|
298
|
+
|
|
299
|
+
**Note:** Inherits default implementation from MastraVoice base class
|
|
300
|
+
|
|
301
|
+
### Event Handling
|
|
302
|
+
|
|
303
|
+
**`on<E extends VoiceEventType>(event: E, callback: (data: E extends keyof GeminiLiveEventMap ? GeminiLiveEventMap[E] : unknown) => void): void`**
|
|
304
|
+
|
|
305
|
+
Registers an event listener.
|
|
306
|
+
|
|
307
|
+
**Parameters:**
|
|
308
|
+
|
|
309
|
+
- `event: E` - Event name to listen for
|
|
310
|
+
- `callback: (data) => void` - Function to call when event occurs
|
|
311
|
+
|
|
312
|
+
**Available Events:**
|
|
313
|
+
|
|
314
|
+
- `'speaking'` - Audio response from model
|
|
315
|
+
- `'speaker'` - Readable stream of concatenated audio for the active response
|
|
316
|
+
- `'writing'` - Text response or transcription
|
|
317
|
+
- `'error'` - Error events
|
|
318
|
+
- `'session'` - Session state changes
|
|
319
|
+
- `'toolCall'` - Tool calls from model
|
|
320
|
+
- `'vad'` - Voice activity detection events
|
|
321
|
+
- `'interrupt'` - Interrupt events
|
|
322
|
+
- `'usage'` - Token usage information
|
|
323
|
+
- `'sessionHandle'` - Session resumption handle
|
|
324
|
+
- `'turnComplete'` - Turn completion for the current model response
|
|
325
|
+
|
|
326
|
+
### Tools
|
|
327
|
+
|
|
328
|
+
Add tools with `addTools()` using either `@mastra/core/tools` or a plain object matching `ToolsInput`.
|
|
329
|
+
|
|
330
|
+
Using `createTool`:
|
|
331
|
+
|
|
332
|
+
```ts
|
|
333
|
+
import { createTool } from '@mastra/core/tools';
|
|
334
|
+
import { z } from 'zod';
|
|
335
|
+
|
|
336
|
+
const searchTool = createTool({
|
|
337
|
+
id: 'search',
|
|
338
|
+
description: 'Search the web',
|
|
339
|
+
inputSchema: z.object({ query: z.string() }),
|
|
340
|
+
execute: async ({ context }) => {
|
|
341
|
+
const { query } = context;
|
|
342
|
+
// ... perform search
|
|
343
|
+
return { results: [] };
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
voice.addTools({ search: searchTool });
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
Using a plain object (ensure each tool has an `id`):
|
|
351
|
+
|
|
352
|
+
```ts
|
|
353
|
+
voice.addTools({
|
|
354
|
+
search: {
|
|
355
|
+
id: 'search',
|
|
356
|
+
description: 'Search the web',
|
|
357
|
+
inputSchema: { type: 'object', properties: { query: { type: 'string' } } },
|
|
358
|
+
execute: async ({ context }) => ({ results: [] }),
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
Tool call events from the model are emitted as:
|
|
364
|
+
|
|
365
|
+
```ts
|
|
366
|
+
voice.on('toolCall', ({ name, args, id }) => {
|
|
367
|
+
// name: string, args: Record<string, any>, id: string
|
|
368
|
+
});
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
**`off<E extends VoiceEventType>(event: E, callback: (data: E extends keyof GeminiLiveEventMap ? GeminiLiveEventMap[E] : unknown) => void): void`**
|
|
374
|
+
|
|
375
|
+
Removes an event listener.
|
|
376
|
+
|
|
377
|
+
**Parameters:**
|
|
378
|
+
|
|
379
|
+
- `event: E` - Event name to stop listening to
|
|
380
|
+
- `callback: (data) => void` - Specific callback function to remove
|
|
381
|
+
|
|
382
|
+
### Configuration Types
|
|
383
|
+
|
|
384
|
+
**`GeminiLiveVoiceConfig`**
|
|
385
|
+
|
|
386
|
+
```typescript
|
|
387
|
+
interface GeminiLiveVoiceConfig {
|
|
388
|
+
apiKey?: string;
|
|
389
|
+
model?: GeminiVoiceModel;
|
|
390
|
+
speaker?: GeminiVoiceName;
|
|
391
|
+
vertexAI?: boolean;
|
|
392
|
+
project?: string;
|
|
393
|
+
location?: string;
|
|
394
|
+
serviceAccountKeyFile?: string;
|
|
395
|
+
serviceAccountEmail?: string;
|
|
396
|
+
instructions?: string;
|
|
397
|
+
tools?: GeminiToolConfig[];
|
|
398
|
+
sessionConfig?: GeminiSessionConfig;
|
|
399
|
+
audioConfig?: Partial<AudioConfig>;
|
|
400
|
+
debug?: boolean;
|
|
401
|
+
}
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
**`GeminiLiveVoiceOptions`**
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
interface GeminiLiveVoiceOptions {
|
|
408
|
+
speaker?: GeminiVoiceName;
|
|
409
|
+
languageCode?: string;
|
|
410
|
+
responseModalities?: ('AUDIO' | 'TEXT')[];
|
|
411
|
+
}
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
**`GeminiSessionConfig`**
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
interface GeminiSessionConfig {
|
|
418
|
+
enableResumption?: boolean;
|
|
419
|
+
maxDuration?: string;
|
|
420
|
+
contextCompression?: boolean;
|
|
421
|
+
vad?: {
|
|
422
|
+
enabled?: boolean;
|
|
423
|
+
sensitivity?: number;
|
|
424
|
+
silenceDurationMs?: number;
|
|
425
|
+
};
|
|
426
|
+
interrupts?: {
|
|
427
|
+
enabled?: boolean;
|
|
428
|
+
allowUserInterruption?: boolean;
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
## Features
|
|
434
|
+
|
|
435
|
+
- **Real-time bidirectional audio streaming**
|
|
436
|
+
- **Multimodal input support** (audio, video, text)
|
|
437
|
+
- **Built-in Voice Activity Detection (VAD)**
|
|
438
|
+
- **Interrupt handling** - Natural conversation flow
|
|
439
|
+
- **Session management** - Resume conversations after network interruptions
|
|
440
|
+
- **Tool calling support** - Integrate with external APIs and functions
|
|
441
|
+
- **Live transcription** - Real-time speech-to-text
|
|
442
|
+
- **Multiple voice options** - Choose from various voice personalities
|
|
443
|
+
- **Multilingual support** - Support for 30+ languages
|
|
444
|
+
|
|
445
|
+
## Voice Options
|
|
446
|
+
|
|
447
|
+
- **Puck** - Conversational, friendly
|
|
448
|
+
- **Charon** - Deep, authoritative
|
|
449
|
+
- **Kore** - Neutral, professional
|
|
450
|
+
- **Fenrir** - Warm, approachable
|
|
451
|
+
|
|
452
|
+
## Model Options
|
|
453
|
+
|
|
454
|
+
- `gemini-2.0-flash-exp` - Default model
|
|
455
|
+
- `gemini-2.0-flash-live-001` - Latest production model
|
|
456
|
+
- `gemini-2.5-flash-preview-native-audio-dialog` - Preview with native audio
|
|
457
|
+
- `gemini-live-2.5-flash-preview` - Half-cascade architecture
|
|
458
|
+
|
|
459
|
+
For detailed API documentation, visit [Google's Gemini Live API docs](https://ai.google.dev/gemini-api/docs/live).
|