@mastra/voice-google 0.14.0 → 0.14.1
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 +12 -0
- package/dist/_types/@internal_voice/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +19 -220
- package/dist/_types/@internal_voice/dist/_types/@internal_core/dist/base/index.d.ts +27 -27
- package/dist/_types/@internal_voice/dist/_types/@internal_core/dist/index-S1lgaKO7.d.ts +218 -0
- package/dist/_types/@internal_voice/dist/_types/@internal_core/dist/request-context/index.d.ts +122 -105
- package/dist/_types/@internal_voice/dist/_types/@internal_core/dist/types/index.d.ts +4 -2
- package/dist/docs/SKILL.md +5 -5
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/{docs-voice-overview.md → guides-voice-overview.md} +85 -131
- package/dist/docs/references/integrations-voice-google.md +688 -0
- package/dist/index.cjs +547 -531
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +546 -529
- package/dist/index.js.map +1 -1
- package/package.json +12 -11
- package/dist/_types/@internal_voice/dist/_types/@internal_core/dist/logger/index.d.ts +0 -217
- package/dist/docs/references/reference-voice-google.md +0 -274
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
-
|
|
3
|
-
# Google
|
|
4
|
-
|
|
5
|
-
The Google Voice implementation in Mastra provides both text-to-speech (TTS) and speech-to-text (STT) capabilities using Google Cloud services. It supports multiple voices, languages, advanced audio configuration options, and both standard API key authentication and Vertex AI mode for enterprise deployments.
|
|
6
|
-
|
|
7
|
-
## Usage example
|
|
8
|
-
|
|
9
|
-
```typescript
|
|
10
|
-
import { GoogleVoice } from '@mastra/voice-google'
|
|
11
|
-
|
|
12
|
-
// Initialize with default configuration (uses GOOGLE_API_KEY environment variable)
|
|
13
|
-
const voice = new GoogleVoice()
|
|
14
|
-
|
|
15
|
-
// Text-to-Speech (plain text)
|
|
16
|
-
const audioStream = await voice.speak('Hello, world!', {
|
|
17
|
-
languageCode: 'en-US',
|
|
18
|
-
audioConfig: {
|
|
19
|
-
audioEncoding: 'LINEAR16',
|
|
20
|
-
},
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
// Text-to-Speech with SSML
|
|
24
|
-
const ssmlStream = await voice.speak('ignored', {
|
|
25
|
-
input: {
|
|
26
|
-
ssml: '<speak>Take <say-as interpret-as="unit">5 mg</say-as> daily.</speak>',
|
|
27
|
-
},
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
// Text-to-Speech with Gemini-TTS model
|
|
31
|
-
const geminiStream = await voice.speak('Hello from Gemini TTS!', {
|
|
32
|
-
voice: { name: 'Kore', modelName: 'gemini-2.5-flash-preview-tts' },
|
|
33
|
-
input: { prompt: 'Warm, calm tone.' },
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
// Speech-to-Text
|
|
37
|
-
const transcript = await voice.listen(audioStream, {
|
|
38
|
-
config: {
|
|
39
|
-
encoding: 'LINEAR16',
|
|
40
|
-
languageCode: 'en-US',
|
|
41
|
-
},
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
// Get available voices for a specific language
|
|
45
|
-
const voices = await voice.getSpeakers({ languageCode: 'en-US' })
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## Constructor parameters
|
|
49
|
-
|
|
50
|
-
**speechModel** (`GoogleModelConfig`): Configuration for text-to-speech functionality (Default: `{ apiKey: process.env.GOOGLE_API_KEY }`)
|
|
51
|
-
|
|
52
|
-
**speechModel.apiKey** (`string`): Google Cloud API key. Falls back to GOOGLE\_API\_KEY environment variable. Not used when vertexAI is true.
|
|
53
|
-
|
|
54
|
-
**speechModel.keyFilename** (`string`): Path to service account JSON key file. Falls back to GOOGLE\_APPLICATION\_CREDENTIALS environment variable.
|
|
55
|
-
|
|
56
|
-
**speechModel.credentials** (`object`): In-memory service account credentials object with client\_email and private\_key properties.
|
|
57
|
-
|
|
58
|
-
**listeningModel** (`GoogleModelConfig`): Configuration for speech-to-text functionality (Default: `{ apiKey: process.env.GOOGLE_API_KEY }`)
|
|
59
|
-
|
|
60
|
-
**listeningModel.apiKey** (`string`): Google Cloud API key. Falls back to GOOGLE\_API\_KEY environment variable. Not used when vertexAI is true.
|
|
61
|
-
|
|
62
|
-
**listeningModel.keyFilename** (`string`): Path to service account JSON key file. Falls back to GOOGLE\_APPLICATION\_CREDENTIALS environment variable.
|
|
63
|
-
|
|
64
|
-
**listeningModel.credentials** (`object`): In-memory service account credentials object with client\_email and private\_key properties.
|
|
65
|
-
|
|
66
|
-
**speaker** (`string`): Default voice ID to use for text-to-speech (Default: `'en-US-Casual-K'`)
|
|
67
|
-
|
|
68
|
-
**vertexAI** (`boolean`): Enable Vertex AI mode for enterprise deployments. Uses project-based authentication instead of API keys. Requires 'project' to be set. (Default: `false`)
|
|
69
|
-
|
|
70
|
-
**project** (`string`): Google Cloud project ID (required when vertexAI is true). Falls back to GOOGLE\_CLOUD\_PROJECT environment variable.
|
|
71
|
-
|
|
72
|
-
**location** (`string`): Google Cloud region for Vertex AI. Falls back to GOOGLE\_CLOUD\_LOCATION environment variable. (Default: `'us-central1'`)
|
|
73
|
-
|
|
74
|
-
## Methods
|
|
75
|
-
|
|
76
|
-
### `speak()`
|
|
77
|
-
|
|
78
|
-
Converts text to speech using Google Cloud Text-to-Speech service.
|
|
79
|
-
|
|
80
|
-
**input** (`string | NodeJS.ReadableStream`): Text to convert to speech. If a stream is provided, it will be converted to text first.
|
|
81
|
-
|
|
82
|
-
**options** (`object`): Speech synthesis options
|
|
83
|
-
|
|
84
|
-
**options.speaker** (`string`): Voice ID to use for this request.
|
|
85
|
-
|
|
86
|
-
**options.languageCode** (`string`): Language code for the voice (e.g., 'en-US'). Defaults to the language code derived from the speaker ID, or 'en-US'.
|
|
87
|
-
|
|
88
|
-
**options.input** (`ISynthesizeSpeechRequest['input']`): Rich input object passed through to the Google Cloud TTS API. Supports ssml, markup, prompt (Gemini-TTS style steering), customPronunciations, and multiSpeakerMarkup. When provided without text, ssml, markup, or multiSpeakerMarkup, the positional input argument is used as the text field automatically.
|
|
89
|
-
|
|
90
|
-
**options.voice** (`ISynthesizeSpeechRequest['voice']`): Voice configuration merged on top of defaults (name and languageCode). Supports modelName (e.g., 'gemini-2.5-flash-preview-tts') and multiSpeakerVoiceConfig.
|
|
91
|
-
|
|
92
|
-
**options.audioConfig** (`ISynthesizeSpeechRequest['audioConfig']`): Audio configuration options from Google Cloud Text-to-Speech API.
|
|
93
|
-
|
|
94
|
-
Returns: `Promise<NodeJS.ReadableStream>`
|
|
95
|
-
|
|
96
|
-
### `listen()`
|
|
97
|
-
|
|
98
|
-
Converts speech to text using Google Cloud Speech-to-Text service. Supports both v1 (default) and v2 APIs. The v2 API adds support for AAC-in-MP4 audio (iOS Safari) via auto-decoding.
|
|
99
|
-
|
|
100
|
-
#### v1 (default)
|
|
101
|
-
|
|
102
|
-
**audioStream** (`NodeJS.ReadableStream`): Audio stream to transcribe
|
|
103
|
-
|
|
104
|
-
**options** (`GoogleListenOptionsV1`): v1 recognition options
|
|
105
|
-
|
|
106
|
-
**options.config** (`IRecognitionConfig`): v1 recognition configuration from Google Cloud Speech-to-Text API
|
|
107
|
-
|
|
108
|
-
#### v2
|
|
109
|
-
|
|
110
|
-
Pass `v2: true` to use the Cloud Speech-to-Text v2 API, which supports additional audio formats like AAC-in-MP4 (iOS Safari).
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
const transcript = await voice.listen(iosSafariAacStream, {
|
|
114
|
-
v2: true,
|
|
115
|
-
config: {
|
|
116
|
-
autoDecodingConfig: {},
|
|
117
|
-
},
|
|
118
|
-
})
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
**audioStream** (`NodeJS.ReadableStream`): Audio stream to transcribe
|
|
122
|
-
|
|
123
|
-
**options** (`GoogleListenOptionsV2`): v2 recognition options
|
|
124
|
-
|
|
125
|
-
**options.v2** (`true`): Enables the v2 API path
|
|
126
|
-
|
|
127
|
-
**options.config** (`v2.IRecognitionConfig`): v2 recognition configuration. Defaults to auto-decoding with languageCodes: \['en-US'] and model: 'long'. Set autoDecodingConfig: {} to auto-detect the audio format, or use explicitDecodingConfig to specify an encoding like MP4\_AAC, M4A\_AAC, or MOV\_AAC.
|
|
128
|
-
|
|
129
|
-
**options.recognizer** (`string`): v2 recognizer resource path. Defaults to projects/{project}/locations/global/recognizers/\_ where {project} is resolved from the constructor project option, GOOGLE\_CLOUD\_PROJECT, or the client's default project.
|
|
130
|
-
|
|
131
|
-
Returns: `Promise<string>`
|
|
132
|
-
|
|
133
|
-
### `getSpeakers()`
|
|
134
|
-
|
|
135
|
-
Returns an array of available voice options, where each node contains:
|
|
136
|
-
|
|
137
|
-
**voiceId** (`string`): Unique identifier for the voice
|
|
138
|
-
|
|
139
|
-
**languageCodes** (`string[]`): List of language codes supported by this voice
|
|
140
|
-
|
|
141
|
-
### `isUsingVertexAI()`
|
|
142
|
-
|
|
143
|
-
Checks if Vertex AI mode is enabled.
|
|
144
|
-
|
|
145
|
-
Returns: `boolean` - `true` if using Vertex AI, `false` otherwise
|
|
146
|
-
|
|
147
|
-
### `getProject()`
|
|
148
|
-
|
|
149
|
-
Gets the configured Google Cloud project ID.
|
|
150
|
-
|
|
151
|
-
Returns: `string | undefined` - The project ID or `undefined` if not set
|
|
152
|
-
|
|
153
|
-
### `getLocation()`
|
|
154
|
-
|
|
155
|
-
Gets the configured Google Cloud location/region.
|
|
156
|
-
|
|
157
|
-
Returns: `string` - The location (default: `'us-central1'`)
|
|
158
|
-
|
|
159
|
-
## Authentication
|
|
160
|
-
|
|
161
|
-
The Google Voice provider supports two authentication methods:
|
|
162
|
-
|
|
163
|
-
### Standard Mode (API Key)
|
|
164
|
-
|
|
165
|
-
Uses a Google Cloud API key for authentication. Suitable for development and basic use cases.
|
|
166
|
-
|
|
167
|
-
```typescript
|
|
168
|
-
// Using environment variable (GOOGLE_API_KEY)
|
|
169
|
-
const voice = new GoogleVoice()
|
|
170
|
-
|
|
171
|
-
// Using explicit API key
|
|
172
|
-
const voice = new GoogleVoice({
|
|
173
|
-
speechModel: { apiKey: 'your-api-key' },
|
|
174
|
-
listeningModel: { apiKey: 'your-api-key' },
|
|
175
|
-
speaker: 'en-US-Casual-K',
|
|
176
|
-
})
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
### Vertex AI Mode (Service Account)
|
|
180
|
-
|
|
181
|
-
Uses Google Cloud project-based authentication with service accounts. Recommended for production and enterprise deployments.
|
|
182
|
-
|
|
183
|
-
**Benefits:**
|
|
184
|
-
|
|
185
|
-
- Better security (no API keys in code)
|
|
186
|
-
- IAM-based access control
|
|
187
|
-
- Project-level billing and quotas
|
|
188
|
-
- Audit logging
|
|
189
|
-
- Enterprise features
|
|
190
|
-
|
|
191
|
-
**Configuration Options:**
|
|
192
|
-
|
|
193
|
-
```typescript
|
|
194
|
-
// Using Application Default Credentials (ADC)
|
|
195
|
-
// Set GOOGLE_APPLICATION_CREDENTIALS and GOOGLE_CLOUD_PROJECT env vars
|
|
196
|
-
const voice = new GoogleVoice({
|
|
197
|
-
vertexAI: true,
|
|
198
|
-
project: 'your-gcp-project',
|
|
199
|
-
location: 'us-central1', // Optional, defaults to 'us-central1'
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
// Using service account key file
|
|
203
|
-
const voice = new GoogleVoice({
|
|
204
|
-
vertexAI: true,
|
|
205
|
-
project: 'your-gcp-project',
|
|
206
|
-
speechModel: {
|
|
207
|
-
keyFilename: '/path/to/service-account.json',
|
|
208
|
-
},
|
|
209
|
-
listeningModel: {
|
|
210
|
-
keyFilename: '/path/to/service-account.json',
|
|
211
|
-
},
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
// Using in-memory credentials
|
|
215
|
-
const voice = new GoogleVoice({
|
|
216
|
-
vertexAI: true,
|
|
217
|
-
project: 'your-gcp-project',
|
|
218
|
-
speechModel: {
|
|
219
|
-
credentials: {
|
|
220
|
-
client_email: 'service-account@project.iam.gserviceaccount.com',
|
|
221
|
-
private_key: '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----',
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
})
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
#### Required Permissions
|
|
228
|
-
|
|
229
|
-
#### IAM Roles
|
|
230
|
-
|
|
231
|
-
For Text-to-Speech:
|
|
232
|
-
|
|
233
|
-
- `roles/texttospeech.admin` - Text-to-Speech Admin (full access)
|
|
234
|
-
- `roles/texttospeech.editor` - Text-to-Speech Editor (create and manage)
|
|
235
|
-
- `roles/texttospeech.viewer` - Text-to-Speech Viewer (read-only)
|
|
236
|
-
|
|
237
|
-
For Speech-to-Text:
|
|
238
|
-
|
|
239
|
-
- `roles/speech.client` - Speech-to-Text Client
|
|
240
|
-
|
|
241
|
-
#### OAuth Scopes
|
|
242
|
-
|
|
243
|
-
For synchronous Text-to-Speech synthesis:
|
|
244
|
-
|
|
245
|
-
- `https://www.googleapis.com/auth/cloud-platform` - Full access to Google Cloud Platform services
|
|
246
|
-
|
|
247
|
-
For long-audio Text-to-Speech operations:
|
|
248
|
-
|
|
249
|
-
- `locations.longAudioSynthesize` - Create long-audio synthesis operations
|
|
250
|
-
- `operations.get` - Get operation status
|
|
251
|
-
- `operations.list` - List operations
|
|
252
|
-
|
|
253
|
-
## Important notes
|
|
254
|
-
|
|
255
|
-
1. **Authentication**: Either a Google Cloud API key (standard mode) or service account credentials (Vertex AI mode) is required.
|
|
256
|
-
|
|
257
|
-
2. **Environment Variables**:
|
|
258
|
-
|
|
259
|
-
- `GOOGLE_API_KEY` - API key for standard mode
|
|
260
|
-
- `GOOGLE_CLOUD_PROJECT` - Project ID for Vertex AI mode
|
|
261
|
-
- `GOOGLE_CLOUD_LOCATION` - Location for Vertex AI mode (defaults to 'us-central1')
|
|
262
|
-
- `GOOGLE_APPLICATION_CREDENTIALS` - Path to service account key file
|
|
263
|
-
|
|
264
|
-
3. The default voice is set to `'en-US-Casual-K'`.
|
|
265
|
-
|
|
266
|
-
4. Both text-to-speech and speech-to-text services use LINEAR16 as the default audio encoding.
|
|
267
|
-
|
|
268
|
-
5. The `speak()` method supports advanced audio configuration through the Google Cloud Text-to-Speech API.
|
|
269
|
-
|
|
270
|
-
6. The `listen()` method supports various recognition configurations through the Google Cloud Speech-to-Text API.
|
|
271
|
-
|
|
272
|
-
7. Available voices can be filtered by language code using the `getSpeakers()` method.
|
|
273
|
-
|
|
274
|
-
8. Vertex AI mode provides enterprise features including IAM control, audit logs, and project-level billing.
|