@mastra/voice-google 0.1.3-alpha.9 → 0.1.4-alpha.0

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 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
- chunks.push(Buffer.from(chunk));
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
- chunks.push(Buffer.from(chunk));
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
- chunks.push(Buffer.from(chunk));
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
- chunks.push(Buffer.from(chunk));
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-alpha.9",
3
+ "version": "0.1.4-alpha.0",
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.0",
23
- "@google-cloud/text-to-speech": "^5.0.1",
24
- "zod": "^3.24.1",
25
- "@mastra/core": "^0.5.0-alpha.9"
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.1-alpha.0"
26
29
  },
27
30
  "devDependencies": {
28
- "@types/node": "^22.13.1",
29
- "tsup": "^8.0.1",
30
- "typescript": "^5.7.3",
31
- "vitest": "^2.1.8",
32
- "eslint": "^9.20.1",
33
- "@internal/lint": "0.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 ."
@@ -1,23 +0,0 @@
1
-
2
- > @mastra/voice-google@0.1.3-alpha.9 build /home/runner/work/mastra/mastra/voice/google
3
- > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake
4
-
5
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.3.6
8
- TSC Build start
9
- TSC ⚡️ Build success in 11591ms
10
- DTS Build start
11
- CLI Target: es2022
12
- Analysis will use the bundled TypeScript version 5.7.3
13
- Writing package typings: /home/runner/work/mastra/mastra/voice/google/dist/_tsup-dts-rollup.d.ts
14
- Analysis will use the bundled TypeScript version 5.7.3
15
- Writing package typings: /home/runner/work/mastra/mastra/voice/google/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 15442ms
17
- CLI Cleaning output folder
18
- ESM Build start
19
- CJS Build start
20
- ESM dist/index.js 5.45 KB
21
- ESM ⚡️ Build success in 671ms
22
- CJS dist/index.cjs 5.48 KB
23
- CJS ⚡️ Build success in 671ms
package/CHANGELOG.md DELETED
@@ -1,237 +0,0 @@
1
- # @mastra/voice-google
2
-
3
- ## 0.1.3-alpha.9
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies [e9fbac5]
8
- - Updated dependencies [1e8bcbc]
9
- - Updated dependencies [aeb5e36]
10
- - Updated dependencies [f2301de]
11
- - @mastra/core@0.5.0-alpha.9
12
-
13
- ## 0.1.3-alpha.8
14
-
15
- ### Patch Changes
16
-
17
- - Updated dependencies [506f1d5]
18
- - @mastra/core@0.5.0-alpha.8
19
-
20
- ## 0.1.3-alpha.7
21
-
22
- ### Patch Changes
23
-
24
- - Updated dependencies [ee667a2]
25
- - @mastra/core@0.5.0-alpha.7
26
-
27
- ## 0.1.3-alpha.6
28
-
29
- ### Patch Changes
30
-
31
- - Updated dependencies [f6678e4]
32
- - @mastra/core@0.5.0-alpha.6
33
-
34
- ## 0.1.3-alpha.5
35
-
36
- ### Patch Changes
37
-
38
- - Updated dependencies [22643eb]
39
- - Updated dependencies [6feb23f]
40
- - Updated dependencies [f2d6727]
41
- - Updated dependencies [301e4ee]
42
- - Updated dependencies [dfbe4e9]
43
- - Updated dependencies [9e81f35]
44
- - Updated dependencies [caefaa2]
45
- - Updated dependencies [c151ae6]
46
- - Updated dependencies [52e0418]
47
- - Updated dependencies [03236ec]
48
- - Updated dependencies [3764e71]
49
- - Updated dependencies [df982db]
50
- - Updated dependencies [0461849]
51
- - Updated dependencies [2259379]
52
- - Updated dependencies [358f069]
53
- - @mastra/core@0.5.0-alpha.5
54
-
55
- ## 0.1.3-alpha.4
56
-
57
- ### Patch Changes
58
-
59
- - Updated dependencies [d79aedf]
60
- - @mastra/core@0.5.0-alpha.4
61
-
62
- ## 0.1.3-alpha.3
63
-
64
- ### Patch Changes
65
-
66
- - Updated dependencies [3d0e290]
67
- - @mastra/core@0.5.0-alpha.3
68
-
69
- ## 0.1.3-alpha.2
70
-
71
- ### Patch Changes
72
-
73
- - Updated dependencies [02ffb7b]
74
- - @mastra/core@0.5.0-alpha.2
75
-
76
- ## 0.1.3-alpha.1
77
-
78
- ### Patch Changes
79
-
80
- - Updated dependencies [dab255b]
81
- - @mastra/core@0.5.0-alpha.1
82
-
83
- ## 0.1.3-alpha.0
84
-
85
- ### Patch Changes
86
-
87
- - Updated dependencies [59df7b6]
88
- - Updated dependencies [29f3a82]
89
- - Updated dependencies [59df7b6]
90
- - Updated dependencies [c139344]
91
- - @mastra/core@0.5.0-alpha.0
92
-
93
- ## 0.1.2
94
-
95
- ### Patch Changes
96
-
97
- - Updated dependencies [1da20e7]
98
- - @mastra/core@0.4.4
99
-
100
- ## 0.1.2-alpha.0
101
-
102
- ### Patch Changes
103
-
104
- - Updated dependencies [1da20e7]
105
- - @mastra/core@0.4.4-alpha.0
106
-
107
- ## 0.1.1
108
-
109
- ### Patch Changes
110
-
111
- - bb4f447: Add support for commonjs
112
- - Updated dependencies [0d185b1]
113
- - Updated dependencies [ed55f1d]
114
- - Updated dependencies [06aa827]
115
- - Updated dependencies [0fd78ac]
116
- - Updated dependencies [2512a93]
117
- - Updated dependencies [e62de74]
118
- - Updated dependencies [0d25b75]
119
- - Updated dependencies [fd14a3f]
120
- - Updated dependencies [8d13b14]
121
- - Updated dependencies [3f369a2]
122
- - Updated dependencies [3ee4831]
123
- - Updated dependencies [4d4e1e1]
124
- - Updated dependencies [bb4f447]
125
- - Updated dependencies [108793c]
126
- - Updated dependencies [5f28f44]
127
- - Updated dependencies [dabecf4]
128
- - @mastra/core@0.4.3
129
-
130
- ## 0.1.1-alpha.4
131
-
132
- ### Patch Changes
133
-
134
- - Updated dependencies [dabecf4]
135
- - @mastra/core@0.4.3-alpha.4
136
-
137
- ## 0.1.1-alpha.3
138
-
139
- ### Patch Changes
140
-
141
- - bb4f447: Add support for commonjs
142
- - Updated dependencies [0fd78ac]
143
- - Updated dependencies [0d25b75]
144
- - Updated dependencies [fd14a3f]
145
- - Updated dependencies [3f369a2]
146
- - Updated dependencies [4d4e1e1]
147
- - Updated dependencies [bb4f447]
148
- - @mastra/core@0.4.3-alpha.3
149
-
150
- ## 0.1.1-alpha.2
151
-
152
- ### Patch Changes
153
-
154
- - Updated dependencies [2512a93]
155
- - Updated dependencies [e62de74]
156
- - @mastra/core@0.4.3-alpha.2
157
-
158
- ## 0.1.1-alpha.1
159
-
160
- ### Patch Changes
161
-
162
- - Updated dependencies [0d185b1]
163
- - Updated dependencies [ed55f1d]
164
- - Updated dependencies [8d13b14]
165
- - Updated dependencies [3ee4831]
166
- - Updated dependencies [108793c]
167
- - Updated dependencies [5f28f44]
168
- - @mastra/core@0.4.3-alpha.1
169
-
170
- ## 0.1.1-alpha.0
171
-
172
- ### Patch Changes
173
-
174
- - Updated dependencies [06aa827]
175
- - @mastra/core@0.4.3-alpha.0
176
-
177
- ## 0.1.0
178
-
179
- ### Patch Changes
180
-
181
- - 5e0f727: deprecate @mastra/speech-google for @mastra/voice-google
182
- - Updated dependencies [7fceae1]
183
- - Updated dependencies [8d94c3e]
184
- - Updated dependencies [99dcdb5]
185
- - Updated dependencies [6cb63e0]
186
- - Updated dependencies [f626fbb]
187
- - Updated dependencies [e752340]
188
- - Updated dependencies [eb91535]
189
- - @mastra/core@0.4.2
190
-
191
- ## 0.1.0-alpha.4
192
-
193
- ### Patch Changes
194
-
195
- - Updated dependencies [8d94c3e]
196
- - Updated dependencies [99dcdb5]
197
- - Updated dependencies [e752340]
198
- - Updated dependencies [eb91535]
199
- - @mastra/core@0.4.2-alpha.2
200
-
201
- ## 0.1.0-alpha.3
202
-
203
- ### Patch Changes
204
-
205
- - Updated dependencies [6cb63e0]
206
- - @mastra/core@0.4.2-alpha.1
207
-
208
- ## 0.1.0-alpha.2
209
-
210
- ### Patch Changes
211
-
212
- - 5e0f727: deprecate @mastra/speech-google for @mastra/voice-google
213
-
214
- ## 0.1.0
215
-
216
- ### Minor Changes
217
-
218
- - Initial release of @mastra/voice-google
219
- - Combines functionality from deprecated @mastra/speech-google
220
- - Adds Speech-to-Text capabilities
221
- - Implements new MastraVoice interface from @mastra/core
222
-
223
- ### Notes
224
-
225
- This package replaces @mastra/speech-google, which reached version 0.1.3-alpha.1. Key features from the previous package:
226
-
227
- - Neural Text-to-Speech synthesis
228
- - Multiple voice options
229
- - Streaming support
230
- - Integration with Google Cloud services
231
-
232
- The new package adds:
233
-
234
- - Speech-to-Text recognition
235
- - Combined speech and listening models
236
- - Improved voice management
237
- - Better type safety and error handling
package/eslint.config.js DELETED
@@ -1,6 +0,0 @@
1
- import { createConfig } from '@internal/lint/eslint';
2
-
3
- const config = await createConfig();
4
-
5
- /** @type {import("eslint").Linter.Config[]} */
6
- export default [...config];
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
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.node.json",
3
- "include": ["src/**/*"],
4
- "exclude": ["node_modules", "**/*.test.ts"]
5
- }
package/vitest.config.ts DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: 'node',
7
- },
8
- });