@juspay/neurolink 9.61.1 → 9.62.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/CHANGELOG.md +12 -0
- package/README.md +23 -17
- package/dist/adapters/tts/googleTTSHandler.js +1 -1
- package/dist/browser/neurolink.min.js +382 -364
- package/dist/cli/commands/serve.js +9 -0
- package/dist/cli/commands/voiceServer.d.ts +7 -0
- package/dist/cli/commands/voiceServer.js +9 -1
- package/dist/cli/factories/commandFactory.js +136 -11
- package/dist/cli/loop/optionsSchema.d.ts +1 -1
- package/dist/cli/utils/audioFileUtils.d.ts +3 -3
- package/dist/cli/utils/audioFileUtils.js +5 -1
- package/dist/core/baseProvider.js +29 -6
- package/dist/factories/providerRegistry.d.ts +14 -0
- package/dist/factories/providerRegistry.js +141 -2
- package/dist/lib/adapters/tts/googleTTSHandler.js +1 -1
- package/dist/lib/core/baseProvider.js +29 -6
- package/dist/lib/factories/providerRegistry.d.ts +14 -0
- package/dist/lib/factories/providerRegistry.js +141 -2
- package/dist/lib/mcp/toolRegistry.js +7 -1
- package/dist/lib/neurolink.d.ts +19 -0
- package/dist/lib/neurolink.js +252 -14
- package/dist/lib/observability/exporters/laminarExporter.js +1 -0
- package/dist/lib/observability/exporters/posthogExporter.js +1 -0
- package/dist/lib/observability/utils/spanSerializer.js +1 -0
- package/dist/lib/server/voice/tokenCompare.d.ts +14 -0
- package/dist/lib/server/voice/tokenCompare.js +23 -0
- package/dist/lib/server/voice/voiceServerApp.js +62 -3
- package/dist/lib/server/voice/voiceWebSocketHandler.d.ts +20 -3
- package/dist/lib/server/voice/voiceWebSocketHandler.js +555 -435
- package/dist/lib/types/generate.d.ts +47 -0
- package/dist/lib/types/hitl.d.ts +3 -0
- package/dist/lib/types/index.d.ts +1 -1
- package/dist/lib/types/index.js +1 -1
- package/dist/lib/types/realtime.d.ts +243 -0
- package/dist/lib/types/realtime.js +70 -0
- package/dist/lib/types/server.d.ts +68 -0
- package/dist/lib/types/span.d.ts +2 -0
- package/dist/lib/types/span.js +2 -0
- package/dist/lib/types/stream.d.ts +36 -14
- package/dist/lib/types/stt.d.ts +585 -0
- package/dist/lib/types/stt.js +90 -0
- package/dist/lib/types/tools.d.ts +2 -0
- package/dist/lib/types/tts.d.ts +23 -11
- package/dist/lib/types/tts.js +7 -0
- package/dist/lib/types/voice.d.ts +272 -0
- package/dist/lib/types/voice.js +137 -0
- package/dist/lib/utils/audioFormatDetector.d.ts +15 -0
- package/dist/lib/utils/audioFormatDetector.js +34 -0
- package/dist/lib/utils/errorHandling.js +4 -0
- package/dist/lib/utils/sttProcessor.d.ts +115 -0
- package/dist/lib/utils/sttProcessor.js +295 -0
- package/dist/lib/voice/RealtimeVoiceAPI.d.ts +183 -0
- package/dist/lib/voice/RealtimeVoiceAPI.js +439 -0
- package/dist/lib/voice/audio-utils.d.ts +135 -0
- package/dist/lib/voice/audio-utils.js +435 -0
- package/dist/lib/voice/errors.d.ts +123 -0
- package/dist/lib/voice/errors.js +386 -0
- package/dist/lib/voice/index.d.ts +26 -0
- package/dist/lib/voice/index.js +55 -0
- package/dist/lib/voice/providers/AzureSTT.d.ts +47 -0
- package/dist/lib/voice/providers/AzureSTT.js +345 -0
- package/dist/lib/voice/providers/AzureTTS.d.ts +59 -0
- package/dist/lib/voice/providers/AzureTTS.js +349 -0
- package/dist/lib/voice/providers/DeepgramSTT.d.ts +40 -0
- package/dist/lib/voice/providers/DeepgramSTT.js +550 -0
- package/dist/lib/voice/providers/ElevenLabsTTS.d.ts +53 -0
- package/dist/lib/voice/providers/ElevenLabsTTS.js +311 -0
- package/dist/lib/voice/providers/GeminiLive.d.ts +52 -0
- package/dist/lib/voice/providers/GeminiLive.js +372 -0
- package/dist/lib/voice/providers/GoogleSTT.d.ts +60 -0
- package/dist/lib/voice/providers/GoogleSTT.js +454 -0
- package/dist/lib/voice/providers/OpenAIRealtime.d.ts +47 -0
- package/dist/lib/voice/providers/OpenAIRealtime.js +412 -0
- package/dist/lib/voice/providers/OpenAISTT.d.ts +41 -0
- package/dist/lib/voice/providers/OpenAISTT.js +286 -0
- package/dist/lib/voice/providers/OpenAITTS.d.ts +49 -0
- package/dist/lib/voice/providers/OpenAITTS.js +271 -0
- package/dist/lib/voice/stream-handler.d.ts +166 -0
- package/dist/lib/voice/stream-handler.js +514 -0
- package/dist/mcp/toolRegistry.js +7 -1
- package/dist/neurolink.d.ts +19 -0
- package/dist/neurolink.js +252 -14
- package/dist/observability/exporters/laminarExporter.js +1 -0
- package/dist/observability/exporters/posthogExporter.js +1 -0
- package/dist/observability/utils/spanSerializer.js +1 -0
- package/dist/server/voice/tokenCompare.d.ts +14 -0
- package/dist/server/voice/tokenCompare.js +22 -0
- package/dist/server/voice/voiceServerApp.js +62 -3
- package/dist/server/voice/voiceWebSocketHandler.d.ts +20 -3
- package/dist/server/voice/voiceWebSocketHandler.js +555 -435
- package/dist/types/generate.d.ts +47 -0
- package/dist/types/hitl.d.ts +3 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/realtime.d.ts +243 -0
- package/dist/types/realtime.js +69 -0
- package/dist/types/server.d.ts +68 -0
- package/dist/types/span.d.ts +2 -0
- package/dist/types/span.js +2 -0
- package/dist/types/stream.d.ts +36 -14
- package/dist/types/stt.d.ts +585 -0
- package/dist/types/stt.js +89 -0
- package/dist/types/tools.d.ts +2 -0
- package/dist/types/tts.d.ts +23 -11
- package/dist/types/tts.js +7 -0
- package/dist/types/voice.d.ts +272 -0
- package/dist/types/voice.js +136 -0
- package/dist/utils/audioFormatDetector.d.ts +15 -0
- package/dist/utils/audioFormatDetector.js +33 -0
- package/dist/utils/errorHandling.js +4 -0
- package/dist/utils/sttProcessor.d.ts +115 -0
- package/dist/utils/sttProcessor.js +294 -0
- package/dist/voice/RealtimeVoiceAPI.d.ts +183 -0
- package/dist/voice/RealtimeVoiceAPI.js +438 -0
- package/dist/voice/audio-utils.d.ts +135 -0
- package/dist/voice/audio-utils.js +434 -0
- package/dist/voice/errors.d.ts +123 -0
- package/dist/voice/errors.js +385 -0
- package/dist/voice/index.d.ts +26 -0
- package/dist/voice/index.js +54 -0
- package/dist/voice/providers/AzureSTT.d.ts +47 -0
- package/dist/voice/providers/AzureSTT.js +344 -0
- package/dist/voice/providers/AzureTTS.d.ts +59 -0
- package/dist/voice/providers/AzureTTS.js +348 -0
- package/dist/voice/providers/DeepgramSTT.d.ts +40 -0
- package/dist/voice/providers/DeepgramSTT.js +549 -0
- package/dist/voice/providers/ElevenLabsTTS.d.ts +53 -0
- package/dist/voice/providers/ElevenLabsTTS.js +310 -0
- package/dist/voice/providers/GeminiLive.d.ts +52 -0
- package/dist/voice/providers/GeminiLive.js +371 -0
- package/dist/voice/providers/GoogleSTT.d.ts +60 -0
- package/dist/voice/providers/GoogleSTT.js +453 -0
- package/dist/voice/providers/OpenAIRealtime.d.ts +47 -0
- package/dist/voice/providers/OpenAIRealtime.js +411 -0
- package/dist/voice/providers/OpenAISTT.d.ts +41 -0
- package/dist/voice/providers/OpenAISTT.js +285 -0
- package/dist/voice/providers/OpenAITTS.d.ts +49 -0
- package/dist/voice/providers/OpenAITTS.js +270 -0
- package/dist/voice/stream-handler.d.ts +166 -0
- package/dist/voice/stream-handler.js +513 -0
- package/package.json +5 -2
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voice Module Error Classes
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive error handling for TTS, STT, and Realtime Voice operations.
|
|
5
|
+
*
|
|
6
|
+
* @module voice/errors
|
|
7
|
+
*/
|
|
8
|
+
import { ErrorCategory, ErrorSeverity } from "../constants/enums.js";
|
|
9
|
+
import { NeuroLinkError } from "../utils/errorHandling.js";
|
|
10
|
+
import { REALTIME_ERROR_CODES, STT_ERROR_CODES, VOICE_ERROR_CODES, } from "../types/index.js";
|
|
11
|
+
// Re-export error codes for convenience
|
|
12
|
+
export { STT_ERROR_CODES, REALTIME_ERROR_CODES, VOICE_ERROR_CODES };
|
|
13
|
+
/**
|
|
14
|
+
* Base Voice Error class for all voice-related errors
|
|
15
|
+
*/
|
|
16
|
+
export class VoiceError extends NeuroLinkError {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super({
|
|
19
|
+
code: options.code,
|
|
20
|
+
message: options.message,
|
|
21
|
+
category: options.category ?? ErrorCategory.EXECUTION,
|
|
22
|
+
severity: options.severity ?? ErrorSeverity.MEDIUM,
|
|
23
|
+
retriable: options.retriable ?? false,
|
|
24
|
+
context: options.context,
|
|
25
|
+
originalError: options.originalError,
|
|
26
|
+
});
|
|
27
|
+
this.name = "VoiceError";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* STT Error class for speech-to-text specific errors
|
|
32
|
+
*/
|
|
33
|
+
export class STTError extends VoiceError {
|
|
34
|
+
constructor(options) {
|
|
35
|
+
super({
|
|
36
|
+
...options,
|
|
37
|
+
category: options.category ?? ErrorCategory.VALIDATION,
|
|
38
|
+
severity: options.severity ?? ErrorSeverity.MEDIUM,
|
|
39
|
+
retriable: options.retriable ?? false,
|
|
40
|
+
});
|
|
41
|
+
this.name = "STTError";
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create an error for empty audio input
|
|
45
|
+
*/
|
|
46
|
+
static audioEmpty(provider) {
|
|
47
|
+
return new STTError({
|
|
48
|
+
code: STT_ERROR_CODES.AUDIO_EMPTY,
|
|
49
|
+
message: "Audio input is empty or invalid",
|
|
50
|
+
category: ErrorCategory.VALIDATION,
|
|
51
|
+
severity: ErrorSeverity.LOW,
|
|
52
|
+
retriable: false,
|
|
53
|
+
context: { provider },
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create an error for audio that exceeds maximum duration
|
|
58
|
+
*/
|
|
59
|
+
static audioTooLong(durationSeconds, maxDurationSeconds, provider) {
|
|
60
|
+
return new STTError({
|
|
61
|
+
code: STT_ERROR_CODES.AUDIO_TOO_LONG,
|
|
62
|
+
message: `Audio duration (${durationSeconds}s) exceeds maximum allowed (${maxDurationSeconds}s)`,
|
|
63
|
+
category: ErrorCategory.VALIDATION,
|
|
64
|
+
severity: ErrorSeverity.MEDIUM,
|
|
65
|
+
retriable: false,
|
|
66
|
+
context: { durationSeconds, maxDurationSeconds, provider },
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Create an error for invalid audio format
|
|
71
|
+
*/
|
|
72
|
+
static invalidFormat(format, supportedFormatsOrProvider, provider) {
|
|
73
|
+
// Handle overloaded signature: (format, provider) or (format, supportedFormats[], provider?)
|
|
74
|
+
let supportedFormats;
|
|
75
|
+
let actualProvider;
|
|
76
|
+
if (typeof supportedFormatsOrProvider === "string") {
|
|
77
|
+
// Called as (format, provider)
|
|
78
|
+
actualProvider = supportedFormatsOrProvider;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// Called as (format, supportedFormats[], provider?)
|
|
82
|
+
supportedFormats = supportedFormatsOrProvider;
|
|
83
|
+
actualProvider = provider;
|
|
84
|
+
}
|
|
85
|
+
const message = supportedFormats
|
|
86
|
+
? `Unsupported audio format: ${format}. Supported formats: ${supportedFormats.join(", ")}`
|
|
87
|
+
: `Unsupported audio format: ${format}`;
|
|
88
|
+
return new STTError({
|
|
89
|
+
code: STT_ERROR_CODES.INVALID_AUDIO_FORMAT,
|
|
90
|
+
message,
|
|
91
|
+
category: ErrorCategory.VALIDATION,
|
|
92
|
+
severity: ErrorSeverity.MEDIUM,
|
|
93
|
+
retriable: false,
|
|
94
|
+
context: { format, supportedFormats, provider: actualProvider },
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Create an error for unsupported language
|
|
99
|
+
*/
|
|
100
|
+
static languageNotSupported(language, supportedLanguages, provider) {
|
|
101
|
+
const message = supportedLanguages
|
|
102
|
+
? `Language "${language}" is not supported. Supported languages: ${supportedLanguages.slice(0, 10).join(", ")}${supportedLanguages.length > 10 ? "..." : ""}`
|
|
103
|
+
: `Language "${language}" is not supported by this provider`;
|
|
104
|
+
return new STTError({
|
|
105
|
+
code: STT_ERROR_CODES.LANGUAGE_NOT_SUPPORTED,
|
|
106
|
+
message,
|
|
107
|
+
category: ErrorCategory.VALIDATION,
|
|
108
|
+
severity: ErrorSeverity.MEDIUM,
|
|
109
|
+
retriable: false,
|
|
110
|
+
context: { language, supportedLanguages, provider },
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Create an error for transcription failure
|
|
115
|
+
* Supports two signatures:
|
|
116
|
+
* - transcriptionFailed(reason, provider?, originalError?)
|
|
117
|
+
* - transcriptionFailed(reason, originalError, provider)
|
|
118
|
+
*/
|
|
119
|
+
static transcriptionFailed(reason, providerOrError, originalErrorOrProvider) {
|
|
120
|
+
let provider;
|
|
121
|
+
let originalError;
|
|
122
|
+
if (typeof providerOrError === "string") {
|
|
123
|
+
// Called as (reason, provider?, originalError?)
|
|
124
|
+
provider = providerOrError;
|
|
125
|
+
originalError =
|
|
126
|
+
originalErrorOrProvider instanceof Error
|
|
127
|
+
? originalErrorOrProvider
|
|
128
|
+
: undefined;
|
|
129
|
+
}
|
|
130
|
+
else if (providerOrError instanceof Error) {
|
|
131
|
+
// Called as (reason, originalError, provider)
|
|
132
|
+
originalError = providerOrError;
|
|
133
|
+
provider =
|
|
134
|
+
typeof originalErrorOrProvider === "string"
|
|
135
|
+
? originalErrorOrProvider
|
|
136
|
+
: undefined;
|
|
137
|
+
}
|
|
138
|
+
return new STTError({
|
|
139
|
+
code: STT_ERROR_CODES.TRANSCRIPTION_FAILED,
|
|
140
|
+
message: `Transcription failed: ${reason}`,
|
|
141
|
+
category: ErrorCategory.EXECUTION,
|
|
142
|
+
severity: ErrorSeverity.HIGH,
|
|
143
|
+
retriable: true,
|
|
144
|
+
context: { provider },
|
|
145
|
+
originalError,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Create an error for unconfigured provider
|
|
150
|
+
*/
|
|
151
|
+
static providerNotConfigured(provider) {
|
|
152
|
+
return new STTError({
|
|
153
|
+
code: STT_ERROR_CODES.PROVIDER_NOT_CONFIGURED,
|
|
154
|
+
message: `STT provider "${provider}" is not properly configured. Please set the required API keys.`,
|
|
155
|
+
category: ErrorCategory.CONFIGURATION,
|
|
156
|
+
severity: ErrorSeverity.HIGH,
|
|
157
|
+
retriable: false,
|
|
158
|
+
context: { provider },
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Create an error for unsupported provider
|
|
163
|
+
*/
|
|
164
|
+
static providerNotSupported(provider, availableProviders) {
|
|
165
|
+
return new STTError({
|
|
166
|
+
code: STT_ERROR_CODES.PROVIDER_NOT_SUPPORTED,
|
|
167
|
+
message: `STT provider "${provider}" is not supported`,
|
|
168
|
+
category: ErrorCategory.VALIDATION,
|
|
169
|
+
severity: ErrorSeverity.HIGH,
|
|
170
|
+
retriable: false,
|
|
171
|
+
context: { provider, availableProviders },
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Create an error for stream processing failure
|
|
176
|
+
*/
|
|
177
|
+
static streamError(reason, provider) {
|
|
178
|
+
return new STTError({
|
|
179
|
+
code: STT_ERROR_CODES.STREAM_ERROR,
|
|
180
|
+
message: `Stream processing error: ${reason}`,
|
|
181
|
+
category: ErrorCategory.EXECUTION,
|
|
182
|
+
severity: ErrorSeverity.HIGH,
|
|
183
|
+
retriable: true,
|
|
184
|
+
context: { provider },
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Alias for providerNotConfigured
|
|
189
|
+
*/
|
|
190
|
+
static notConfigured(provider) {
|
|
191
|
+
return STTError.providerNotConfigured(provider);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Alias for audioEmpty
|
|
195
|
+
*/
|
|
196
|
+
static emptyAudio(provider) {
|
|
197
|
+
return STTError.audioEmpty(provider);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Realtime Voice Error class for realtime-specific errors
|
|
202
|
+
*/
|
|
203
|
+
export class RealtimeError extends VoiceError {
|
|
204
|
+
constructor(options) {
|
|
205
|
+
super({
|
|
206
|
+
...options,
|
|
207
|
+
category: options.category ?? ErrorCategory.EXECUTION,
|
|
208
|
+
severity: options.severity ?? ErrorSeverity.HIGH,
|
|
209
|
+
retriable: options.retriable ?? false,
|
|
210
|
+
});
|
|
211
|
+
this.name = "RealtimeError";
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Create an error for connection failure
|
|
215
|
+
* Supports two signatures:
|
|
216
|
+
* - connectionFailed(reason, provider?, originalError?)
|
|
217
|
+
* - connectionFailed(reason, originalError?, provider?)
|
|
218
|
+
*/
|
|
219
|
+
static connectionFailed(reason, providerOrError, originalErrorOrProvider) {
|
|
220
|
+
let provider;
|
|
221
|
+
let originalError;
|
|
222
|
+
if (typeof providerOrError === "string") {
|
|
223
|
+
// Called as (reason, provider?, originalError?)
|
|
224
|
+
provider = providerOrError;
|
|
225
|
+
originalError =
|
|
226
|
+
originalErrorOrProvider instanceof Error
|
|
227
|
+
? originalErrorOrProvider
|
|
228
|
+
: undefined;
|
|
229
|
+
}
|
|
230
|
+
else if (providerOrError instanceof Error) {
|
|
231
|
+
// Called as (reason, originalError, provider)
|
|
232
|
+
originalError = providerOrError;
|
|
233
|
+
provider =
|
|
234
|
+
typeof originalErrorOrProvider === "string"
|
|
235
|
+
? originalErrorOrProvider
|
|
236
|
+
: undefined;
|
|
237
|
+
}
|
|
238
|
+
return new RealtimeError({
|
|
239
|
+
code: REALTIME_ERROR_CODES.CONNECTION_FAILED,
|
|
240
|
+
message: `Failed to connect to realtime service: ${reason}`,
|
|
241
|
+
category: ErrorCategory.NETWORK,
|
|
242
|
+
severity: ErrorSeverity.HIGH,
|
|
243
|
+
retriable: true,
|
|
244
|
+
context: { provider },
|
|
245
|
+
originalError,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Create an error for session timeout
|
|
250
|
+
*/
|
|
251
|
+
static sessionTimeout(timeoutMs, provider) {
|
|
252
|
+
return new RealtimeError({
|
|
253
|
+
code: REALTIME_ERROR_CODES.SESSION_TIMEOUT,
|
|
254
|
+
message: `Realtime session timed out after ${timeoutMs}ms`,
|
|
255
|
+
category: ErrorCategory.TIMEOUT,
|
|
256
|
+
severity: ErrorSeverity.MEDIUM,
|
|
257
|
+
retriable: true,
|
|
258
|
+
context: { timeoutMs, provider },
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Create an error for protocol errors
|
|
263
|
+
*/
|
|
264
|
+
static protocolError(reason, provider, originalError) {
|
|
265
|
+
return new RealtimeError({
|
|
266
|
+
code: REALTIME_ERROR_CODES.PROTOCOL_ERROR,
|
|
267
|
+
message: `Protocol error: ${reason}`,
|
|
268
|
+
category: ErrorCategory.EXECUTION,
|
|
269
|
+
severity: ErrorSeverity.HIGH,
|
|
270
|
+
retriable: false,
|
|
271
|
+
context: { provider },
|
|
272
|
+
originalError,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Create an error for audio stream failures
|
|
277
|
+
*/
|
|
278
|
+
static audioStreamError(reason, provider) {
|
|
279
|
+
return new RealtimeError({
|
|
280
|
+
code: REALTIME_ERROR_CODES.AUDIO_STREAM_ERROR,
|
|
281
|
+
message: `Audio stream error: ${reason}`,
|
|
282
|
+
category: ErrorCategory.EXECUTION,
|
|
283
|
+
severity: ErrorSeverity.HIGH,
|
|
284
|
+
retriable: true,
|
|
285
|
+
context: { provider },
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Create an error for unconfigured provider
|
|
290
|
+
*/
|
|
291
|
+
static providerNotConfigured(provider) {
|
|
292
|
+
return new RealtimeError({
|
|
293
|
+
code: REALTIME_ERROR_CODES.PROVIDER_NOT_CONFIGURED,
|
|
294
|
+
message: `Realtime provider "${provider}" is not properly configured. Please set the required API keys.`,
|
|
295
|
+
category: ErrorCategory.CONFIGURATION,
|
|
296
|
+
severity: ErrorSeverity.HIGH,
|
|
297
|
+
retriable: false,
|
|
298
|
+
context: { provider },
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Create an error for unsupported provider
|
|
303
|
+
*/
|
|
304
|
+
static providerNotSupported(provider, availableProviders) {
|
|
305
|
+
return new RealtimeError({
|
|
306
|
+
code: REALTIME_ERROR_CODES.PROVIDER_NOT_SUPPORTED,
|
|
307
|
+
message: `Realtime provider "${provider}" is not supported`,
|
|
308
|
+
category: ErrorCategory.VALIDATION,
|
|
309
|
+
severity: ErrorSeverity.HIGH,
|
|
310
|
+
retriable: false,
|
|
311
|
+
context: { provider, availableProviders },
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Create an error for duplicate session
|
|
316
|
+
*/
|
|
317
|
+
static sessionAlreadyActive(provider) {
|
|
318
|
+
return new RealtimeError({
|
|
319
|
+
code: REALTIME_ERROR_CODES.SESSION_ALREADY_ACTIVE,
|
|
320
|
+
message: "A realtime session is already active. Disconnect first.",
|
|
321
|
+
category: ErrorCategory.VALIDATION,
|
|
322
|
+
severity: ErrorSeverity.MEDIUM,
|
|
323
|
+
retriable: false,
|
|
324
|
+
context: { provider },
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Create an error for no active session
|
|
329
|
+
*/
|
|
330
|
+
static sessionNotActive(provider) {
|
|
331
|
+
return new RealtimeError({
|
|
332
|
+
code: REALTIME_ERROR_CODES.SESSION_NOT_ACTIVE,
|
|
333
|
+
message: "No active realtime session. Connect first.",
|
|
334
|
+
category: ErrorCategory.VALIDATION,
|
|
335
|
+
severity: ErrorSeverity.MEDIUM,
|
|
336
|
+
retriable: false,
|
|
337
|
+
context: { provider },
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Create an error for invalid messages
|
|
342
|
+
*/
|
|
343
|
+
static invalidMessage(reason, provider) {
|
|
344
|
+
return new RealtimeError({
|
|
345
|
+
code: REALTIME_ERROR_CODES.INVALID_MESSAGE,
|
|
346
|
+
message: `Invalid message: ${reason}`,
|
|
347
|
+
category: ErrorCategory.VALIDATION,
|
|
348
|
+
severity: ErrorSeverity.MEDIUM,
|
|
349
|
+
retriable: false,
|
|
350
|
+
context: { provider },
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Create an error for connection closed unexpectedly
|
|
355
|
+
*/
|
|
356
|
+
static connectionClosed(reason, sessionId, provider) {
|
|
357
|
+
return new RealtimeError({
|
|
358
|
+
code: REALTIME_ERROR_CODES.CONNECTION_FAILED,
|
|
359
|
+
message: `Connection closed: ${reason}`,
|
|
360
|
+
category: ErrorCategory.NETWORK,
|
|
361
|
+
severity: ErrorSeverity.HIGH,
|
|
362
|
+
retriable: true,
|
|
363
|
+
context: { sessionId, provider },
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Create an error for unconfigured provider (alias)
|
|
368
|
+
*/
|
|
369
|
+
static notConfigured(provider) {
|
|
370
|
+
return RealtimeError.providerNotConfigured(provider);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Create an error for operation timeout
|
|
374
|
+
*/
|
|
375
|
+
static timeout(operation, timeoutMs, provider) {
|
|
376
|
+
return new RealtimeError({
|
|
377
|
+
code: REALTIME_ERROR_CODES.SESSION_TIMEOUT,
|
|
378
|
+
message: `Operation "${operation}" timed out after ${timeoutMs}ms`,
|
|
379
|
+
category: ErrorCategory.TIMEOUT,
|
|
380
|
+
severity: ErrorSeverity.MEDIUM,
|
|
381
|
+
retriable: true,
|
|
382
|
+
context: { operation, timeoutMs, provider },
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voice Module - Unified Voice/Speech Integration for NeuroLink
|
|
3
|
+
*
|
|
4
|
+
* Provides TTS (Text-to-Speech), STT (Speech-to-Text), and
|
|
5
|
+
* Realtime Voice capabilities across multiple providers.
|
|
6
|
+
*
|
|
7
|
+
* Use TTSProcessor (src/lib/utils/ttsProcessor.ts) for TTS.
|
|
8
|
+
* Use STTProcessor (src/lib/utils/sttProcessor.ts) for STT.
|
|
9
|
+
* Use RealtimeProcessor for realtime voice sessions.
|
|
10
|
+
*
|
|
11
|
+
* @module voice
|
|
12
|
+
*/
|
|
13
|
+
export { AUDIO_FORMAT_DETAILS, DEFAULT_REALTIME_CONFIG, DEFAULT_STT_OPTIONS, isSTTResult, isTranscriptionSegment, isValidRealtimeConfig, isValidSTTOptions, REALTIME_ERROR_CODES, STT_ERROR_CODES, VOICE_ERROR_CODES, } from "../types/index.js";
|
|
14
|
+
export { RealtimeError, STTError, VoiceError } from "./errors.js";
|
|
15
|
+
export { BaseRealtimeHandler, RealtimeProcessor } from "./RealtimeVoiceAPI.js";
|
|
16
|
+
export { AUDIO_SIGNATURES, calculateDuration, convertAudioFormat, createPcmBuffer, createWavFile, createWavHeader, detectAudioFormat, extractPcmSamples, getFileExtension, getMimeType, MIME_TYPES, normalizeAudio, resamplePcm, splitIntoChunks, } from "./audio-utils.js";
|
|
17
|
+
export { asyncIterableToStream, ChunkedAudioStream, StreamHandler, StreamMerger, StreamSplitter, streamToAsyncIterable, } from "./stream-handler.js";
|
|
18
|
+
export { AzureTTS, AzureTTS as AzureTTSHandler } from "./providers/AzureTTS.js";
|
|
19
|
+
export { ElevenLabsTTS, ElevenLabsTTS as ElevenLabsTTSHandler, } from "./providers/ElevenLabsTTS.js";
|
|
20
|
+
export { OpenAITTS, OpenAITTS as OpenAITTSHandler, } from "./providers/OpenAITTS.js";
|
|
21
|
+
export { AzureSTT, AzureSTT as AzureSTTHandler } from "./providers/AzureSTT.js";
|
|
22
|
+
export { DeepgramSTT, DeepgramSTT as DeepgramSTTHandler, } from "./providers/DeepgramSTT.js";
|
|
23
|
+
export { GoogleSTT, GoogleSTT as GoogleSTTHandler, } from "./providers/GoogleSTT.js";
|
|
24
|
+
export { OpenAISTT, OpenAISTTHandler, WhisperSTT, WhisperSTTHandler, } from "./providers/OpenAISTT.js";
|
|
25
|
+
export { GeminiLive, GeminiLive as GeminiLiveHandler, } from "./providers/GeminiLive.js";
|
|
26
|
+
export { OpenAIRealtime, OpenAIRealtime as OpenAIRealtimeHandler, } from "./providers/OpenAIRealtime.js";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voice Module - Unified Voice/Speech Integration for NeuroLink
|
|
3
|
+
*
|
|
4
|
+
* Provides TTS (Text-to-Speech), STT (Speech-to-Text), and
|
|
5
|
+
* Realtime Voice capabilities across multiple providers.
|
|
6
|
+
*
|
|
7
|
+
* Use TTSProcessor (src/lib/utils/ttsProcessor.ts) for TTS.
|
|
8
|
+
* Use STTProcessor (src/lib/utils/sttProcessor.ts) for STT.
|
|
9
|
+
* Use RealtimeProcessor for realtime voice sessions.
|
|
10
|
+
*
|
|
11
|
+
* @module voice
|
|
12
|
+
*/
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// ERROR CODES AND CONSTANTS
|
|
15
|
+
// ============================================================================
|
|
16
|
+
export { AUDIO_FORMAT_DETAILS, DEFAULT_REALTIME_CONFIG, DEFAULT_STT_OPTIONS,
|
|
17
|
+
// Type guards
|
|
18
|
+
isSTTResult, isTranscriptionSegment, isValidRealtimeConfig, isValidSTTOptions, REALTIME_ERROR_CODES, STT_ERROR_CODES, VOICE_ERROR_CODES, } from "../types/index.js";
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// ERRORS
|
|
21
|
+
// ============================================================================
|
|
22
|
+
export { RealtimeError, STTError, VoiceError } from "./errors.js";
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// REALTIME VOICE API
|
|
25
|
+
// ============================================================================
|
|
26
|
+
export { BaseRealtimeHandler, RealtimeProcessor } from "./RealtimeVoiceAPI.js";
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// AUDIO UTILITIES
|
|
29
|
+
// ============================================================================
|
|
30
|
+
export { AUDIO_SIGNATURES, calculateDuration, convertAudioFormat, createPcmBuffer, createWavFile, createWavHeader, detectAudioFormat, extractPcmSamples, getFileExtension, getMimeType, MIME_TYPES, normalizeAudio, resamplePcm, splitIntoChunks, } from "./audio-utils.js";
|
|
31
|
+
// ============================================================================
|
|
32
|
+
// STREAM HANDLER
|
|
33
|
+
// ============================================================================
|
|
34
|
+
export { asyncIterableToStream, ChunkedAudioStream, StreamHandler, StreamMerger, StreamSplitter, streamToAsyncIterable, } from "./stream-handler.js";
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// TTS PROVIDERS
|
|
37
|
+
// ============================================================================
|
|
38
|
+
export { AzureTTS, AzureTTS as AzureTTSHandler } from "./providers/AzureTTS.js";
|
|
39
|
+
export { ElevenLabsTTS, ElevenLabsTTS as ElevenLabsTTSHandler, } from "./providers/ElevenLabsTTS.js";
|
|
40
|
+
export { OpenAITTS, OpenAITTS as OpenAITTSHandler, } from "./providers/OpenAITTS.js";
|
|
41
|
+
// ============================================================================
|
|
42
|
+
// STT PROVIDERS
|
|
43
|
+
// ============================================================================
|
|
44
|
+
export { AzureSTT, AzureSTT as AzureSTTHandler } from "./providers/AzureSTT.js";
|
|
45
|
+
export { DeepgramSTT, DeepgramSTT as DeepgramSTTHandler, } from "./providers/DeepgramSTT.js";
|
|
46
|
+
// Export STT provider classes for direct use
|
|
47
|
+
export { GoogleSTT, GoogleSTT as GoogleSTTHandler, } from "./providers/GoogleSTT.js";
|
|
48
|
+
export { OpenAISTT, OpenAISTTHandler, WhisperSTT, WhisperSTTHandler, } from "./providers/OpenAISTT.js";
|
|
49
|
+
// ============================================================================
|
|
50
|
+
// REALTIME PROVIDERS
|
|
51
|
+
// ============================================================================
|
|
52
|
+
export { GeminiLive, GeminiLive as GeminiLiveHandler, } from "./providers/GeminiLive.js";
|
|
53
|
+
// Export Realtime provider classes for direct use
|
|
54
|
+
export { OpenAIRealtime, OpenAIRealtime as OpenAIRealtimeHandler, } from "./providers/OpenAIRealtime.js";
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Azure Cognitive Services Speech-to-Text Handler
|
|
3
|
+
*
|
|
4
|
+
* Implementation of STT using Azure Speech Services.
|
|
5
|
+
*
|
|
6
|
+
* @module voice/providers/AzureSTT
|
|
7
|
+
*/
|
|
8
|
+
import type { TTSAudioFormat, STTHandler, STTLanguage, STTOptions, STTResult, TranscriptionSegment } from "../../types/index.js";
|
|
9
|
+
/**
|
|
10
|
+
* Azure Cognitive Services Speech-to-Text Handler
|
|
11
|
+
*
|
|
12
|
+
* Supports speech recognition with custom models and detailed output.
|
|
13
|
+
*
|
|
14
|
+
* @see https://docs.microsoft.com/azure/cognitive-services/speech-service/
|
|
15
|
+
*/
|
|
16
|
+
export declare class AzureSTT implements STTHandler {
|
|
17
|
+
private readonly apiKey;
|
|
18
|
+
private readonly region;
|
|
19
|
+
/**
|
|
20
|
+
* Maximum audio duration in seconds (60s — Azure's REST API for short audio
|
|
21
|
+
* documented limit on `/speech/recognition/conversation/cognitiveservices/v1`).
|
|
22
|
+
* For longer audio, use Azure Batch Transcription (not yet implemented) or
|
|
23
|
+
* pre-segment the input.
|
|
24
|
+
*/
|
|
25
|
+
readonly maxAudioDuration = 60;
|
|
26
|
+
/**
|
|
27
|
+
* Azure STT implementation buffers chunks via REST — not true streaming
|
|
28
|
+
*/
|
|
29
|
+
readonly supportsStreaming = false;
|
|
30
|
+
constructor(apiKey?: string, region?: string);
|
|
31
|
+
isConfigured(): boolean;
|
|
32
|
+
getSupportedFormats(): TTSAudioFormat[];
|
|
33
|
+
getSupportedLanguages(): Promise<STTLanguage[]>;
|
|
34
|
+
transcribe(audio: Buffer | ArrayBuffer, options?: STTOptions): Promise<STTResult>;
|
|
35
|
+
/**
|
|
36
|
+
* Streaming transcription (placeholder - requires SDK)
|
|
37
|
+
*/
|
|
38
|
+
transcribeStream(audioStream: AsyncIterable<Buffer>, options: STTOptions): AsyncIterable<TranscriptionSegment>;
|
|
39
|
+
/**
|
|
40
|
+
* Get Content-Type header for audio format
|
|
41
|
+
*/
|
|
42
|
+
private getContentType;
|
|
43
|
+
/**
|
|
44
|
+
* Convert Azure ticks (100ns units) to seconds
|
|
45
|
+
*/
|
|
46
|
+
private ticksToSeconds;
|
|
47
|
+
}
|