@mastra/voice-google 0.1.3-alpha.8 → 0.1.3
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/dist/index.cjs +10 -2
- package/dist/index.js +10 -2
- package/package.json +15 -12
- package/.turbo/turbo-build.log +0 -23
- package/CHANGELOG.md +0 -227
- package/eslint.config.js +0 -6
- package/src/index.test.ts +0 -133
- package/src/index.ts +0 -199
- package/tsconfig.json +0 -5
- package/vitest.config.ts +0 -8
package/dist/index.cjs
CHANGED
|
@@ -65,7 +65,11 @@ var GoogleVoice = class extends voice.MastraVoice {
|
|
|
65
65
|
async streamToString(stream) {
|
|
66
66
|
const chunks = [];
|
|
67
67
|
for await (const chunk of stream) {
|
|
68
|
-
|
|
68
|
+
if (typeof chunk === "string") {
|
|
69
|
+
chunks.push(Buffer.from(chunk));
|
|
70
|
+
} else {
|
|
71
|
+
chunks.push(chunk);
|
|
72
|
+
}
|
|
69
73
|
}
|
|
70
74
|
return Buffer.concat(chunks).toString("utf-8");
|
|
71
75
|
}
|
|
@@ -112,7 +116,11 @@ var GoogleVoice = class extends voice.MastraVoice {
|
|
|
112
116
|
return this.traced(async () => {
|
|
113
117
|
const chunks = [];
|
|
114
118
|
for await (const chunk of audioStream) {
|
|
115
|
-
|
|
119
|
+
if (typeof chunk === "string") {
|
|
120
|
+
chunks.push(Buffer.from(chunk));
|
|
121
|
+
} else {
|
|
122
|
+
chunks.push(chunk);
|
|
123
|
+
}
|
|
116
124
|
}
|
|
117
125
|
const buffer = Buffer.concat(chunks);
|
|
118
126
|
let request = {
|
package/dist/index.js
CHANGED
|
@@ -63,7 +63,11 @@ var GoogleVoice = class extends MastraVoice {
|
|
|
63
63
|
async streamToString(stream) {
|
|
64
64
|
const chunks = [];
|
|
65
65
|
for await (const chunk of stream) {
|
|
66
|
-
|
|
66
|
+
if (typeof chunk === "string") {
|
|
67
|
+
chunks.push(Buffer.from(chunk));
|
|
68
|
+
} else {
|
|
69
|
+
chunks.push(chunk);
|
|
70
|
+
}
|
|
67
71
|
}
|
|
68
72
|
return Buffer.concat(chunks).toString("utf-8");
|
|
69
73
|
}
|
|
@@ -110,7 +114,11 @@ var GoogleVoice = class extends MastraVoice {
|
|
|
110
114
|
return this.traced(async () => {
|
|
111
115
|
const chunks = [];
|
|
112
116
|
for await (const chunk of audioStream) {
|
|
113
|
-
|
|
117
|
+
if (typeof chunk === "string") {
|
|
118
|
+
chunks.push(Buffer.from(chunk));
|
|
119
|
+
} else {
|
|
120
|
+
chunks.push(chunk);
|
|
121
|
+
}
|
|
114
122
|
}
|
|
115
123
|
const buffer = Buffer.concat(chunks);
|
|
116
124
|
let request = {
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/voice-google",
|
|
3
|
-
"version": "0.1.3
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Mastra Google voice integration",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
6
9
|
"main": "dist/index.js",
|
|
7
10
|
"types": "dist/index.d.ts",
|
|
8
11
|
"exports": {
|
|
@@ -19,21 +22,21 @@
|
|
|
19
22
|
"./package.json": "./package.json"
|
|
20
23
|
},
|
|
21
24
|
"dependencies": {
|
|
22
|
-
"@google-cloud/speech": "^6.7.
|
|
23
|
-
"@google-cloud/text-to-speech": "^5.
|
|
24
|
-
"zod": "^3.24.
|
|
25
|
-
"@mastra/core": "^0.5.0
|
|
25
|
+
"@google-cloud/speech": "^6.7.1",
|
|
26
|
+
"@google-cloud/text-to-speech": "^5.8.1",
|
|
27
|
+
"zod": "^3.24.2",
|
|
28
|
+
"@mastra/core": "^0.5.0"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
|
-
"@types/node": "^22.13.
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"@internal/lint": "0.0.
|
|
31
|
+
"@types/node": "^22.13.10",
|
|
32
|
+
"eslint": "^9.22.0",
|
|
33
|
+
"tsup": "^8.4.0",
|
|
34
|
+
"typescript": "^5.8.2",
|
|
35
|
+
"vitest": "^2.1.9",
|
|
36
|
+
"@internal/lint": "0.0.1"
|
|
34
37
|
},
|
|
35
38
|
"scripts": {
|
|
36
|
-
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake",
|
|
39
|
+
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
|
37
40
|
"build:watch": "pnpm build --watch",
|
|
38
41
|
"test": "vitest run",
|
|
39
42
|
"lint": "eslint ."
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @mastra/voice-google@0.1.3-alpha.8 build /home/runner/work/mastra/mastra/voice/google
|
|
3
|
-
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake
|
|
4
|
-
|
|
5
|
-
[34mCLI[39m Building entry: src/index.ts
|
|
6
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
-
[34mCLI[39m tsup v8.3.6
|
|
8
|
-
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in 12454ms
|
|
10
|
-
[34mDTS[39m Build start
|
|
11
|
-
[34mCLI[39m Target: es2022
|
|
12
|
-
Analysis will use the bundled TypeScript version 5.7.3
|
|
13
|
-
[36mWriting package typings: /home/runner/work/mastra/mastra/voice/google/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
|
-
Analysis will use the bundled TypeScript version 5.7.3
|
|
15
|
-
[36mWriting package typings: /home/runner/work/mastra/mastra/voice/google/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in 15142ms
|
|
17
|
-
[34mCLI[39m Cleaning output folder
|
|
18
|
-
[34mESM[39m Build start
|
|
19
|
-
[34mCJS[39m Build start
|
|
20
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m5.48 KB[39m
|
|
21
|
-
[32mCJS[39m ⚡️ Build success in 681ms
|
|
22
|
-
[32mESM[39m [1mdist/index.js [22m[32m5.45 KB[39m
|
|
23
|
-
[32mESM[39m ⚡️ Build success in 684ms
|
package/CHANGELOG.md
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
# @mastra/voice-google
|
|
2
|
-
|
|
3
|
-
## 0.1.3-alpha.8
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- Updated dependencies [506f1d5]
|
|
8
|
-
- @mastra/core@0.5.0-alpha.8
|
|
9
|
-
|
|
10
|
-
## 0.1.3-alpha.7
|
|
11
|
-
|
|
12
|
-
### Patch Changes
|
|
13
|
-
|
|
14
|
-
- Updated dependencies [ee667a2]
|
|
15
|
-
- @mastra/core@0.5.0-alpha.7
|
|
16
|
-
|
|
17
|
-
## 0.1.3-alpha.6
|
|
18
|
-
|
|
19
|
-
### Patch Changes
|
|
20
|
-
|
|
21
|
-
- Updated dependencies [f6678e4]
|
|
22
|
-
- @mastra/core@0.5.0-alpha.6
|
|
23
|
-
|
|
24
|
-
## 0.1.3-alpha.5
|
|
25
|
-
|
|
26
|
-
### Patch Changes
|
|
27
|
-
|
|
28
|
-
- Updated dependencies [22643eb]
|
|
29
|
-
- Updated dependencies [6feb23f]
|
|
30
|
-
- Updated dependencies [f2d6727]
|
|
31
|
-
- Updated dependencies [301e4ee]
|
|
32
|
-
- Updated dependencies [dfbe4e9]
|
|
33
|
-
- Updated dependencies [9e81f35]
|
|
34
|
-
- Updated dependencies [caefaa2]
|
|
35
|
-
- Updated dependencies [c151ae6]
|
|
36
|
-
- Updated dependencies [52e0418]
|
|
37
|
-
- Updated dependencies [03236ec]
|
|
38
|
-
- Updated dependencies [3764e71]
|
|
39
|
-
- Updated dependencies [df982db]
|
|
40
|
-
- Updated dependencies [0461849]
|
|
41
|
-
- Updated dependencies [2259379]
|
|
42
|
-
- Updated dependencies [358f069]
|
|
43
|
-
- @mastra/core@0.5.0-alpha.5
|
|
44
|
-
|
|
45
|
-
## 0.1.3-alpha.4
|
|
46
|
-
|
|
47
|
-
### Patch Changes
|
|
48
|
-
|
|
49
|
-
- Updated dependencies [d79aedf]
|
|
50
|
-
- @mastra/core@0.5.0-alpha.4
|
|
51
|
-
|
|
52
|
-
## 0.1.3-alpha.3
|
|
53
|
-
|
|
54
|
-
### Patch Changes
|
|
55
|
-
|
|
56
|
-
- Updated dependencies [3d0e290]
|
|
57
|
-
- @mastra/core@0.5.0-alpha.3
|
|
58
|
-
|
|
59
|
-
## 0.1.3-alpha.2
|
|
60
|
-
|
|
61
|
-
### Patch Changes
|
|
62
|
-
|
|
63
|
-
- Updated dependencies [02ffb7b]
|
|
64
|
-
- @mastra/core@0.5.0-alpha.2
|
|
65
|
-
|
|
66
|
-
## 0.1.3-alpha.1
|
|
67
|
-
|
|
68
|
-
### Patch Changes
|
|
69
|
-
|
|
70
|
-
- Updated dependencies [dab255b]
|
|
71
|
-
- @mastra/core@0.5.0-alpha.1
|
|
72
|
-
|
|
73
|
-
## 0.1.3-alpha.0
|
|
74
|
-
|
|
75
|
-
### Patch Changes
|
|
76
|
-
|
|
77
|
-
- Updated dependencies [59df7b6]
|
|
78
|
-
- Updated dependencies [29f3a82]
|
|
79
|
-
- Updated dependencies [59df7b6]
|
|
80
|
-
- Updated dependencies [c139344]
|
|
81
|
-
- @mastra/core@0.5.0-alpha.0
|
|
82
|
-
|
|
83
|
-
## 0.1.2
|
|
84
|
-
|
|
85
|
-
### Patch Changes
|
|
86
|
-
|
|
87
|
-
- Updated dependencies [1da20e7]
|
|
88
|
-
- @mastra/core@0.4.4
|
|
89
|
-
|
|
90
|
-
## 0.1.2-alpha.0
|
|
91
|
-
|
|
92
|
-
### Patch Changes
|
|
93
|
-
|
|
94
|
-
- Updated dependencies [1da20e7]
|
|
95
|
-
- @mastra/core@0.4.4-alpha.0
|
|
96
|
-
|
|
97
|
-
## 0.1.1
|
|
98
|
-
|
|
99
|
-
### Patch Changes
|
|
100
|
-
|
|
101
|
-
- bb4f447: Add support for commonjs
|
|
102
|
-
- Updated dependencies [0d185b1]
|
|
103
|
-
- Updated dependencies [ed55f1d]
|
|
104
|
-
- Updated dependencies [06aa827]
|
|
105
|
-
- Updated dependencies [0fd78ac]
|
|
106
|
-
- Updated dependencies [2512a93]
|
|
107
|
-
- Updated dependencies [e62de74]
|
|
108
|
-
- Updated dependencies [0d25b75]
|
|
109
|
-
- Updated dependencies [fd14a3f]
|
|
110
|
-
- Updated dependencies [8d13b14]
|
|
111
|
-
- Updated dependencies [3f369a2]
|
|
112
|
-
- Updated dependencies [3ee4831]
|
|
113
|
-
- Updated dependencies [4d4e1e1]
|
|
114
|
-
- Updated dependencies [bb4f447]
|
|
115
|
-
- Updated dependencies [108793c]
|
|
116
|
-
- Updated dependencies [5f28f44]
|
|
117
|
-
- Updated dependencies [dabecf4]
|
|
118
|
-
- @mastra/core@0.4.3
|
|
119
|
-
|
|
120
|
-
## 0.1.1-alpha.4
|
|
121
|
-
|
|
122
|
-
### Patch Changes
|
|
123
|
-
|
|
124
|
-
- Updated dependencies [dabecf4]
|
|
125
|
-
- @mastra/core@0.4.3-alpha.4
|
|
126
|
-
|
|
127
|
-
## 0.1.1-alpha.3
|
|
128
|
-
|
|
129
|
-
### Patch Changes
|
|
130
|
-
|
|
131
|
-
- bb4f447: Add support for commonjs
|
|
132
|
-
- Updated dependencies [0fd78ac]
|
|
133
|
-
- Updated dependencies [0d25b75]
|
|
134
|
-
- Updated dependencies [fd14a3f]
|
|
135
|
-
- Updated dependencies [3f369a2]
|
|
136
|
-
- Updated dependencies [4d4e1e1]
|
|
137
|
-
- Updated dependencies [bb4f447]
|
|
138
|
-
- @mastra/core@0.4.3-alpha.3
|
|
139
|
-
|
|
140
|
-
## 0.1.1-alpha.2
|
|
141
|
-
|
|
142
|
-
### Patch Changes
|
|
143
|
-
|
|
144
|
-
- Updated dependencies [2512a93]
|
|
145
|
-
- Updated dependencies [e62de74]
|
|
146
|
-
- @mastra/core@0.4.3-alpha.2
|
|
147
|
-
|
|
148
|
-
## 0.1.1-alpha.1
|
|
149
|
-
|
|
150
|
-
### Patch Changes
|
|
151
|
-
|
|
152
|
-
- Updated dependencies [0d185b1]
|
|
153
|
-
- Updated dependencies [ed55f1d]
|
|
154
|
-
- Updated dependencies [8d13b14]
|
|
155
|
-
- Updated dependencies [3ee4831]
|
|
156
|
-
- Updated dependencies [108793c]
|
|
157
|
-
- Updated dependencies [5f28f44]
|
|
158
|
-
- @mastra/core@0.4.3-alpha.1
|
|
159
|
-
|
|
160
|
-
## 0.1.1-alpha.0
|
|
161
|
-
|
|
162
|
-
### Patch Changes
|
|
163
|
-
|
|
164
|
-
- Updated dependencies [06aa827]
|
|
165
|
-
- @mastra/core@0.4.3-alpha.0
|
|
166
|
-
|
|
167
|
-
## 0.1.0
|
|
168
|
-
|
|
169
|
-
### Patch Changes
|
|
170
|
-
|
|
171
|
-
- 5e0f727: deprecate @mastra/speech-google for @mastra/voice-google
|
|
172
|
-
- Updated dependencies [7fceae1]
|
|
173
|
-
- Updated dependencies [8d94c3e]
|
|
174
|
-
- Updated dependencies [99dcdb5]
|
|
175
|
-
- Updated dependencies [6cb63e0]
|
|
176
|
-
- Updated dependencies [f626fbb]
|
|
177
|
-
- Updated dependencies [e752340]
|
|
178
|
-
- Updated dependencies [eb91535]
|
|
179
|
-
- @mastra/core@0.4.2
|
|
180
|
-
|
|
181
|
-
## 0.1.0-alpha.4
|
|
182
|
-
|
|
183
|
-
### Patch Changes
|
|
184
|
-
|
|
185
|
-
- Updated dependencies [8d94c3e]
|
|
186
|
-
- Updated dependencies [99dcdb5]
|
|
187
|
-
- Updated dependencies [e752340]
|
|
188
|
-
- Updated dependencies [eb91535]
|
|
189
|
-
- @mastra/core@0.4.2-alpha.2
|
|
190
|
-
|
|
191
|
-
## 0.1.0-alpha.3
|
|
192
|
-
|
|
193
|
-
### Patch Changes
|
|
194
|
-
|
|
195
|
-
- Updated dependencies [6cb63e0]
|
|
196
|
-
- @mastra/core@0.4.2-alpha.1
|
|
197
|
-
|
|
198
|
-
## 0.1.0-alpha.2
|
|
199
|
-
|
|
200
|
-
### Patch Changes
|
|
201
|
-
|
|
202
|
-
- 5e0f727: deprecate @mastra/speech-google for @mastra/voice-google
|
|
203
|
-
|
|
204
|
-
## 0.1.0
|
|
205
|
-
|
|
206
|
-
### Minor Changes
|
|
207
|
-
|
|
208
|
-
- Initial release of @mastra/voice-google
|
|
209
|
-
- Combines functionality from deprecated @mastra/speech-google
|
|
210
|
-
- Adds Speech-to-Text capabilities
|
|
211
|
-
- Implements new MastraVoice interface from @mastra/core
|
|
212
|
-
|
|
213
|
-
### Notes
|
|
214
|
-
|
|
215
|
-
This package replaces @mastra/speech-google, which reached version 0.1.3-alpha.1. Key features from the previous package:
|
|
216
|
-
|
|
217
|
-
- Neural Text-to-Speech synthesis
|
|
218
|
-
- Multiple voice options
|
|
219
|
-
- Streaming support
|
|
220
|
-
- Integration with Google Cloud services
|
|
221
|
-
|
|
222
|
-
The new package adds:
|
|
223
|
-
|
|
224
|
-
- Speech-to-Text recognition
|
|
225
|
-
- Combined speech and listening models
|
|
226
|
-
- Improved voice management
|
|
227
|
-
- Better type safety and error handling
|
package/eslint.config.js
DELETED
package/src/index.test.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { createWriteStream, mkdirSync, readFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { Readable } from 'node:stream';
|
|
4
|
-
import { describe, expect, it, beforeAll } from 'vitest';
|
|
5
|
-
|
|
6
|
-
import { GoogleVoice } from './index';
|
|
7
|
-
|
|
8
|
-
describe('GoogleVoice Integration Tests', () => {
|
|
9
|
-
let voice: GoogleVoice;
|
|
10
|
-
const outputDir = join(process.cwd(), 'test-outputs');
|
|
11
|
-
|
|
12
|
-
beforeAll(() => {
|
|
13
|
-
// Create output directory if it doesn't exist
|
|
14
|
-
try {
|
|
15
|
-
mkdirSync(outputDir, { recursive: true });
|
|
16
|
-
} catch (err) {
|
|
17
|
-
console.error(err);
|
|
18
|
-
// Ignore if directory already exists
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
voice = new GoogleVoice();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe('getSpeakers', () => {
|
|
25
|
-
it('should list available voices', async () => {
|
|
26
|
-
const voices = await voice.getSpeakers();
|
|
27
|
-
expect(voices.length).toBeGreaterThan(0);
|
|
28
|
-
expect(voices[0]).toHaveProperty('voiceId');
|
|
29
|
-
expect(voices[0]).toHaveProperty('languageCodes');
|
|
30
|
-
}, 10000);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
describe('speak', () => {
|
|
34
|
-
it('should generate audio from text and save to file', async () => {
|
|
35
|
-
const audioStream = await voice.speak('Hello World', {
|
|
36
|
-
speaker: 'en-US-Standard-F',
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
const outputPath = join(outputDir, 'speech-test.wav');
|
|
41
|
-
const fileStream = createWriteStream(outputPath);
|
|
42
|
-
const chunks: Buffer[] = [];
|
|
43
|
-
|
|
44
|
-
audioStream.on('data', (chunk: Buffer) => chunks.push(chunk));
|
|
45
|
-
audioStream.pipe(fileStream);
|
|
46
|
-
|
|
47
|
-
fileStream.on('finish', () => {
|
|
48
|
-
expect(chunks.length).toBeGreaterThan(0);
|
|
49
|
-
resolve(undefined);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
audioStream.on('error', reject);
|
|
53
|
-
fileStream.on('error', reject);
|
|
54
|
-
});
|
|
55
|
-
}, 10000);
|
|
56
|
-
|
|
57
|
-
it('should work with default voice', async () => {
|
|
58
|
-
const audioStream = await voice.speak('Test with default voice');
|
|
59
|
-
|
|
60
|
-
return new Promise((resolve, reject) => {
|
|
61
|
-
const outputPath = join(outputDir, 'speech-test-default.wav');
|
|
62
|
-
const fileStream = createWriteStream(outputPath);
|
|
63
|
-
const chunks: Buffer[] = [];
|
|
64
|
-
|
|
65
|
-
audioStream.on('data', (chunk: Buffer) => chunks.push(chunk));
|
|
66
|
-
audioStream.pipe(fileStream);
|
|
67
|
-
|
|
68
|
-
fileStream.on('finish', () => {
|
|
69
|
-
expect(chunks.length).toBeGreaterThan(0);
|
|
70
|
-
resolve(undefined);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
audioStream.on('error', reject);
|
|
74
|
-
fileStream.on('error', reject);
|
|
75
|
-
});
|
|
76
|
-
}, 10000);
|
|
77
|
-
|
|
78
|
-
it('should handle stream input', async () => {
|
|
79
|
-
const textStream = Readable.from(['Hello', ' from', ' stream', ' input!']);
|
|
80
|
-
|
|
81
|
-
const audioStream = await voice.speak(textStream);
|
|
82
|
-
|
|
83
|
-
return new Promise((resolve, reject) => {
|
|
84
|
-
const outputPath = join(outputDir, 'speech-stream-input-test.wav');
|
|
85
|
-
const fileStream = createWriteStream(outputPath);
|
|
86
|
-
const chunks: Buffer[] = [];
|
|
87
|
-
|
|
88
|
-
audioStream.on('data', (chunk: Buffer) => chunks.push(chunk));
|
|
89
|
-
audioStream.pipe(fileStream);
|
|
90
|
-
|
|
91
|
-
fileStream.on('finish', () => {
|
|
92
|
-
expect(chunks.length).toBeGreaterThan(0);
|
|
93
|
-
resolve(undefined);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
audioStream.on('error', reject);
|
|
97
|
-
fileStream.on('error', reject);
|
|
98
|
-
});
|
|
99
|
-
}, 10000);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe('listen', () => {
|
|
103
|
-
it('should transcribe audio stream to text', async () => {
|
|
104
|
-
const audioStream = Readable.from(readFileSync(join(outputDir, 'speech-test.wav')));
|
|
105
|
-
|
|
106
|
-
const result = await voice.listen(audioStream);
|
|
107
|
-
console.log(result);
|
|
108
|
-
expect(typeof result).toBe('string');
|
|
109
|
-
expect(result).toContain('hello world');
|
|
110
|
-
}, 10000);
|
|
111
|
-
|
|
112
|
-
// it('should support streaming transcription', async () => {
|
|
113
|
-
// const audioStream = Readable.from(
|
|
114
|
-
// readFileSync(join(outputDir, 'speech-test.mp3'))
|
|
115
|
-
// );
|
|
116
|
-
|
|
117
|
-
// const outputStream = await voice.listen(audioStream, { stream: true });
|
|
118
|
-
// expect(outputStream).toBeInstanceOf(PassThrough);
|
|
119
|
-
|
|
120
|
-
// return new Promise((resolve, reject) => {
|
|
121
|
-
// const chunks: string[] = [];
|
|
122
|
-
// (outputStream as PassThrough).on('data', (chunk: string) => chunks.push(chunk));
|
|
123
|
-
// (outputStream as PassThrough).on('end', () => {
|
|
124
|
-
// expect(chunks.length).toBeGreaterThan(0);
|
|
125
|
-
// const transcription = chunks.join('');
|
|
126
|
-
// expect(transcription).toContain('hello world');
|
|
127
|
-
// resolve(undefined);
|
|
128
|
-
// });
|
|
129
|
-
// (outputStream as PassThrough).on('error', reject);
|
|
130
|
-
// });
|
|
131
|
-
// });
|
|
132
|
-
});
|
|
133
|
-
});
|
package/src/index.ts
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { PassThrough } from 'stream';
|
|
2
|
-
|
|
3
|
-
import { SpeechClient } from '@google-cloud/speech';
|
|
4
|
-
import type { google as SpeechTypes } from '@google-cloud/speech/build/protos/protos';
|
|
5
|
-
import { TextToSpeechClient } from '@google-cloud/text-to-speech';
|
|
6
|
-
import type { google as TextToSpeechTypes } from '@google-cloud/text-to-speech/build/protos/protos';
|
|
7
|
-
import { MastraVoice } from '@mastra/core/voice';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Configuration for Google Cloud Voice models
|
|
11
|
-
* @interface GoogleModelConfig
|
|
12
|
-
* @property {string} [apiKey] - Optional Google Cloud API key. If not provided, will use GOOGLE_API_KEY environment variable
|
|
13
|
-
*/
|
|
14
|
-
export interface GoogleModelConfig {
|
|
15
|
-
apiKey?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const DEFAULT_VOICE = 'en-US-Casual-K';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* GoogleVoice class provides Text-to-Speech and Speech-to-Text capabilities using Google Cloud services
|
|
22
|
-
* @class GoogleVoice
|
|
23
|
-
* @extends MastraVoice
|
|
24
|
-
*/
|
|
25
|
-
export class GoogleVoice extends MastraVoice {
|
|
26
|
-
private ttsClient: TextToSpeechClient;
|
|
27
|
-
private speechClient: SpeechClient;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Creates an instance of GoogleVoice
|
|
31
|
-
* @param {Object} config - Configuration options
|
|
32
|
-
* @param {GoogleModelConfig} [config.speechModel] - Configuration for speech synthesis
|
|
33
|
-
* @param {GoogleModelConfig} [config.listeningModel] - Configuration for speech recognition
|
|
34
|
-
* @param {string} [config.speaker] - Default voice ID to use for speech synthesis
|
|
35
|
-
* @throws {Error} If no API key is provided via config or environment variable
|
|
36
|
-
*/
|
|
37
|
-
constructor({
|
|
38
|
-
listeningModel,
|
|
39
|
-
speechModel,
|
|
40
|
-
speaker,
|
|
41
|
-
}: {
|
|
42
|
-
listeningModel?: GoogleModelConfig;
|
|
43
|
-
speechModel?: GoogleModelConfig;
|
|
44
|
-
speaker?: string;
|
|
45
|
-
} = {}) {
|
|
46
|
-
const defaultApiKey = process.env.GOOGLE_API_KEY;
|
|
47
|
-
const defaultSpeaker = DEFAULT_VOICE;
|
|
48
|
-
|
|
49
|
-
super({
|
|
50
|
-
speechModel: {
|
|
51
|
-
name: '',
|
|
52
|
-
apiKey: speechModel?.apiKey ?? defaultApiKey,
|
|
53
|
-
},
|
|
54
|
-
listeningModel: {
|
|
55
|
-
name: '',
|
|
56
|
-
apiKey: listeningModel?.apiKey ?? defaultApiKey,
|
|
57
|
-
},
|
|
58
|
-
speaker: speaker ?? defaultSpeaker,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const apiKey = defaultApiKey || speechModel?.apiKey || listeningModel?.apiKey;
|
|
62
|
-
if (!apiKey) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
'Google API key is not set, set GOOGLE_API_KEY environment variable or pass apiKey to constructor',
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
this.ttsClient = new TextToSpeechClient({
|
|
69
|
-
apiKey: this.speechModel?.apiKey || defaultApiKey,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
this.speechClient = new SpeechClient({
|
|
73
|
-
apiKey: this.listeningModel?.apiKey || defaultApiKey,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Gets a list of available voices
|
|
79
|
-
* @returns {Promise<Array<{voiceId: string, languageCodes: string[]}>>} List of available voices and their supported languages. Default language is en-US.
|
|
80
|
-
*/
|
|
81
|
-
async getSpeakers({ languageCode = 'en-US' }: { languageCode?: string } = {}) {
|
|
82
|
-
return this.traced(async () => {
|
|
83
|
-
const [response] = await this.ttsClient.listVoices({ languageCode: languageCode });
|
|
84
|
-
return (response?.voices || [])
|
|
85
|
-
.filter(voice => voice.name && voice.languageCodes)
|
|
86
|
-
.map(voice => ({
|
|
87
|
-
voiceId: voice.name!,
|
|
88
|
-
languageCodes: voice.languageCodes!,
|
|
89
|
-
}));
|
|
90
|
-
}, 'voice.google.getSpeakers')();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private async streamToString(stream: NodeJS.ReadableStream): Promise<string> {
|
|
94
|
-
const chunks: Buffer[] = [];
|
|
95
|
-
for await (const chunk of stream) {
|
|
96
|
-
chunks.push(Buffer.from(chunk));
|
|
97
|
-
}
|
|
98
|
-
return Buffer.concat(chunks).toString('utf-8');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Converts text to speech
|
|
103
|
-
* @param {string | NodeJS.ReadableStream} input - Text or stream to convert to speech
|
|
104
|
-
* @param {Object} [options] - Speech synthesis options
|
|
105
|
-
* @param {string} [options.speaker] - Voice ID to use
|
|
106
|
-
* @param {string} [options.languageCode] - Language code for the voice
|
|
107
|
-
* @param {TextToSpeechTypes.cloud.texttospeech.v1.ISynthesizeSpeechRequest['audioConfig']} [options.audioConfig] - Audio configuration options
|
|
108
|
-
* @returns {Promise<NodeJS.ReadableStream>} Stream of synthesized audio. Default encoding is LINEAR16.
|
|
109
|
-
*/
|
|
110
|
-
async speak(
|
|
111
|
-
input: string | NodeJS.ReadableStream,
|
|
112
|
-
options?: {
|
|
113
|
-
speaker?: string;
|
|
114
|
-
languageCode?: string;
|
|
115
|
-
audioConfig?: TextToSpeechTypes.cloud.texttospeech.v1.ISynthesizeSpeechRequest['audioConfig'];
|
|
116
|
-
},
|
|
117
|
-
): Promise<NodeJS.ReadableStream> {
|
|
118
|
-
return this.traced(async () => {
|
|
119
|
-
const text = typeof input === 'string' ? input : await this.streamToString(input);
|
|
120
|
-
|
|
121
|
-
const request: TextToSpeechTypes.cloud.texttospeech.v1.ISynthesizeSpeechRequest = {
|
|
122
|
-
input: { text },
|
|
123
|
-
voice: {
|
|
124
|
-
name: options?.speaker || this.speaker,
|
|
125
|
-
languageCode: options?.languageCode || options?.speaker?.split('-').slice(0, 2).join('-') || 'en-US',
|
|
126
|
-
},
|
|
127
|
-
audioConfig: options?.audioConfig || { audioEncoding: 'LINEAR16' },
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const [response] = await this.ttsClient.synthesizeSpeech(request);
|
|
131
|
-
|
|
132
|
-
if (!response.audioContent) {
|
|
133
|
-
throw new Error('No audio content returned.');
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (typeof response.audioContent === 'string') {
|
|
137
|
-
throw new Error('Audio content is a string.');
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const stream = new PassThrough();
|
|
141
|
-
stream.end(Buffer.from(response.audioContent));
|
|
142
|
-
return stream;
|
|
143
|
-
}, 'voice.google.speak')();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Converts speech to text
|
|
148
|
-
* @param {NodeJS.ReadableStream} audioStream - Audio stream to transcribe. Default encoding is LINEAR16.
|
|
149
|
-
* @param {Object} [options] - Recognition options
|
|
150
|
-
* @param {SpeechTypes.cloud.speech.v1.IRecognitionConfig} [options.config] - Recognition configuration
|
|
151
|
-
* @returns {Promise<string>} Transcribed text
|
|
152
|
-
*/
|
|
153
|
-
async listen(
|
|
154
|
-
audioStream: NodeJS.ReadableStream,
|
|
155
|
-
options?: { stream?: boolean; config?: SpeechTypes.cloud.speech.v1.IRecognitionConfig },
|
|
156
|
-
): Promise<string> {
|
|
157
|
-
return this.traced(async () => {
|
|
158
|
-
const chunks: Buffer[] = [];
|
|
159
|
-
for await (const chunk of audioStream) {
|
|
160
|
-
chunks.push(Buffer.from(chunk));
|
|
161
|
-
}
|
|
162
|
-
const buffer = Buffer.concat(chunks);
|
|
163
|
-
|
|
164
|
-
let request = {
|
|
165
|
-
config: {
|
|
166
|
-
encoding: 'LINEAR16',
|
|
167
|
-
languageCode: 'en-US',
|
|
168
|
-
...options?.config,
|
|
169
|
-
},
|
|
170
|
-
audio: {
|
|
171
|
-
content: buffer.toString('base64'),
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
console.log(`BEFORE REQUEST`);
|
|
175
|
-
const [response] = await this.speechClient.recognize(request as SpeechTypes.cloud.speech.v1.IRecognizeRequest);
|
|
176
|
-
console.log(`AFTER REQUEST`);
|
|
177
|
-
|
|
178
|
-
if (!response.results || response.results.length === 0) {
|
|
179
|
-
throw new Error('No transcription results returned');
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const transcription = response.results
|
|
183
|
-
.map((result: any) => {
|
|
184
|
-
if (!result.alternatives || result.alternatives.length === 0) {
|
|
185
|
-
return '';
|
|
186
|
-
}
|
|
187
|
-
return result.alternatives[0].transcript || '';
|
|
188
|
-
})
|
|
189
|
-
.filter((text: string) => text.length > 0)
|
|
190
|
-
.join(' ');
|
|
191
|
-
|
|
192
|
-
if (!transcription) {
|
|
193
|
-
throw new Error('No valid transcription found in results');
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return transcription;
|
|
197
|
-
}, 'voice.google.listen')();
|
|
198
|
-
}
|
|
199
|
-
}
|
package/tsconfig.json
DELETED