@mastra/voice-azure 0.1.0-alpha.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/.turbo/turbo-build.log +23 -0
- package/CHANGELOG.md +9 -0
- package/LICENSE +44 -0
- package/README.md +78 -0
- package/dist/_tsup-dts-rollup.d.cts +64 -0
- package/dist/_tsup-dts-rollup.d.ts +64 -0
- package/dist/index.cjs +418 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +396 -0
- package/eslint.config.js +6 -0
- package/package.json +40 -0
- package/src/index.test.ts +167 -0
- package/src/index.ts +229 -0
- package/src/voices.ts +215 -0
- package/tsconfig.json +5 -0
- package/vitest.config.ts +8 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var stream = require('stream');
|
|
4
|
+
var voice = require('@mastra/core/voice');
|
|
5
|
+
var Azure = require('microsoft-cognitiveservices-speech-sdk');
|
|
6
|
+
|
|
7
|
+
function _interopNamespace(e) {
|
|
8
|
+
if (e && e.__esModule) return e;
|
|
9
|
+
var n = Object.create(null);
|
|
10
|
+
if (e) {
|
|
11
|
+
Object.keys(e).forEach(function (k) {
|
|
12
|
+
if (k !== 'default') {
|
|
13
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return e[k]; }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return Object.freeze(n);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var Azure__namespace = /*#__PURE__*/_interopNamespace(Azure);
|
|
26
|
+
|
|
27
|
+
// src/index.ts
|
|
28
|
+
|
|
29
|
+
// src/voices.ts
|
|
30
|
+
var AZURE_VOICES = [
|
|
31
|
+
"af-ZA-AdriNeural",
|
|
32
|
+
"af-ZA-WillemNeural",
|
|
33
|
+
"am-ET-MekdesNeural",
|
|
34
|
+
"am-ET-AmehaNeural",
|
|
35
|
+
"ar-AE-FatimaNeural",
|
|
36
|
+
"ar-AE-HamdanNeural",
|
|
37
|
+
"ar-BH-LailaNeural",
|
|
38
|
+
"ar-BH-AliNeural",
|
|
39
|
+
"ar-DZ-AminaNeural",
|
|
40
|
+
"ar-DZ-IsmaelNeural",
|
|
41
|
+
"ar-EG-SalmaNeural",
|
|
42
|
+
"ar-EG-ShakirNeural",
|
|
43
|
+
"ar-IQ-RanaNeural",
|
|
44
|
+
"ar-IQ-BasselNeural",
|
|
45
|
+
"ar-JO-SanaNeural",
|
|
46
|
+
"ar-JO-TaimNeural",
|
|
47
|
+
"ar-KW-NouraNeural",
|
|
48
|
+
"ar-KW-FahedNeural",
|
|
49
|
+
"ar-LB-LaylaNeural",
|
|
50
|
+
"ar-LB-RamiNeural",
|
|
51
|
+
"ar-LY-ImanNeural",
|
|
52
|
+
"ar-LY-OmarNeural",
|
|
53
|
+
"ar-MA-MounaNeural",
|
|
54
|
+
"ar-MA-JamalNeural",
|
|
55
|
+
"ar-OM-AyshaNeural",
|
|
56
|
+
"ar-OM-AbdullahNeural",
|
|
57
|
+
"ar-QA-AmalNeural",
|
|
58
|
+
"ar-QA-MoazNeural",
|
|
59
|
+
"ar-SA-ZariyahNeural",
|
|
60
|
+
"ar-SA-HamedNeural",
|
|
61
|
+
"ar-SY-AmanyNeural",
|
|
62
|
+
"ar-SY-LaithNeural",
|
|
63
|
+
"ar-TN-ReemNeural",
|
|
64
|
+
"ar-TN-HediNeural",
|
|
65
|
+
"ar-YE-MaryamNeural",
|
|
66
|
+
"ar-YE-SalehNeural",
|
|
67
|
+
"as-IN-YashicaNeural",
|
|
68
|
+
"as-IN-PriyomNeural",
|
|
69
|
+
"az-AZ-BanuNeural",
|
|
70
|
+
"az-AZ-BabekNeural",
|
|
71
|
+
"bg-BG-KalinaNeural",
|
|
72
|
+
"bg-BG-BorislavNeural",
|
|
73
|
+
"bn-BD-NabanitaNeural",
|
|
74
|
+
"bn-BD-PradeepNeural",
|
|
75
|
+
"bn-IN-TanishaaNeural",
|
|
76
|
+
"bn-IN-BashkarNeural",
|
|
77
|
+
"bs-BA-VesnaNeural",
|
|
78
|
+
"bs-BA-GoranNeural",
|
|
79
|
+
"ca-ES-JoanaNeural",
|
|
80
|
+
"ca-ES-EnricNeural",
|
|
81
|
+
"ca-ES-AlbaNeural",
|
|
82
|
+
"cs-CZ-VlastaNeural",
|
|
83
|
+
"cs-CZ-AntoninNeural",
|
|
84
|
+
"cy-GB-NiaNeural",
|
|
85
|
+
"cy-GB-AledNeural",
|
|
86
|
+
"da-DK-ChristelNeural",
|
|
87
|
+
"da-DK-JeppeNeural",
|
|
88
|
+
"de-AT-IngridNeural",
|
|
89
|
+
"de-AT-JonasNeural",
|
|
90
|
+
"de-CH-LeniNeural",
|
|
91
|
+
"de-CH-JanNeural",
|
|
92
|
+
"de-DE-KatjaNeural",
|
|
93
|
+
"de-DE-ConradNeural",
|
|
94
|
+
"de-DE-SeraphinaMultilingualNeural",
|
|
95
|
+
"de-DE-FlorianMultilingualNeural",
|
|
96
|
+
"de-DE-AmalaNeural",
|
|
97
|
+
"de-DE-BerndNeural",
|
|
98
|
+
"de-DE-ChristophNeural",
|
|
99
|
+
"de-DE-ElkeNeural",
|
|
100
|
+
"de-DE-GiselaNeural",
|
|
101
|
+
"de-DE-KasperNeural",
|
|
102
|
+
"de-DE-KillianNeural",
|
|
103
|
+
"de-DE-KlarissaNeural",
|
|
104
|
+
"de-DE-KlausNeural",
|
|
105
|
+
"de-DE-LouisaNeural",
|
|
106
|
+
"de-DE-MajaNeural",
|
|
107
|
+
"de-DE-RalfNeural",
|
|
108
|
+
"de-DE-TanjaNeural",
|
|
109
|
+
"de-DE-Seraphina:DragonHDLatestNeural",
|
|
110
|
+
"el-GR-AthinaNeural",
|
|
111
|
+
"el-GR-NestorasNeural",
|
|
112
|
+
"en-AU-NatashaNeural",
|
|
113
|
+
"en-AU-WilliamNeural",
|
|
114
|
+
"en-AU-AnnetteNeural",
|
|
115
|
+
"en-AU-CarlyNeural",
|
|
116
|
+
"en-AU-DarrenNeural",
|
|
117
|
+
"en-AU-DuncanNeural",
|
|
118
|
+
"en-AU-ElsieNeural",
|
|
119
|
+
"en-AU-FreyaNeural",
|
|
120
|
+
"en-AU-JoanneNeural",
|
|
121
|
+
"en-AU-KenNeural",
|
|
122
|
+
"en-AU-KimNeural",
|
|
123
|
+
"en-AU-NeilNeural",
|
|
124
|
+
"en-AU-TimNeural",
|
|
125
|
+
"en-AU-TinaNeural",
|
|
126
|
+
"en-CA-ClaraNeural",
|
|
127
|
+
"en-CA-LiamNeural",
|
|
128
|
+
"en-GB-SoniaNeural",
|
|
129
|
+
"en-GB-RyanNeural",
|
|
130
|
+
"en-GB-LibbyNeural",
|
|
131
|
+
"en-GB-AdaMultilingualNeural",
|
|
132
|
+
"en-GB-OllieMultilingualNeural",
|
|
133
|
+
"en-GB-AbbiNeural",
|
|
134
|
+
"en-GB-AlfieNeural",
|
|
135
|
+
"en-GB-BellaNeural",
|
|
136
|
+
"en-GB-ElliotNeural",
|
|
137
|
+
"en-GB-EthanNeural",
|
|
138
|
+
"en-GB-HollieNeural",
|
|
139
|
+
"en-GB-MaisieNeural",
|
|
140
|
+
"en-GB-NoahNeural",
|
|
141
|
+
"en-GB-OliverNeural",
|
|
142
|
+
"en-GB-OliviaNeural",
|
|
143
|
+
"en-GB-ThomasNeural",
|
|
144
|
+
"en-GB-MiaNeural",
|
|
145
|
+
"en-HK-YanNeural",
|
|
146
|
+
"en-HK-SamNeural",
|
|
147
|
+
"en-IE-EmilyNeural",
|
|
148
|
+
"en-IE-ConnorNeural",
|
|
149
|
+
"en-IN-AaravNeural",
|
|
150
|
+
"en-IN-AashiNeural",
|
|
151
|
+
"en-IN-AnanyaNeural",
|
|
152
|
+
"en-IN-KavyaNeural",
|
|
153
|
+
"en-IN-KunalNeural",
|
|
154
|
+
"en-IN-NeerjaNeural",
|
|
155
|
+
"en-IN-PrabhatNeural",
|
|
156
|
+
"en-IN-RehaanNeural",
|
|
157
|
+
"en-IN-AartiNeural",
|
|
158
|
+
"en-IN-ArjunNeural",
|
|
159
|
+
"en-KE-AsiliaNeural",
|
|
160
|
+
"en-KE-ChilembaNeural",
|
|
161
|
+
"en-NG-EzinneNeural",
|
|
162
|
+
"en-NG-AbeoNeural",
|
|
163
|
+
"en-NZ-MollyNeural",
|
|
164
|
+
"en-NZ-MitchellNeural",
|
|
165
|
+
"en-PH-RosaNeural",
|
|
166
|
+
"en-PH-JamesNeural",
|
|
167
|
+
"en-SG-LunaNeural",
|
|
168
|
+
"en-SG-WayneNeural",
|
|
169
|
+
"en-TZ-ImaniNeural",
|
|
170
|
+
"en-TZ-ElimuNeural",
|
|
171
|
+
"en-US-AvaMultilingualNeural",
|
|
172
|
+
"en-US-AndrewMultilingualNeural",
|
|
173
|
+
"en-US-EmmaMultilingualNeural",
|
|
174
|
+
"en-US-BrianMultilingualNeural",
|
|
175
|
+
"en-US-AvaNeural",
|
|
176
|
+
"en-US-AndrewNeural",
|
|
177
|
+
"en-US-EmmaNeural",
|
|
178
|
+
"en-US-BrianNeural",
|
|
179
|
+
"en-US-JennyNeural",
|
|
180
|
+
"en-US-GuyNeural",
|
|
181
|
+
"en-US-AriaNeural",
|
|
182
|
+
"en-US-DavisNeural",
|
|
183
|
+
"en-US-JaneNeural",
|
|
184
|
+
"en-US-JasonNeural",
|
|
185
|
+
"en-US-KaiNeural",
|
|
186
|
+
"en-US-LunaNeural",
|
|
187
|
+
"en-US-SaraNeural",
|
|
188
|
+
"en-US-TonyNeural",
|
|
189
|
+
"en-US-NancyNeural",
|
|
190
|
+
"en-US-CoraMultilingualNeural",
|
|
191
|
+
"en-US-ChristopherMultilingualNeural",
|
|
192
|
+
"en-US-BrandonMultilingualNeural",
|
|
193
|
+
"en-US-AmberNeural",
|
|
194
|
+
"en-US-AnaNeural",
|
|
195
|
+
"en-US-AshleyNeural",
|
|
196
|
+
"en-US-BrandonNeural",
|
|
197
|
+
"en-US-ChristopherNeural",
|
|
198
|
+
"en-US-CoraNeural",
|
|
199
|
+
"en-US-ElizabethNeural",
|
|
200
|
+
"en-US-EricNeural",
|
|
201
|
+
"en-US-JacobNeural",
|
|
202
|
+
"en-US-JennyMultilingualNeural",
|
|
203
|
+
"en-US-MichelleNeural",
|
|
204
|
+
"en-US-MonicaNeural",
|
|
205
|
+
"en-US-RogerNeural",
|
|
206
|
+
"en-US-RyanMultilingualNeural",
|
|
207
|
+
"en-US-SteffanNeural",
|
|
208
|
+
"en-US-AdamMultilingualNeural",
|
|
209
|
+
"en-US-AIGenerate1Neural",
|
|
210
|
+
"en-US-AIGenerate2Neural",
|
|
211
|
+
"en-US-AlloyTurboMultilingualNeural",
|
|
212
|
+
"en-US-AmandaMultilingualNeural",
|
|
213
|
+
"en-US-BlueNeural",
|
|
214
|
+
"en-US-DavisMultilingualNeural",
|
|
215
|
+
"en-US-DerekMultilingualNeural",
|
|
216
|
+
"en-US-DustinMultilingualNeural",
|
|
217
|
+
"en-US-EchoTurboMultilingualNeural",
|
|
218
|
+
"en-US-EvelynMultilingualNeural",
|
|
219
|
+
"en-US-FableTurboMultilingualNeural",
|
|
220
|
+
"en-US-LewisMultilingualNeural",
|
|
221
|
+
"en-US-LolaMultilingualNeural",
|
|
222
|
+
"en-US-NancyMultilingualNeural",
|
|
223
|
+
"en-US-NovaTurboMultilingualNeural",
|
|
224
|
+
"en-US-OnyxTurboMultilingualNeural",
|
|
225
|
+
"en-US-PhoebeMultilingualNeural",
|
|
226
|
+
"en-US-SamuelMultilingualNeural",
|
|
227
|
+
"en-US-SerenaMultilingualNeural",
|
|
228
|
+
"en-US-ShimmerTurboMultilingualNeural",
|
|
229
|
+
"en-US-SteffanMultilingualNeural",
|
|
230
|
+
"en-US-Andrew:DragonHDLatestNeural",
|
|
231
|
+
"en-US-Andrew2:DragonHDLatestNeural",
|
|
232
|
+
"en-US-Aria:DragonHDLatestNeural",
|
|
233
|
+
"en-US-Ava:DragonHDLatestNeural",
|
|
234
|
+
"en-US-Brian:DragonHDLatestNeural",
|
|
235
|
+
"en-US-Davis:DragonHDLatestNeural",
|
|
236
|
+
"en-US-Emma:DragonHDLatestNeural",
|
|
237
|
+
"en-US-Emma2:DragonHDLatestNeural",
|
|
238
|
+
"en-US-Jenny:DragonHDLatestNeural",
|
|
239
|
+
"en-US-Steffan:DragonHDLatestNeural",
|
|
240
|
+
"en-ZA-LeahNeural",
|
|
241
|
+
"en-ZA-LukeNeural"
|
|
242
|
+
];
|
|
243
|
+
|
|
244
|
+
// src/index.ts
|
|
245
|
+
var AzureVoice = class extends voice.MastraVoice {
|
|
246
|
+
speechConfig;
|
|
247
|
+
listeningConfig;
|
|
248
|
+
speechSynthesizer;
|
|
249
|
+
speechRecognizer;
|
|
250
|
+
/**
|
|
251
|
+
* Creates a new instance of AzureVoice for text-to-speech and speech-to-text services.
|
|
252
|
+
*
|
|
253
|
+
* @param {Object} config - Configuration options
|
|
254
|
+
* @param {AzureVoiceConfig} [config.speechModel] - Configuration for text-to-speech
|
|
255
|
+
* @param {AzureVoiceConfig} [config.listeningModel] - Configuration for speech-to-text
|
|
256
|
+
* @param {VoiceId} [config.speaker] - Default voice ID for speech synthesis
|
|
257
|
+
*/
|
|
258
|
+
constructor({
|
|
259
|
+
speechModel,
|
|
260
|
+
listeningModel,
|
|
261
|
+
speaker
|
|
262
|
+
} = {}) {
|
|
263
|
+
super({
|
|
264
|
+
speechModel: {
|
|
265
|
+
name: "",
|
|
266
|
+
apiKey: speechModel?.apiKey ?? process.env.AZURE_API_KEY
|
|
267
|
+
},
|
|
268
|
+
listeningModel: {
|
|
269
|
+
name: "",
|
|
270
|
+
apiKey: listeningModel?.apiKey ?? process.env.AZURE_API_KEY
|
|
271
|
+
},
|
|
272
|
+
speaker
|
|
273
|
+
});
|
|
274
|
+
const envApiKey = process.env.AZURE_API_KEY;
|
|
275
|
+
const envRegion = process.env.AZURE_REGION;
|
|
276
|
+
if (speechModel) {
|
|
277
|
+
const apiKey = speechModel.apiKey ?? envApiKey;
|
|
278
|
+
const region = speechModel.region ?? envRegion;
|
|
279
|
+
if (!apiKey) throw new Error("No Azure API key provided for speech model");
|
|
280
|
+
if (!region) throw new Error("No region provided for speech model");
|
|
281
|
+
this.speechConfig = Azure__namespace.SpeechConfig.fromSubscription(apiKey, region);
|
|
282
|
+
this.speechConfig.speechSynthesisVoiceName = speechModel.voiceName || speaker || "en-US-AriaNeural";
|
|
283
|
+
this.speechSynthesizer = new Azure__namespace.SpeechSynthesizer(this.speechConfig);
|
|
284
|
+
}
|
|
285
|
+
if (listeningModel) {
|
|
286
|
+
const apiKey = listeningModel.apiKey ?? envApiKey;
|
|
287
|
+
const region = listeningModel.region ?? envRegion;
|
|
288
|
+
if (!apiKey) throw new Error("No Azure API key provided for listening model");
|
|
289
|
+
if (!region) throw new Error("No region provided for listening model");
|
|
290
|
+
this.listeningConfig = Azure__namespace.SpeechConfig.fromSubscription(apiKey, region);
|
|
291
|
+
if (listeningModel.language) {
|
|
292
|
+
this.listeningConfig.speechRecognitionLanguage = listeningModel.language;
|
|
293
|
+
}
|
|
294
|
+
this.speechRecognizer = new Azure__namespace.SpeechRecognizer(this.listeningConfig);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Gets a list of available voices for speech synthesis.
|
|
299
|
+
*
|
|
300
|
+
* @returns {Promise<Array<{ voiceId: string; language: string; region: string; }>>} List of available voices
|
|
301
|
+
*/
|
|
302
|
+
async getSpeakers() {
|
|
303
|
+
return this.traced(async () => {
|
|
304
|
+
return AZURE_VOICES.map((voice) => ({
|
|
305
|
+
voiceId: voice,
|
|
306
|
+
language: voice.split("-")[0],
|
|
307
|
+
region: voice.split("-")[1]
|
|
308
|
+
}));
|
|
309
|
+
}, "voice.azure.voices")();
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Converts text to speech using Azure's Text-to-Speech service.
|
|
313
|
+
*
|
|
314
|
+
* @param {string | NodeJS.ReadableStream} input - Text to convert to speech
|
|
315
|
+
* @param {Object} [options] - Optional parameters
|
|
316
|
+
* @param {string} [options.speaker] - Voice ID to use for synthesis
|
|
317
|
+
* @returns {Promise<NodeJS.ReadableStream>} Stream containing the synthesized audio
|
|
318
|
+
* @throws {Error} If speech model is not configured or synthesis fails
|
|
319
|
+
*/
|
|
320
|
+
async speak(input, options) {
|
|
321
|
+
if (!this.speechConfig) {
|
|
322
|
+
throw new Error("Speech model (Azure) not configured");
|
|
323
|
+
}
|
|
324
|
+
if (typeof input !== "string") {
|
|
325
|
+
const chunks = [];
|
|
326
|
+
try {
|
|
327
|
+
for await (const chunk of input) {
|
|
328
|
+
chunks.push(chunk);
|
|
329
|
+
}
|
|
330
|
+
input = Buffer.concat(chunks).toString("utf-8");
|
|
331
|
+
} catch (error) {
|
|
332
|
+
throw new Error(`Failed to read input stream: ${error instanceof Error ? error.message : String(error)}`);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (!input?.trim()) {
|
|
336
|
+
throw new Error("Input text is empty");
|
|
337
|
+
}
|
|
338
|
+
if (options?.speaker) {
|
|
339
|
+
this.speechConfig.speechSynthesisVoiceName = options.speaker;
|
|
340
|
+
}
|
|
341
|
+
const synthesizer = new Azure__namespace.SpeechSynthesizer(this.speechConfig);
|
|
342
|
+
try {
|
|
343
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
344
|
+
setTimeout(() => reject(new Error("Speech synthesis timed out")), 5e3);
|
|
345
|
+
});
|
|
346
|
+
const synthesisPromise = this.traced(
|
|
347
|
+
() => new Promise((resolve, reject) => {
|
|
348
|
+
synthesizer.speakTextAsync(
|
|
349
|
+
input,
|
|
350
|
+
(result2) => result2.errorDetails ? reject(new Error(`Speech synthesis failed: ${result2.errorDetails}`)) : resolve(result2),
|
|
351
|
+
(error) => reject(new Error(`Speech synthesis error: ${String(error)}`))
|
|
352
|
+
);
|
|
353
|
+
}),
|
|
354
|
+
"voice.azure.speak"
|
|
355
|
+
)();
|
|
356
|
+
const result = await Promise.race([synthesisPromise, timeoutPromise]);
|
|
357
|
+
synthesizer.close();
|
|
358
|
+
if (result.reason !== Azure__namespace.ResultReason.SynthesizingAudioCompleted) {
|
|
359
|
+
throw new Error(`Speech synthesis failed: ${result.errorDetails || result.reason}`);
|
|
360
|
+
}
|
|
361
|
+
return stream.Readable.from([Buffer.from(result.audioData)]);
|
|
362
|
+
} catch (error) {
|
|
363
|
+
synthesizer.close();
|
|
364
|
+
throw error instanceof Error ? error : new Error(String(error));
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Transcribes audio (STT) from a Node.js stream using Azure.
|
|
369
|
+
*
|
|
370
|
+
* @param {NodeJS.ReadableStream} audioStream - The audio to be transcribed, must be in .wav format.
|
|
371
|
+
* @returns {Promise<string>} - The recognized text.
|
|
372
|
+
*/
|
|
373
|
+
async listen(audioStream) {
|
|
374
|
+
if (!this.listeningConfig || !this.speechRecognizer) {
|
|
375
|
+
throw new Error("Listening model (Azure) not configured");
|
|
376
|
+
}
|
|
377
|
+
const chunks = [];
|
|
378
|
+
for await (const chunk of audioStream) {
|
|
379
|
+
chunks.push(chunk);
|
|
380
|
+
}
|
|
381
|
+
const audioData = Buffer.concat(chunks);
|
|
382
|
+
const pushStream = Azure__namespace.AudioInputStream.createPushStream();
|
|
383
|
+
const audioConfig = Azure__namespace.AudioConfig.fromStreamInput(pushStream);
|
|
384
|
+
const recognizer = new Azure__namespace.SpeechRecognizer(this.listeningConfig, audioConfig);
|
|
385
|
+
try {
|
|
386
|
+
const recognitionPromise = new Promise((resolve, reject) => {
|
|
387
|
+
recognizer.recognizeOnceAsync(
|
|
388
|
+
(result) => {
|
|
389
|
+
if (result.reason === Azure__namespace.ResultReason.RecognizedSpeech) {
|
|
390
|
+
resolve(result.text);
|
|
391
|
+
} else {
|
|
392
|
+
const reason = Azure__namespace.ResultReason[result.reason] || result.reason;
|
|
393
|
+
reject(new Error(`Speech recognition failed: ${reason} - ${result.errorDetails || ""}`));
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
(error) => reject(new Error(`Speech recognition error: ${String(error)}`))
|
|
397
|
+
);
|
|
398
|
+
});
|
|
399
|
+
const chunkSize = 4096;
|
|
400
|
+
for (let i = 0; i < audioData.length; i += chunkSize) {
|
|
401
|
+
const chunk = audioData.slice(i, i + chunkSize);
|
|
402
|
+
pushStream.write(chunk);
|
|
403
|
+
}
|
|
404
|
+
pushStream.close();
|
|
405
|
+
const text = await this.traced(() => recognitionPromise, "voice.azure.listen")();
|
|
406
|
+
return text;
|
|
407
|
+
} catch (error) {
|
|
408
|
+
if (error instanceof Error) {
|
|
409
|
+
throw error;
|
|
410
|
+
}
|
|
411
|
+
throw new Error(String(error));
|
|
412
|
+
} finally {
|
|
413
|
+
recognizer.close();
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
exports.AzureVoice = AzureVoice;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AzureVoice } from './_tsup-dts-rollup.cjs';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AzureVoice } from './_tsup-dts-rollup.js';
|