@volley/recognition-client-sdk 0.1.417 → 0.1.419

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.
Files changed (37) hide show
  1. package/dist/index.js +14 -10
  2. package/dist/index.js.map +2 -2
  3. package/package.json +3 -3
  4. package/src/index.ts +2 -0
  5. package/src/simplified-vgf-recognition-client.ts +5 -14
  6. package/src/vgf-recognition-mapper.spec.ts +78 -0
  7. package/src/vgf-recognition-mapper.ts +29 -0
  8. package/dist/browser.bundled.d.ts +0 -1185
  9. package/dist/browser.d.ts +0 -10
  10. package/dist/browser.d.ts.map +0 -1
  11. package/dist/config-builder.d.ts +0 -134
  12. package/dist/config-builder.d.ts.map +0 -1
  13. package/dist/errors.d.ts +0 -41
  14. package/dist/errors.d.ts.map +0 -1
  15. package/dist/factory.d.ts +0 -36
  16. package/dist/factory.d.ts.map +0 -1
  17. package/dist/index.bundled.d.ts +0 -2371
  18. package/dist/index.d.ts +0 -15
  19. package/dist/index.d.ts.map +0 -1
  20. package/dist/recog-client-sdk.browser.d.ts +0 -10
  21. package/dist/recog-client-sdk.browser.d.ts.map +0 -1
  22. package/dist/recognition-client.d.ts +0 -124
  23. package/dist/recognition-client.d.ts.map +0 -1
  24. package/dist/recognition-client.types.d.ts +0 -271
  25. package/dist/recognition-client.types.d.ts.map +0 -1
  26. package/dist/simplified-vgf-recognition-client.d.ts +0 -178
  27. package/dist/simplified-vgf-recognition-client.d.ts.map +0 -1
  28. package/dist/utils/audio-ring-buffer.d.ts +0 -69
  29. package/dist/utils/audio-ring-buffer.d.ts.map +0 -1
  30. package/dist/utils/message-handler.d.ts +0 -45
  31. package/dist/utils/message-handler.d.ts.map +0 -1
  32. package/dist/utils/url-builder.d.ts +0 -28
  33. package/dist/utils/url-builder.d.ts.map +0 -1
  34. package/dist/vgf-recognition-mapper.d.ts +0 -49
  35. package/dist/vgf-recognition-mapper.d.ts.map +0 -1
  36. package/dist/vgf-recognition-state.d.ts +0 -91
  37. package/dist/vgf-recognition-state.d.ts.map +0 -1
@@ -1,2371 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- /**
4
- * Provider types and enums for recognition services
5
- * NOTE_TO_AI: DO NOT CHANGE THIS UNLESS EXPLICITLY ASKED. Always ask before making any changes.
6
- */
7
- /**
8
- * Supported speech recognition providers
9
- */
10
- declare enum RecognitionProvider {
11
- ASSEMBLYAI = "assemblyai",
12
- DEEPGRAM = "deepgram",
13
- ELEVENLABS = "elevenlabs",
14
- FIREWORKS = "fireworks",
15
- GOOGLE = "google",
16
- GEMINI_BATCH = "gemini-batch",
17
- OPENAI_BATCH = "openai-batch",
18
- OPENAI_REALTIME = "openai-realtime"
19
- }
20
- /**
21
- * ASR API type - distinguishes between streaming and file-based transcription APIs
22
- * - STREAMING: Real-time streaming APIs (Deepgram, AssemblyAI, Google)
23
- * - FILE_BASED: File upload/batch APIs (OpenAI Batch, Gemini Batch)
24
- */
25
- declare enum ASRApiType {
26
- STREAMING = "streaming",
27
- FILE_BASED = "file-based"
28
- }
29
- /**
30
- * Deepgram model names
31
- */
32
- declare enum DeepgramModel {
33
- NOVA_2 = "nova-2",
34
- NOVA_3 = "nova-3",
35
- FLUX_GENERAL_EN = "flux-general-en"
36
- }
37
- /**
38
- * Google Cloud Speech models
39
- * @see https://cloud.google.com/speech-to-text/docs/transcription-model
40
- * @see https://cloud.google.com/speech-to-text/v2/docs/chirp_3-model
41
- */
42
- declare enum GoogleModel {
43
- CHIRP_3 = "chirp_3",
44
- CHIRP_2 = "chirp_2",
45
- CHIRP = "chirp",
46
- LATEST_LONG = "latest_long",
47
- LATEST_SHORT = "latest_short",
48
- TELEPHONY = "telephony",
49
- TELEPHONY_SHORT = "telephony_short",
50
- DEFAULT = "default",
51
- COMMAND_AND_SEARCH = "command_and_search",
52
- PHONE_CALL = "phone_call",
53
- VIDEO = "video"
54
- }
55
- /**
56
- * Fireworks AI models for ASR
57
- * @see https://docs.fireworks.ai/guides/querying-asr-models
58
- * @see https://fireworks.ai/models/fireworks/fireworks-asr-large
59
- */
60
- declare enum FireworksModel {
61
- ASR_V1 = "fireworks-asr-large",
62
- ASR_V2 = "fireworks-asr-v2",
63
- WHISPER_V3 = "whisper-v3",
64
- WHISPER_V3_TURBO = "whisper-v3-turbo"
65
- }
66
- /**
67
- * ElevenLabs Scribe models for speech-to-text
68
- * @see https://elevenlabs.io/blog/introducing-scribe-v2-realtime
69
- * @see https://elevenlabs.io/docs/cookbooks/speech-to-text/streaming
70
- * @see https://elevenlabs.io/docs/api-reference/speech-to-text/convert
71
- */
72
- declare enum ElevenLabsModel {
73
- SCRIBE_V2_REALTIME = "scribe_v2_realtime",
74
- SCRIBE_V1 = "scribe_v1"
75
- }
76
- /**
77
- * OpenAI Realtime API transcription models
78
- * These are the verified `input_audio_transcription.model` values.
79
- * @see https://platform.openai.com/docs/guides/realtime
80
- */
81
- declare enum OpenAIRealtimeModel {
82
- GPT_4O_MINI_TRANSCRIBE = "gpt-4o-mini-transcribe"
83
- }
84
- /**
85
- * Type alias for any model from any provider
86
- */
87
- type RecognitionModel = DeepgramModel | GoogleModel | FireworksModel | ElevenLabsModel | OpenAIRealtimeModel | string;
88
-
89
- /**
90
- * Audio encoding types
91
- */
92
- declare enum AudioEncoding {
93
- ENCODING_UNSPECIFIED = 0,
94
- LINEAR16 = 1,
95
- OGG_OPUS = 2,
96
- FLAC = 3,
97
- MULAW = 4,
98
- ALAW = 5
99
- }
100
- declare namespace AudioEncoding {
101
- /**
102
- * Convert numeric ID to AudioEncoding enum
103
- * @param id - Numeric encoding identifier (0-5)
104
- * @returns AudioEncoding enum value or undefined if invalid
105
- */
106
- function fromId(id: number): AudioEncoding | undefined;
107
- /**
108
- * Convert string name to AudioEncoding enum
109
- * @param nameStr - String name like "linear16", "LINEAR16", "ogg_opus", "OGG_OPUS", etc. (case insensitive)
110
- * @returns AudioEncoding enum value or undefined if invalid
111
- */
112
- function fromName(nameStr: string): AudioEncoding | undefined;
113
- /**
114
- * Convert AudioEncoding enum to numeric ID
115
- * @param encoding - AudioEncoding enum value
116
- * @returns Numeric ID (0-5)
117
- */
118
- function toId(encoding: AudioEncoding): number;
119
- /**
120
- * Convert AudioEncoding enum to string name
121
- * @param encoding - AudioEncoding enum value
122
- * @returns String name like "LINEAR16", "MULAW", etc.
123
- */
124
- function toName(encoding: AudioEncoding): string;
125
- /**
126
- * Check if a numeric ID is a valid encoding
127
- * @param id - Numeric identifier to validate
128
- * @returns true if valid encoding ID
129
- */
130
- function isIdValid(id: number): boolean;
131
- /**
132
- * Check if a string name is a valid encoding
133
- * @param nameStr - String name to validate
134
- * @returns true if valid encoding name
135
- */
136
- function isNameValid(nameStr: string): boolean;
137
- }
138
- /**
139
- * Common sample rates (in Hz)
140
- */
141
- declare enum SampleRate {
142
- RATE_8000 = 8000,
143
- RATE_16000 = 16000,
144
- RATE_22050 = 22050,
145
- RATE_24000 = 24000,
146
- RATE_32000 = 32000,
147
- RATE_44100 = 44100,
148
- RATE_48000 = 48000
149
- }
150
- declare namespace SampleRate {
151
- /**
152
- * Convert Hz value to SampleRate enum
153
- * @param hz - Sample rate in Hz (8000, 16000, etc.)
154
- * @returns SampleRate enum value or undefined if invalid
155
- */
156
- function fromHz(hz: number): SampleRate | undefined;
157
- /**
158
- * Convert string name to SampleRate enum
159
- * @param nameStr - String name like "rate_8000", "RATE_16000", etc. (case insensitive)
160
- * @returns SampleRate enum value or undefined if invalid
161
- */
162
- function fromName(nameStr: string): SampleRate | undefined;
163
- /**
164
- * Convert SampleRate enum to Hz value
165
- * @param rate - SampleRate enum value
166
- * @returns Hz value (8000, 16000, etc.)
167
- */
168
- function toHz(rate: SampleRate): number;
169
- /**
170
- * Convert SampleRate enum to string name
171
- * @param rate - SampleRate enum value
172
- * @returns String name like "RATE_8000", "RATE_16000", etc.
173
- */
174
- function toName(rate: SampleRate): string;
175
- /**
176
- * Check if a numeric Hz value is a valid sample rate
177
- * @param hz - Hz value to validate
178
- * @returns true if valid sample rate
179
- */
180
- function isHzValid(hz: number): boolean;
181
- /**
182
- * Check if a string name is a valid sample rate
183
- * @param nameStr - String name to validate
184
- * @returns true if valid sample rate name
185
- */
186
- function isNameValid(nameStr: string): boolean;
187
- }
188
- /**
189
- * Supported languages for recognition
190
- * Using BCP-47 language tags
191
- */
192
- declare enum Language {
193
- ENGLISH_US = "en-US",
194
- ENGLISH_GB = "en-GB",
195
- SPANISH_ES = "es-ES",
196
- SPANISH_MX = "es-MX",
197
- FRENCH_FR = "fr-FR",
198
- GERMAN_DE = "de-DE",
199
- ITALIAN_IT = "it-IT",
200
- PORTUGUESE_BR = "pt-BR",
201
- JAPANESE_JP = "ja-JP",
202
- KOREAN_KR = "ko-KR",
203
- CHINESE_CN = "zh-CN",
204
- CHINESE_TW = "zh-TW"
205
- }
206
-
207
- /**
208
- * Recognition Result Types V1
209
- * NOTE_TO_AI: DO NOT CHANGE THIS UNLESS EXPLICITLY ASKED. Always ask before making any changes.
210
- * Types and schemas for recognition results sent to SDK clients
211
- */
212
-
213
- /**
214
- * Message type discriminator for recognition results V1
215
- */
216
- declare enum RecognitionResultTypeV1 {
217
- TRANSCRIPTION = "Transcription",
218
- FUNCTION_CALL = "FunctionCall",
219
- METADATA = "Metadata",
220
- ERROR = "Error",
221
- CLIENT_CONTROL_MESSAGE = "ClientControlMessage",
222
- AUDIO_METRICS = "AudioMetrics"
223
- }
224
- /**
225
- * Transcription result V1 - contains transcript message
226
- * In the long run game side should not need to know it. In the short run it is send back to client.
227
- * NOTE_TO_AI: DO NOT CHANGE THIS UNLESS EXPLICITLY ASKED. Always ask before making any changes.
228
- */
229
- declare const TranscriptionResultSchemaV1: z.ZodObject<{
230
- type: z.ZodLiteral<RecognitionResultTypeV1.TRANSCRIPTION>;
231
- audioUtteranceId: z.ZodString;
232
- finalTranscript: z.ZodString;
233
- finalTranscriptConfidence: z.ZodOptional<z.ZodNumber>;
234
- pendingTranscript: z.ZodOptional<z.ZodString>;
235
- pendingTranscriptConfidence: z.ZodOptional<z.ZodNumber>;
236
- is_finished: z.ZodBoolean;
237
- voiceStart: z.ZodOptional<z.ZodNumber>;
238
- voiceDuration: z.ZodOptional<z.ZodNumber>;
239
- voiceEnd: z.ZodOptional<z.ZodNumber>;
240
- startTimestamp: z.ZodOptional<z.ZodNumber>;
241
- endTimestamp: z.ZodOptional<z.ZodNumber>;
242
- receivedAtMs: z.ZodOptional<z.ZodNumber>;
243
- accumulatedAudioTimeMs: z.ZodOptional<z.ZodNumber>;
244
- }, "strip", z.ZodTypeAny, {
245
- type: RecognitionResultTypeV1.TRANSCRIPTION;
246
- audioUtteranceId: string;
247
- finalTranscript: string;
248
- is_finished: boolean;
249
- finalTranscriptConfidence?: number | undefined;
250
- pendingTranscript?: string | undefined;
251
- pendingTranscriptConfidence?: number | undefined;
252
- voiceStart?: number | undefined;
253
- voiceDuration?: number | undefined;
254
- voiceEnd?: number | undefined;
255
- startTimestamp?: number | undefined;
256
- endTimestamp?: number | undefined;
257
- receivedAtMs?: number | undefined;
258
- accumulatedAudioTimeMs?: number | undefined;
259
- }, {
260
- type: RecognitionResultTypeV1.TRANSCRIPTION;
261
- audioUtteranceId: string;
262
- finalTranscript: string;
263
- is_finished: boolean;
264
- finalTranscriptConfidence?: number | undefined;
265
- pendingTranscript?: string | undefined;
266
- pendingTranscriptConfidence?: number | undefined;
267
- voiceStart?: number | undefined;
268
- voiceDuration?: number | undefined;
269
- voiceEnd?: number | undefined;
270
- startTimestamp?: number | undefined;
271
- endTimestamp?: number | undefined;
272
- receivedAtMs?: number | undefined;
273
- accumulatedAudioTimeMs?: number | undefined;
274
- }>;
275
- type TranscriptionResultV1 = z.infer<typeof TranscriptionResultSchemaV1>;
276
- /**
277
- * Function call result V1 - similar to LLM function call
278
- * In the long run game server should know it, rather than TV or client.
279
- */
280
- declare const FunctionCallResultSchemaV1: z.ZodObject<{
281
- type: z.ZodLiteral<RecognitionResultTypeV1.FUNCTION_CALL>;
282
- audioUtteranceId: z.ZodString;
283
- functionName: z.ZodString;
284
- functionArgJson: z.ZodString;
285
- }, "strip", z.ZodTypeAny, {
286
- type: RecognitionResultTypeV1.FUNCTION_CALL;
287
- audioUtteranceId: string;
288
- functionName: string;
289
- functionArgJson: string;
290
- }, {
291
- type: RecognitionResultTypeV1.FUNCTION_CALL;
292
- audioUtteranceId: string;
293
- functionName: string;
294
- functionArgJson: string;
295
- }>;
296
- type FunctionCallResultV1 = z.infer<typeof FunctionCallResultSchemaV1>;
297
- /**
298
- * Transcript outcome type - categorizes final transcript state
299
- * Used in Metadata schema. Maps 1:1 with Datadog metrics:
300
- * - WITH_CONTENT → recog.client.websocket.transcript.final_with_content
301
- * - EMPTY → recog.client.websocket.transcript.final_empty
302
- * - NEVER_SENT → derived from sessions.streamed - final_with_content - final_empty
303
- */
304
- declare enum TranscriptOutcomeType {
305
- WITH_CONTENT = "with_content",
306
- EMPTY = "empty",
307
- NEVER_SENT = "never_sent"
308
- }
309
- /**
310
- * Metadata result V1 - contains metadata, timing information, and ASR config
311
- * Sent when the provider connection closes to provide final timing metrics and config
312
- * In the long run game server should know it, rather than TV or client.
313
- */
314
- declare const MetadataResultSchemaV1: z.ZodObject<{
315
- type: z.ZodLiteral<RecognitionResultTypeV1.METADATA>;
316
- audioUtteranceId: z.ZodString;
317
- recordingStartMs: z.ZodOptional<z.ZodNumber>;
318
- recordingEndMs: z.ZodOptional<z.ZodNumber>;
319
- transcriptEndMs: z.ZodOptional<z.ZodNumber>;
320
- socketCloseAtMs: z.ZodOptional<z.ZodNumber>;
321
- duration: z.ZodOptional<z.ZodNumber>;
322
- volume: z.ZodOptional<z.ZodNumber>;
323
- accumulatedAudioTimeMs: z.ZodOptional<z.ZodNumber>;
324
- costInUSD: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
325
- apiType: z.ZodOptional<z.ZodNativeEnum<typeof ASRApiType>>;
326
- asrConfig: z.ZodOptional<z.ZodString>;
327
- rawAsrMetadata: z.ZodOptional<z.ZodString>;
328
- transcriptOutcome: z.ZodOptional<z.ZodNativeEnum<typeof TranscriptOutcomeType>>;
329
- }, "strip", z.ZodTypeAny, {
330
- type: RecognitionResultTypeV1.METADATA;
331
- audioUtteranceId: string;
332
- recordingStartMs?: number | undefined;
333
- recordingEndMs?: number | undefined;
334
- transcriptEndMs?: number | undefined;
335
- socketCloseAtMs?: number | undefined;
336
- duration?: number | undefined;
337
- volume?: number | undefined;
338
- accumulatedAudioTimeMs?: number | undefined;
339
- costInUSD?: number | undefined;
340
- apiType?: ASRApiType | undefined;
341
- asrConfig?: string | undefined;
342
- rawAsrMetadata?: string | undefined;
343
- transcriptOutcome?: TranscriptOutcomeType | undefined;
344
- }, {
345
- type: RecognitionResultTypeV1.METADATA;
346
- audioUtteranceId: string;
347
- recordingStartMs?: number | undefined;
348
- recordingEndMs?: number | undefined;
349
- transcriptEndMs?: number | undefined;
350
- socketCloseAtMs?: number | undefined;
351
- duration?: number | undefined;
352
- volume?: number | undefined;
353
- accumulatedAudioTimeMs?: number | undefined;
354
- costInUSD?: number | undefined;
355
- apiType?: ASRApiType | undefined;
356
- asrConfig?: string | undefined;
357
- rawAsrMetadata?: string | undefined;
358
- transcriptOutcome?: TranscriptOutcomeType | undefined;
359
- }>;
360
- type MetadataResultV1 = z.infer<typeof MetadataResultSchemaV1>;
361
- /**
362
- * Error type enum V1 - categorizes different types of errors
363
- */
364
- declare enum ErrorTypeV1 {
365
- AUTHENTICATION_ERROR = "authentication_error",
366
- VALIDATION_ERROR = "validation_error",
367
- PROVIDER_ERROR = "provider_error",
368
- TIMEOUT_ERROR = "timeout_error",
369
- QUOTA_EXCEEDED = "quota_exceeded",
370
- CONNECTION_ERROR = "connection_error",
371
- UNKNOWN_ERROR = "unknown_error"
372
- }
373
- /**
374
- * Error result V1 - contains error message
375
- * In the long run game server should know it, rather than TV or client.
376
- */
377
- declare const ErrorResultSchemaV1: z.ZodObject<{
378
- type: z.ZodLiteral<RecognitionResultTypeV1.ERROR>;
379
- audioUtteranceId: z.ZodString;
380
- errorType: z.ZodOptional<z.ZodNativeEnum<typeof ErrorTypeV1>>;
381
- message: z.ZodOptional<z.ZodString>;
382
- code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
383
- description: z.ZodOptional<z.ZodString>;
384
- }, "strip", z.ZodTypeAny, {
385
- type: RecognitionResultTypeV1.ERROR;
386
- audioUtteranceId: string;
387
- errorType?: ErrorTypeV1 | undefined;
388
- message?: string | undefined;
389
- code?: string | number | undefined;
390
- description?: string | undefined;
391
- }, {
392
- type: RecognitionResultTypeV1.ERROR;
393
- audioUtteranceId: string;
394
- errorType?: ErrorTypeV1 | undefined;
395
- message?: string | undefined;
396
- code?: string | number | undefined;
397
- description?: string | undefined;
398
- }>;
399
- type ErrorResultV1 = z.infer<typeof ErrorResultSchemaV1>;
400
- /**
401
- * Client control actions enum V1
402
- * Actions that can be sent from server to client to control the recognition stream
403
- * In the long run audio client(mic) should know it, rather than servers.
404
- */
405
- declare enum ClientControlActionV1 {
406
- READY_FOR_UPLOADING_RECORDING = "ready_for_uploading_recording",
407
- STOP_RECORDING = "stop_recording"
408
- }
409
-
410
- /**
411
- * Error Exception Types
412
- *
413
- * Defines structured exception types for each ErrorTypeV1 category.
414
- * Each exception type has metadata about whether it's immediately available
415
- * (can be shown to user right away vs needs investigation/retry).
416
- */
417
-
418
- /**
419
- * Authentication/Authorization Error
420
- * isImmediatelyAvailable: false
421
- * These are system configuration issues, not user-facing
422
- */
423
- declare const AuthenticationExceptionSchema: z.ZodObject<{
424
- code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
425
- message: z.ZodString;
426
- provider: z.ZodOptional<z.ZodNativeEnum<typeof RecognitionProvider>>;
427
- description: z.ZodOptional<z.ZodString>;
428
- audioUtteranceId: z.ZodOptional<z.ZodString>;
429
- timestamp: z.ZodOptional<z.ZodNumber>;
430
- errorType: z.ZodLiteral<ErrorTypeV1.AUTHENTICATION_ERROR>;
431
- isImmediatelyAvailable: z.ZodLiteral<false>;
432
- service: z.ZodOptional<z.ZodString>;
433
- authMethod: z.ZodOptional<z.ZodString>;
434
- }, "strip", z.ZodTypeAny, {
435
- message: string;
436
- errorType: ErrorTypeV1.AUTHENTICATION_ERROR;
437
- isImmediatelyAvailable: false;
438
- code?: string | number | undefined;
439
- provider?: RecognitionProvider | undefined;
440
- description?: string | undefined;
441
- audioUtteranceId?: string | undefined;
442
- timestamp?: number | undefined;
443
- service?: string | undefined;
444
- authMethod?: string | undefined;
445
- }, {
446
- message: string;
447
- errorType: ErrorTypeV1.AUTHENTICATION_ERROR;
448
- isImmediatelyAvailable: false;
449
- code?: string | number | undefined;
450
- provider?: RecognitionProvider | undefined;
451
- description?: string | undefined;
452
- audioUtteranceId?: string | undefined;
453
- timestamp?: number | undefined;
454
- service?: string | undefined;
455
- authMethod?: string | undefined;
456
- }>;
457
- type AuthenticationException = z.infer<typeof AuthenticationExceptionSchema>;
458
- /**
459
- * Validation Error
460
- * isImmediatelyAvailable: true
461
- * User provided invalid input - can show them what's wrong
462
- */
463
- declare const ValidationExceptionSchema: z.ZodObject<{
464
- code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
465
- message: z.ZodString;
466
- provider: z.ZodOptional<z.ZodNativeEnum<typeof RecognitionProvider>>;
467
- description: z.ZodOptional<z.ZodString>;
468
- audioUtteranceId: z.ZodOptional<z.ZodString>;
469
- timestamp: z.ZodOptional<z.ZodNumber>;
470
- errorType: z.ZodLiteral<ErrorTypeV1.VALIDATION_ERROR>;
471
- isImmediatelyAvailable: z.ZodLiteral<true>;
472
- field: z.ZodOptional<z.ZodString>;
473
- expected: z.ZodOptional<z.ZodString>;
474
- received: z.ZodOptional<z.ZodString>;
475
- }, "strip", z.ZodTypeAny, {
476
- message: string;
477
- errorType: ErrorTypeV1.VALIDATION_ERROR;
478
- isImmediatelyAvailable: true;
479
- code?: string | number | undefined;
480
- provider?: RecognitionProvider | undefined;
481
- description?: string | undefined;
482
- audioUtteranceId?: string | undefined;
483
- timestamp?: number | undefined;
484
- field?: string | undefined;
485
- expected?: string | undefined;
486
- received?: string | undefined;
487
- }, {
488
- message: string;
489
- errorType: ErrorTypeV1.VALIDATION_ERROR;
490
- isImmediatelyAvailable: true;
491
- code?: string | number | undefined;
492
- provider?: RecognitionProvider | undefined;
493
- description?: string | undefined;
494
- audioUtteranceId?: string | undefined;
495
- timestamp?: number | undefined;
496
- field?: string | undefined;
497
- expected?: string | undefined;
498
- received?: string | undefined;
499
- }>;
500
- type ValidationException = z.infer<typeof ValidationExceptionSchema>;
501
- /**
502
- * Provider Error
503
- * isImmediatelyAvailable: false
504
- * Error from ASR provider - usually transient or needs investigation
505
- */
506
- declare const ProviderExceptionSchema: z.ZodObject<{
507
- code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
508
- message: z.ZodString;
509
- description: z.ZodOptional<z.ZodString>;
510
- audioUtteranceId: z.ZodOptional<z.ZodString>;
511
- timestamp: z.ZodOptional<z.ZodNumber>;
512
- errorType: z.ZodLiteral<ErrorTypeV1.PROVIDER_ERROR>;
513
- isImmediatelyAvailable: z.ZodLiteral<false>;
514
- provider: z.ZodOptional<z.ZodString>;
515
- providerErrorCode: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
516
- isTransient: z.ZodOptional<z.ZodBoolean>;
517
- }, "strip", z.ZodTypeAny, {
518
- message: string;
519
- errorType: ErrorTypeV1.PROVIDER_ERROR;
520
- isImmediatelyAvailable: false;
521
- code?: string | number | undefined;
522
- description?: string | undefined;
523
- audioUtteranceId?: string | undefined;
524
- timestamp?: number | undefined;
525
- provider?: string | undefined;
526
- providerErrorCode?: string | number | undefined;
527
- isTransient?: boolean | undefined;
528
- }, {
529
- message: string;
530
- errorType: ErrorTypeV1.PROVIDER_ERROR;
531
- isImmediatelyAvailable: false;
532
- code?: string | number | undefined;
533
- description?: string | undefined;
534
- audioUtteranceId?: string | undefined;
535
- timestamp?: number | undefined;
536
- provider?: string | undefined;
537
- providerErrorCode?: string | number | undefined;
538
- isTransient?: boolean | undefined;
539
- }>;
540
- type ProviderException = z.infer<typeof ProviderExceptionSchema>;
541
- /**
542
- * Timeout Error
543
- * isImmediatelyAvailable: true
544
- * Request took too long - user should try again
545
- */
546
- declare const TimeoutExceptionSchema: z.ZodObject<{
547
- code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
548
- message: z.ZodString;
549
- provider: z.ZodOptional<z.ZodNativeEnum<typeof RecognitionProvider>>;
550
- description: z.ZodOptional<z.ZodString>;
551
- audioUtteranceId: z.ZodOptional<z.ZodString>;
552
- timestamp: z.ZodOptional<z.ZodNumber>;
553
- errorType: z.ZodLiteral<ErrorTypeV1.TIMEOUT_ERROR>;
554
- isImmediatelyAvailable: z.ZodLiteral<true>;
555
- timeoutMs: z.ZodOptional<z.ZodNumber>;
556
- operation: z.ZodOptional<z.ZodString>;
557
- }, "strip", z.ZodTypeAny, {
558
- message: string;
559
- errorType: ErrorTypeV1.TIMEOUT_ERROR;
560
- isImmediatelyAvailable: true;
561
- code?: string | number | undefined;
562
- provider?: RecognitionProvider | undefined;
563
- description?: string | undefined;
564
- audioUtteranceId?: string | undefined;
565
- timestamp?: number | undefined;
566
- timeoutMs?: number | undefined;
567
- operation?: string | undefined;
568
- }, {
569
- message: string;
570
- errorType: ErrorTypeV1.TIMEOUT_ERROR;
571
- isImmediatelyAvailable: true;
572
- code?: string | number | undefined;
573
- provider?: RecognitionProvider | undefined;
574
- description?: string | undefined;
575
- audioUtteranceId?: string | undefined;
576
- timestamp?: number | undefined;
577
- timeoutMs?: number | undefined;
578
- operation?: string | undefined;
579
- }>;
580
- type TimeoutException = z.infer<typeof TimeoutExceptionSchema>;
581
- /**
582
- * Quota Exceeded Error
583
- * isImmediatelyAvailable: true
584
- * Rate limit or quota exceeded - user should wait
585
- */
586
- declare const QuotaExceededExceptionSchema: z.ZodObject<{
587
- code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
588
- message: z.ZodString;
589
- provider: z.ZodOptional<z.ZodNativeEnum<typeof RecognitionProvider>>;
590
- description: z.ZodOptional<z.ZodString>;
591
- audioUtteranceId: z.ZodOptional<z.ZodString>;
592
- timestamp: z.ZodOptional<z.ZodNumber>;
593
- errorType: z.ZodLiteral<ErrorTypeV1.QUOTA_EXCEEDED>;
594
- isImmediatelyAvailable: z.ZodLiteral<true>;
595
- quotaType: z.ZodOptional<z.ZodString>;
596
- resetAt: z.ZodOptional<z.ZodNumber>;
597
- retryAfterSeconds: z.ZodOptional<z.ZodNumber>;
598
- }, "strip", z.ZodTypeAny, {
599
- message: string;
600
- errorType: ErrorTypeV1.QUOTA_EXCEEDED;
601
- isImmediatelyAvailable: true;
602
- code?: string | number | undefined;
603
- provider?: RecognitionProvider | undefined;
604
- description?: string | undefined;
605
- audioUtteranceId?: string | undefined;
606
- timestamp?: number | undefined;
607
- quotaType?: string | undefined;
608
- resetAt?: number | undefined;
609
- retryAfterSeconds?: number | undefined;
610
- }, {
611
- message: string;
612
- errorType: ErrorTypeV1.QUOTA_EXCEEDED;
613
- isImmediatelyAvailable: true;
614
- code?: string | number | undefined;
615
- provider?: RecognitionProvider | undefined;
616
- description?: string | undefined;
617
- audioUtteranceId?: string | undefined;
618
- timestamp?: number | undefined;
619
- quotaType?: string | undefined;
620
- resetAt?: number | undefined;
621
- retryAfterSeconds?: number | undefined;
622
- }>;
623
- type QuotaExceededException = z.infer<typeof QuotaExceededExceptionSchema>;
624
- /**
625
- * Connection Error
626
- * isImmediatelyAvailable: true
627
- * Connection establishment or network failure - user should check network or retry
628
- */
629
- declare const ConnectionExceptionSchema: z.ZodObject<{
630
- code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
631
- message: z.ZodString;
632
- provider: z.ZodOptional<z.ZodNativeEnum<typeof RecognitionProvider>>;
633
- description: z.ZodOptional<z.ZodString>;
634
- audioUtteranceId: z.ZodOptional<z.ZodString>;
635
- timestamp: z.ZodOptional<z.ZodNumber>;
636
- errorType: z.ZodLiteral<ErrorTypeV1.CONNECTION_ERROR>;
637
- isImmediatelyAvailable: z.ZodLiteral<true>;
638
- attempts: z.ZodOptional<z.ZodNumber>;
639
- url: z.ZodOptional<z.ZodString>;
640
- underlyingError: z.ZodOptional<z.ZodString>;
641
- }, "strip", z.ZodTypeAny, {
642
- message: string;
643
- errorType: ErrorTypeV1.CONNECTION_ERROR;
644
- isImmediatelyAvailable: true;
645
- code?: string | number | undefined;
646
- provider?: RecognitionProvider | undefined;
647
- description?: string | undefined;
648
- audioUtteranceId?: string | undefined;
649
- timestamp?: number | undefined;
650
- attempts?: number | undefined;
651
- url?: string | undefined;
652
- underlyingError?: string | undefined;
653
- }, {
654
- message: string;
655
- errorType: ErrorTypeV1.CONNECTION_ERROR;
656
- isImmediatelyAvailable: true;
657
- code?: string | number | undefined;
658
- provider?: RecognitionProvider | undefined;
659
- description?: string | undefined;
660
- audioUtteranceId?: string | undefined;
661
- timestamp?: number | undefined;
662
- attempts?: number | undefined;
663
- url?: string | undefined;
664
- underlyingError?: string | undefined;
665
- }>;
666
- type ConnectionException = z.infer<typeof ConnectionExceptionSchema>;
667
- /**
668
- * Unknown Error
669
- * isImmediatelyAvailable: false
670
- * Unexpected error - needs investigation
671
- */
672
- declare const UnknownExceptionSchema: z.ZodObject<{
673
- code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
674
- message: z.ZodString;
675
- provider: z.ZodOptional<z.ZodNativeEnum<typeof RecognitionProvider>>;
676
- description: z.ZodOptional<z.ZodString>;
677
- audioUtteranceId: z.ZodOptional<z.ZodString>;
678
- timestamp: z.ZodOptional<z.ZodNumber>;
679
- errorType: z.ZodLiteral<ErrorTypeV1.UNKNOWN_ERROR>;
680
- isImmediatelyAvailable: z.ZodLiteral<false>;
681
- stack: z.ZodOptional<z.ZodString>;
682
- context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
683
- }, "strip", z.ZodTypeAny, {
684
- message: string;
685
- errorType: ErrorTypeV1.UNKNOWN_ERROR;
686
- isImmediatelyAvailable: false;
687
- code?: string | number | undefined;
688
- provider?: RecognitionProvider | undefined;
689
- description?: string | undefined;
690
- audioUtteranceId?: string | undefined;
691
- timestamp?: number | undefined;
692
- stack?: string | undefined;
693
- context?: Record<string, unknown> | undefined;
694
- }, {
695
- message: string;
696
- errorType: ErrorTypeV1.UNKNOWN_ERROR;
697
- isImmediatelyAvailable: false;
698
- code?: string | number | undefined;
699
- provider?: RecognitionProvider | undefined;
700
- description?: string | undefined;
701
- audioUtteranceId?: string | undefined;
702
- timestamp?: number | undefined;
703
- stack?: string | undefined;
704
- context?: Record<string, unknown> | undefined;
705
- }>;
706
- type UnknownException = z.infer<typeof UnknownExceptionSchema>;
707
- /**
708
- * Discriminated union of all exception types
709
- * Use this for type-safe error handling
710
- */
711
- declare const RecognitionExceptionSchema: z.ZodDiscriminatedUnion<"errorType", [z.ZodObject<{
712
- code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
713
- message: z.ZodString;
714
- provider: z.ZodOptional<z.ZodNativeEnum<typeof RecognitionProvider>>;
715
- description: z.ZodOptional<z.ZodString>;
716
- audioUtteranceId: z.ZodOptional<z.ZodString>;
717
- timestamp: z.ZodOptional<z.ZodNumber>;
718
- errorType: z.ZodLiteral<ErrorTypeV1.AUTHENTICATION_ERROR>;
719
- isImmediatelyAvailable: z.ZodLiteral<false>;
720
- service: z.ZodOptional<z.ZodString>;
721
- authMethod: z.ZodOptional<z.ZodString>;
722
- }, "strip", z.ZodTypeAny, {
723
- message: string;
724
- errorType: ErrorTypeV1.AUTHENTICATION_ERROR;
725
- isImmediatelyAvailable: false;
726
- code?: string | number | undefined;
727
- provider?: RecognitionProvider | undefined;
728
- description?: string | undefined;
729
- audioUtteranceId?: string | undefined;
730
- timestamp?: number | undefined;
731
- service?: string | undefined;
732
- authMethod?: string | undefined;
733
- }, {
734
- message: string;
735
- errorType: ErrorTypeV1.AUTHENTICATION_ERROR;
736
- isImmediatelyAvailable: false;
737
- code?: string | number | undefined;
738
- provider?: RecognitionProvider | undefined;
739
- description?: string | undefined;
740
- audioUtteranceId?: string | undefined;
741
- timestamp?: number | undefined;
742
- service?: string | undefined;
743
- authMethod?: string | undefined;
744
- }>, z.ZodObject<{
745
- code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
746
- message: z.ZodString;
747
- provider: z.ZodOptional<z.ZodNativeEnum<typeof RecognitionProvider>>;
748
- description: z.ZodOptional<z.ZodString>;
749
- audioUtteranceId: z.ZodOptional<z.ZodString>;
750
- timestamp: z.ZodOptional<z.ZodNumber>;
751
- errorType: z.ZodLiteral<ErrorTypeV1.VALIDATION_ERROR>;
752
- isImmediatelyAvailable: z.ZodLiteral<true>;
753
- field: z.ZodOptional<z.ZodString>;
754
- expected: z.ZodOptional<z.ZodString>;
755
- received: z.ZodOptional<z.ZodString>;
756
- }, "strip", z.ZodTypeAny, {
757
- message: string;
758
- errorType: ErrorTypeV1.VALIDATION_ERROR;
759
- isImmediatelyAvailable: true;
760
- code?: string | number | undefined;
761
- provider?: RecognitionProvider | undefined;
762
- description?: string | undefined;
763
- audioUtteranceId?: string | undefined;
764
- timestamp?: number | undefined;
765
- field?: string | undefined;
766
- expected?: string | undefined;
767
- received?: string | undefined;
768
- }, {
769
- message: string;
770
- errorType: ErrorTypeV1.VALIDATION_ERROR;
771
- isImmediatelyAvailable: true;
772
- code?: string | number | undefined;
773
- provider?: RecognitionProvider | undefined;
774
- description?: string | undefined;
775
- audioUtteranceId?: string | undefined;
776
- timestamp?: number | undefined;
777
- field?: string | undefined;
778
- expected?: string | undefined;
779
- received?: string | undefined;
780
- }>, z.ZodObject<{
781
- code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
782
- message: z.ZodString;
783
- description: z.ZodOptional<z.ZodString>;
784
- audioUtteranceId: z.ZodOptional<z.ZodString>;
785
- timestamp: z.ZodOptional<z.ZodNumber>;
786
- errorType: z.ZodLiteral<ErrorTypeV1.PROVIDER_ERROR>;
787
- isImmediatelyAvailable: z.ZodLiteral<false>;
788
- provider: z.ZodOptional<z.ZodString>;
789
- providerErrorCode: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
790
- isTransient: z.ZodOptional<z.ZodBoolean>;
791
- }, "strip", z.ZodTypeAny, {
792
- message: string;
793
- errorType: ErrorTypeV1.PROVIDER_ERROR;
794
- isImmediatelyAvailable: false;
795
- code?: string | number | undefined;
796
- description?: string | undefined;
797
- audioUtteranceId?: string | undefined;
798
- timestamp?: number | undefined;
799
- provider?: string | undefined;
800
- providerErrorCode?: string | number | undefined;
801
- isTransient?: boolean | undefined;
802
- }, {
803
- message: string;
804
- errorType: ErrorTypeV1.PROVIDER_ERROR;
805
- isImmediatelyAvailable: false;
806
- code?: string | number | undefined;
807
- description?: string | undefined;
808
- audioUtteranceId?: string | undefined;
809
- timestamp?: number | undefined;
810
- provider?: string | undefined;
811
- providerErrorCode?: string | number | undefined;
812
- isTransient?: boolean | undefined;
813
- }>, z.ZodObject<{
814
- code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
815
- message: z.ZodString;
816
- provider: z.ZodOptional<z.ZodNativeEnum<typeof RecognitionProvider>>;
817
- description: z.ZodOptional<z.ZodString>;
818
- audioUtteranceId: z.ZodOptional<z.ZodString>;
819
- timestamp: z.ZodOptional<z.ZodNumber>;
820
- errorType: z.ZodLiteral<ErrorTypeV1.TIMEOUT_ERROR>;
821
- isImmediatelyAvailable: z.ZodLiteral<true>;
822
- timeoutMs: z.ZodOptional<z.ZodNumber>;
823
- operation: z.ZodOptional<z.ZodString>;
824
- }, "strip", z.ZodTypeAny, {
825
- message: string;
826
- errorType: ErrorTypeV1.TIMEOUT_ERROR;
827
- isImmediatelyAvailable: true;
828
- code?: string | number | undefined;
829
- provider?: RecognitionProvider | undefined;
830
- description?: string | undefined;
831
- audioUtteranceId?: string | undefined;
832
- timestamp?: number | undefined;
833
- timeoutMs?: number | undefined;
834
- operation?: string | undefined;
835
- }, {
836
- message: string;
837
- errorType: ErrorTypeV1.TIMEOUT_ERROR;
838
- isImmediatelyAvailable: true;
839
- code?: string | number | undefined;
840
- provider?: RecognitionProvider | undefined;
841
- description?: string | undefined;
842
- audioUtteranceId?: string | undefined;
843
- timestamp?: number | undefined;
844
- timeoutMs?: number | undefined;
845
- operation?: string | undefined;
846
- }>, z.ZodObject<{
847
- code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
848
- message: z.ZodString;
849
- provider: z.ZodOptional<z.ZodNativeEnum<typeof RecognitionProvider>>;
850
- description: z.ZodOptional<z.ZodString>;
851
- audioUtteranceId: z.ZodOptional<z.ZodString>;
852
- timestamp: z.ZodOptional<z.ZodNumber>;
853
- errorType: z.ZodLiteral<ErrorTypeV1.QUOTA_EXCEEDED>;
854
- isImmediatelyAvailable: z.ZodLiteral<true>;
855
- quotaType: z.ZodOptional<z.ZodString>;
856
- resetAt: z.ZodOptional<z.ZodNumber>;
857
- retryAfterSeconds: z.ZodOptional<z.ZodNumber>;
858
- }, "strip", z.ZodTypeAny, {
859
- message: string;
860
- errorType: ErrorTypeV1.QUOTA_EXCEEDED;
861
- isImmediatelyAvailable: true;
862
- code?: string | number | undefined;
863
- provider?: RecognitionProvider | undefined;
864
- description?: string | undefined;
865
- audioUtteranceId?: string | undefined;
866
- timestamp?: number | undefined;
867
- quotaType?: string | undefined;
868
- resetAt?: number | undefined;
869
- retryAfterSeconds?: number | undefined;
870
- }, {
871
- message: string;
872
- errorType: ErrorTypeV1.QUOTA_EXCEEDED;
873
- isImmediatelyAvailable: true;
874
- code?: string | number | undefined;
875
- provider?: RecognitionProvider | undefined;
876
- description?: string | undefined;
877
- audioUtteranceId?: string | undefined;
878
- timestamp?: number | undefined;
879
- quotaType?: string | undefined;
880
- resetAt?: number | undefined;
881
- retryAfterSeconds?: number | undefined;
882
- }>, z.ZodObject<{
883
- code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
884
- message: z.ZodString;
885
- provider: z.ZodOptional<z.ZodNativeEnum<typeof RecognitionProvider>>;
886
- description: z.ZodOptional<z.ZodString>;
887
- audioUtteranceId: z.ZodOptional<z.ZodString>;
888
- timestamp: z.ZodOptional<z.ZodNumber>;
889
- errorType: z.ZodLiteral<ErrorTypeV1.CONNECTION_ERROR>;
890
- isImmediatelyAvailable: z.ZodLiteral<true>;
891
- attempts: z.ZodOptional<z.ZodNumber>;
892
- url: z.ZodOptional<z.ZodString>;
893
- underlyingError: z.ZodOptional<z.ZodString>;
894
- }, "strip", z.ZodTypeAny, {
895
- message: string;
896
- errorType: ErrorTypeV1.CONNECTION_ERROR;
897
- isImmediatelyAvailable: true;
898
- code?: string | number | undefined;
899
- provider?: RecognitionProvider | undefined;
900
- description?: string | undefined;
901
- audioUtteranceId?: string | undefined;
902
- timestamp?: number | undefined;
903
- attempts?: number | undefined;
904
- url?: string | undefined;
905
- underlyingError?: string | undefined;
906
- }, {
907
- message: string;
908
- errorType: ErrorTypeV1.CONNECTION_ERROR;
909
- isImmediatelyAvailable: true;
910
- code?: string | number | undefined;
911
- provider?: RecognitionProvider | undefined;
912
- description?: string | undefined;
913
- audioUtteranceId?: string | undefined;
914
- timestamp?: number | undefined;
915
- attempts?: number | undefined;
916
- url?: string | undefined;
917
- underlyingError?: string | undefined;
918
- }>, z.ZodObject<{
919
- code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
920
- message: z.ZodString;
921
- provider: z.ZodOptional<z.ZodNativeEnum<typeof RecognitionProvider>>;
922
- description: z.ZodOptional<z.ZodString>;
923
- audioUtteranceId: z.ZodOptional<z.ZodString>;
924
- timestamp: z.ZodOptional<z.ZodNumber>;
925
- errorType: z.ZodLiteral<ErrorTypeV1.UNKNOWN_ERROR>;
926
- isImmediatelyAvailable: z.ZodLiteral<false>;
927
- stack: z.ZodOptional<z.ZodString>;
928
- context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
929
- }, "strip", z.ZodTypeAny, {
930
- message: string;
931
- errorType: ErrorTypeV1.UNKNOWN_ERROR;
932
- isImmediatelyAvailable: false;
933
- code?: string | number | undefined;
934
- provider?: RecognitionProvider | undefined;
935
- description?: string | undefined;
936
- audioUtteranceId?: string | undefined;
937
- timestamp?: number | undefined;
938
- stack?: string | undefined;
939
- context?: Record<string, unknown> | undefined;
940
- }, {
941
- message: string;
942
- errorType: ErrorTypeV1.UNKNOWN_ERROR;
943
- isImmediatelyAvailable: false;
944
- code?: string | number | undefined;
945
- provider?: RecognitionProvider | undefined;
946
- description?: string | undefined;
947
- audioUtteranceId?: string | undefined;
948
- timestamp?: number | undefined;
949
- stack?: string | undefined;
950
- context?: Record<string, unknown> | undefined;
951
- }>]>;
952
- type RecognitionException = z.infer<typeof RecognitionExceptionSchema>;
953
- /**
954
- * Check if an exception should be shown to the user immediately
955
- */
956
- declare function isExceptionImmediatelyAvailable(exception: RecognitionException): boolean;
957
- /**
958
- * Get user-friendly error message for exceptions
959
- */
960
- declare function getUserFriendlyMessage(exception: RecognitionException): string;
961
-
962
- /**
963
- * Recognition Context Types V1
964
- * NOTE_TO_AI: DO NOT CHANGE THIS UNLESS EXPLICITLY ASKED. Always ask before making any changes.
965
- * Types and schemas for recognition context data
966
- */
967
-
968
- /**
969
- * Message type discriminator for recognition context V1
970
- */
971
- declare enum RecognitionContextTypeV1 {
972
- GAME_CONTEXT = "GameContext",
973
- CONTROL_SIGNAL = "ControlSignal",
974
- ASR_REQUEST = "ASRRequest"
975
- }
976
- /**
977
- * Control signal types for recognition V1
978
- */
979
- declare enum ControlSignalTypeV1 {
980
- START_RECORDING = "start_recording",
981
- STOP_RECORDING = "stop_recording"
982
- }
983
- /**
984
- * SlotMap - A strongly typed map from slot names to lists of values
985
- * Used for entity extraction and slot filling in voice interactions
986
- */
987
- declare const SlotMapSchema: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>;
988
- type SlotMap = z.infer<typeof SlotMapSchema>;
989
- /**
990
- * Game context V1 - contains game state information
991
- */
992
- declare const GameContextSchemaV1: z.ZodObject<{
993
- type: z.ZodLiteral<RecognitionContextTypeV1.GAME_CONTEXT>;
994
- gameId: z.ZodString;
995
- gamePhase: z.ZodString;
996
- promptSTT: z.ZodOptional<z.ZodString>;
997
- promptSTF: z.ZodOptional<z.ZodString>;
998
- promptTTF: z.ZodOptional<z.ZodString>;
999
- slotMap: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
1000
- }, "strip", z.ZodTypeAny, {
1001
- type: RecognitionContextTypeV1.GAME_CONTEXT;
1002
- gameId: string;
1003
- gamePhase: string;
1004
- promptSTT?: string | undefined;
1005
- promptSTF?: string | undefined;
1006
- promptTTF?: string | undefined;
1007
- slotMap?: Record<string, string[]> | undefined;
1008
- }, {
1009
- type: RecognitionContextTypeV1.GAME_CONTEXT;
1010
- gameId: string;
1011
- gamePhase: string;
1012
- promptSTT?: string | undefined;
1013
- promptSTF?: string | undefined;
1014
- promptTTF?: string | undefined;
1015
- slotMap?: Record<string, string[]> | undefined;
1016
- }>;
1017
- type GameContextV1 = z.infer<typeof GameContextSchemaV1>;
1018
- /**
1019
- * ASR Request V1 - contains complete ASR setup information
1020
- * Sent once at connection start to configure the session
1021
- */
1022
- declare const ASRRequestSchemaV1: z.ZodObject<{
1023
- type: z.ZodLiteral<RecognitionContextTypeV1.ASR_REQUEST>;
1024
- audioUtteranceId: z.ZodOptional<z.ZodString>;
1025
- provider: z.ZodString;
1026
- model: z.ZodOptional<z.ZodString>;
1027
- language: z.ZodString;
1028
- sampleRate: z.ZodNumber;
1029
- encoding: z.ZodNumber;
1030
- interimResults: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
1031
- useContext: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
1032
- finalTranscriptStability: z.ZodOptional<z.ZodString>;
1033
- debugCommand: z.ZodOptional<z.ZodObject<{
1034
- enableDebugLog: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
1035
- enableAudioStorage: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
1036
- enableSongQuizSessionIdCheck: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
1037
- enablePilotModels: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
1038
- }, "strip", z.ZodTypeAny, {
1039
- enableDebugLog: boolean;
1040
- enableAudioStorage: boolean;
1041
- enableSongQuizSessionIdCheck: boolean;
1042
- enablePilotModels: boolean;
1043
- }, {
1044
- enableDebugLog?: boolean | undefined;
1045
- enableAudioStorage?: boolean | undefined;
1046
- enableSongQuizSessionIdCheck?: boolean | undefined;
1047
- enablePilotModels?: boolean | undefined;
1048
- }>>;
1049
- }, "strip", z.ZodTypeAny, {
1050
- provider: string;
1051
- language: string;
1052
- sampleRate: number;
1053
- encoding: number;
1054
- interimResults: boolean;
1055
- useContext: boolean;
1056
- type: RecognitionContextTypeV1.ASR_REQUEST;
1057
- audioUtteranceId?: string | undefined;
1058
- model?: string | undefined;
1059
- finalTranscriptStability?: string | undefined;
1060
- debugCommand?: {
1061
- enableDebugLog: boolean;
1062
- enableAudioStorage: boolean;
1063
- enableSongQuizSessionIdCheck: boolean;
1064
- enablePilotModels: boolean;
1065
- } | undefined;
1066
- }, {
1067
- provider: string;
1068
- language: string;
1069
- sampleRate: number;
1070
- encoding: number;
1071
- type: RecognitionContextTypeV1.ASR_REQUEST;
1072
- audioUtteranceId?: string | undefined;
1073
- model?: string | undefined;
1074
- interimResults?: boolean | undefined;
1075
- useContext?: boolean | undefined;
1076
- finalTranscriptStability?: string | undefined;
1077
- debugCommand?: {
1078
- enableDebugLog?: boolean | undefined;
1079
- enableAudioStorage?: boolean | undefined;
1080
- enableSongQuizSessionIdCheck?: boolean | undefined;
1081
- enablePilotModels?: boolean | undefined;
1082
- } | undefined;
1083
- }>;
1084
- type ASRRequestV1 = z.infer<typeof ASRRequestSchemaV1>;
1085
-
1086
- /**
1087
- * Unified ASR Request Configuration
1088
- *
1089
- * Provider-agnostic configuration for ASR (Automatic Speech Recognition) requests.
1090
- * This interface provides a consistent API for clients regardless of the underlying provider.
1091
- *
1092
- * All fields use library-defined enums for type safety and consistency.
1093
- * Provider-specific mappers will convert these to provider-native formats.
1094
- */
1095
-
1096
- /**
1097
- * Final transcript stability modes
1098
- *
1099
- * Controls timeout duration for fallback final transcript after stopRecording().
1100
- * Similar to AssemblyAI's turn detection confidence modes but applied to our
1101
- * internal timeout mechanism when vendors don't respond with is_final=true.
1102
- *
1103
- * @see https://www.assemblyai.com/docs/speech-to-text/universal-streaming/turn-detection
1104
- */
1105
- declare enum FinalTranscriptStability {
1106
- /**
1107
- * Aggressive mode: 100ms timeout
1108
- * Fast response, optimized for short utterances and quick back-and-forth
1109
- * Use cases: IVR, quick commands, retail confirmations
1110
- */
1111
- AGGRESSIVE = "aggressive",
1112
- /**
1113
- * Balanced mode: 200ms timeout (default)
1114
- * Natural middle ground for most conversational scenarios
1115
- * Use cases: General customer support, tech support, typical voice interactions
1116
- */
1117
- BALANCED = "balanced",
1118
- /**
1119
- * Conservative mode: 400ms timeout
1120
- * Wait longer for providers, optimized for complex/reflective speech
1121
- * Use cases: Healthcare, complex queries, careful thought processes
1122
- */
1123
- CONSERVATIVE = "conservative",
1124
- /**
1125
- * Experimental mode: 10000ms (10 seconds) timeout
1126
- * Very long wait for batch/async providers that need significant processing time
1127
- * Use cases: Batch processing (Gemini, OpenAI Whisper), complex audio analysis
1128
- * Note: Should be cancelled immediately when transcript is received
1129
- */
1130
- EXPERIMENTAL = "experimental"
1131
- }
1132
- /**
1133
- * Unified ASR request configuration
1134
- *
1135
- * This configuration is used by:
1136
- * - Client SDKs to specify recognition parameters
1137
- * - Demo applications for user input
1138
- * - Service layer to configure provider sessions
1139
- *
1140
- * Core fields only - all provider-specific options go in providerOptions
1141
- *
1142
- * @example
1143
- * ```typescript
1144
- * const config: ASRRequestConfig = {
1145
- * provider: RecognitionProvider.GOOGLE,
1146
- * model: GoogleModel.LATEST_LONG,
1147
- * language: Language.ENGLISH_US,
1148
- * sampleRate: SampleRate.RATE_16000, // or just 16000
1149
- * encoding: AudioEncoding.LINEAR16,
1150
- * providerOptions: {
1151
- * google: {
1152
- * enableAutomaticPunctuation: true,
1153
- * interimResults: true,
1154
- * singleUtterance: false
1155
- * }
1156
- * }
1157
- * };
1158
- * ```
1159
- */
1160
- interface ASRRequestConfig {
1161
- /**
1162
- * The ASR provider to use
1163
- * Must be one of the supported providers in RecognitionProvider enum
1164
- */
1165
- provider: RecognitionProvider | string;
1166
- /**
1167
- * Optional model specification for the provider
1168
- * Can be provider-specific model enum or string
1169
- * If not specified, provider's default model will be used
1170
- */
1171
- model?: RecognitionModel;
1172
- /**
1173
- * Language/locale for recognition
1174
- * Use Language enum for common languages
1175
- * Can also accept BCP-47 language tags as strings
1176
- */
1177
- language: Language | string;
1178
- /**
1179
- * Audio sample rate in Hz
1180
- * Prefer using SampleRate enum values for standard rates
1181
- * Can also accept numeric Hz values (e.g., 16000)
1182
- */
1183
- sampleRate: SampleRate | number;
1184
- /**
1185
- * Audio encoding format
1186
- * Must match the actual audio data being sent
1187
- * Use AudioEncoding enum for standard formats
1188
- */
1189
- encoding: AudioEncoding | string;
1190
- /**
1191
- * Enable interim (partial) results during recognition
1192
- * When true, receive real-time updates before finalization
1193
- * When false, only receive final results
1194
- * Default: false
1195
- */
1196
- interimResults?: boolean;
1197
- /**
1198
- * Require GameContext before starting recognition such as song titles
1199
- * When true, server waits for GameContext message before processing audio
1200
- * When false, recognition starts immediately
1201
- * Default: false
1202
- */
1203
- useContext?: boolean;
1204
- /**
1205
- * Final transcript stability mode
1206
- *
1207
- * Controls timeout duration for fallback final transcript when provider
1208
- * doesn't respond with is_final=true after stopRecording().
1209
- *
1210
- * - aggressive: 100ms - fast response, may cut off slow providers
1211
- * - balanced: 200ms - current default, good for most cases
1212
- * - conservative: 400ms - wait longer for complex utterances
1213
- *
1214
- * @default 'balanced'
1215
- * @see FinalTranscriptStability enum for detailed descriptions
1216
- */
1217
- finalTranscriptStability?: FinalTranscriptStability | string;
1218
- /**
1219
- * Additional provider-specific options
1220
- *
1221
- * Common options per provider:
1222
- * - Deepgram: punctuate, smart_format, diarize, utterances
1223
- * - Google: enableAutomaticPunctuation, singleUtterance, enableWordTimeOffsets
1224
- * - AssemblyAI: formatTurns, filter_profanity, word_boost
1225
- *
1226
- * Note: interimResults is now a top-level field, but can still be overridden per provider
1227
- *
1228
- * @example
1229
- * ```typescript
1230
- * providerOptions: {
1231
- * google: {
1232
- * enableAutomaticPunctuation: true,
1233
- * singleUtterance: false,
1234
- * enableWordTimeOffsets: false
1235
- * }
1236
- * }
1237
- * ```
1238
- */
1239
- providerOptions?: Record<string, any>;
1240
- /**
1241
- * Optional fallback ASR configurations
1242
- *
1243
- * List of alternative ASR configurations to use if the primary fails.
1244
- * Each fallback config is a complete ASRRequestConfig that will be tried
1245
- * in order until one succeeds.
1246
- *
1247
- * @example
1248
- * ```typescript
1249
- * fallbackModels: [
1250
- * {
1251
- * provider: RecognitionProvider.DEEPGRAM,
1252
- * model: DeepgramModel.NOVA_2,
1253
- * language: Language.ENGLISH_US,
1254
- * sampleRate: 16000,
1255
- * encoding: AudioEncoding.LINEAR16
1256
- * },
1257
- * {
1258
- * provider: RecognitionProvider.GOOGLE,
1259
- * model: GoogleModel.LATEST_SHORT,
1260
- * language: Language.ENGLISH_US,
1261
- * sampleRate: 16000,
1262
- * encoding: AudioEncoding.LINEAR16
1263
- * }
1264
- * ]
1265
- * ```
1266
- */
1267
- fallbackModels?: ASRRequestConfig[];
1268
- }
1269
- /**
1270
- * Partial ASR config for updates
1271
- * All fields are optional for partial updates
1272
- */
1273
- type PartialASRRequestConfig = Partial<ASRRequestConfig>;
1274
- /**
1275
- * Helper function to create a default ASR config
1276
- */
1277
- declare function createDefaultASRConfig(overrides?: PartialASRRequestConfig): ASRRequestConfig;
1278
-
1279
- /**
1280
- * Gemini Model Types
1281
- * Based on available models as of January 2025
1282
- *
1283
- * API Version Notes:
1284
- * - Gemini 2.5+ models: Use v1beta API (early access features)
1285
- * - Gemini 2.0 models: Use v1beta API (early access features)
1286
- * - Gemini 1.5 models: Use v1 API (stable, production-ready)
1287
- *
1288
- * @see https://ai.google.dev/gemini-api/docs/models
1289
- * @see https://ai.google.dev/gemini-api/docs/api-versions
1290
- */
1291
- declare enum GeminiModel {
1292
- GEMINI_2_5_PRO = "gemini-2.5-pro",
1293
- GEMINI_2_5_FLASH = "gemini-2.5-flash",
1294
- GEMINI_2_5_FLASH_LITE = "gemini-2.5-flash-lite",
1295
- GEMINI_2_0_FLASH_LATEST = "gemini-2.0-flash-latest",
1296
- GEMINI_2_0_FLASH_EXP = "gemini-2.0-flash-exp"
1297
- }
1298
-
1299
- /**
1300
- * OpenAI Model Types
1301
- */
1302
- declare enum OpenAIModel {
1303
- WHISPER_1 = "whisper-1"
1304
- }
1305
-
1306
- /**
1307
- * Standard stage/environment constants used across all services
1308
- */
1309
- declare const STAGES: {
1310
- readonly LOCAL: "local";
1311
- readonly DEV: "dev";
1312
- readonly STAGING: "staging";
1313
- readonly PRODUCTION: "production";
1314
- };
1315
- type Stage = typeof STAGES[keyof typeof STAGES];
1316
-
1317
- /**
1318
- * Generic WebSocket protocol types and utilities
1319
- * Supports flexible versioning and message types
1320
- * Used by both client and server implementations
1321
- */
1322
-
1323
- /**
1324
- * Base message structure - completely flexible
1325
- * @template V - Version type (number, string, etc.)
1326
- */
1327
- interface Message<V = number> {
1328
- v: V;
1329
- type: string;
1330
- data?: unknown;
1331
- }
1332
- /**
1333
- * Version serializer interface
1334
- * Converts between version type V and byte representation
1335
- */
1336
- interface VersionSerializer<V> {
1337
- serialize: (v: V) => number;
1338
- deserialize: (byte: number) => V;
1339
- }
1340
-
1341
- /**
1342
- * WebSocketAudioClient - Abstract base class for WebSocket clients
1343
- * Sends audio and control messages, receives responses from server
1344
- *
1345
- * Features:
1346
- * - Generic version type support (number, string, etc.)
1347
- * - Type-safe upward/downward message data
1348
- * - Client-side backpressure monitoring
1349
- * - Abstract hooks for application-specific logic
1350
- * - Format-agnostic audio protocol (supports any encoding)
1351
- */
1352
-
1353
- type ClientConfig = {
1354
- url: string;
1355
- highWM?: number;
1356
- lowWM?: number;
1357
- };
1358
- /**
1359
- * WebSocketAudioClient - Abstract base class for WebSocket clients
1360
- * that send audio frames and JSON messages
1361
- *
1362
- * @template V - Version type (number, string, object, etc.)
1363
- * @template TUpward - Type of upward message data (Client -> Server)
1364
- * @template TDownward - Type of downward message data (Server -> Client)
1365
- *
1366
- * @example
1367
- * ```typescript
1368
- * class MyClient extends WebSocketAudioClient<number, MyUpMsg, MyDownMsg> {
1369
- * protected onConnected() {
1370
- * console.log('Connected!');
1371
- * }
1372
- *
1373
- * protected onMessage(msg) {
1374
- * console.log('Received:', msg.type, msg.data);
1375
- * }
1376
- *
1377
- * protected onDisconnected(code, reason) {
1378
- * console.log('Disconnected:', code, reason);
1379
- * }
1380
- *
1381
- * protected onError(error) {
1382
- * console.error('Error:', error);
1383
- * }
1384
- * }
1385
- *
1386
- * const client = new MyClient({ url: 'ws://localhost:8080' });
1387
- * client.connect();
1388
- * client.sendMessage(1, 'configure', { language: 'en' });
1389
- * client.sendAudio(audioData);
1390
- * ```
1391
- */
1392
- declare abstract class WebSocketAudioClient<V = number, // Version type (default: number)
1393
- TUpward = unknown, // Upward message data type
1394
- TDownward = unknown> {
1395
- private cfg;
1396
- protected versionSerializer: VersionSerializer<V>;
1397
- private ws;
1398
- private seq;
1399
- private HWM;
1400
- private LWM;
1401
- constructor(cfg: ClientConfig, versionSerializer?: VersionSerializer<V>);
1402
- /**
1403
- * Hook: Called when WebSocket connection is established
1404
- */
1405
- protected abstract onConnected(): void;
1406
- /**
1407
- * Hook: Called when WebSocket connection closes
1408
- * @param code - Close code (see WebSocketCloseCode enum)
1409
- * @param reason - Human-readable close reason
1410
- */
1411
- protected abstract onDisconnected(code: number, reason: string): void;
1412
- /**
1413
- * Hook: Called when WebSocket error occurs
1414
- */
1415
- protected abstract onError(error: Event): void;
1416
- /**
1417
- * Hook: Called when downward message arrives from server
1418
- * Override this to handle messages (optional - default does nothing)
1419
- */
1420
- protected onMessage(_msg: Message<V> & {
1421
- data: TDownward;
1422
- }): void;
1423
- connect(): void;
1424
- /**
1425
- * Send JSON message to server
1426
- * @param version - Message version
1427
- * @param type - Message type (developer defined)
1428
- * @param data - Message payload (typed)
1429
- */
1430
- sendMessage(version: V, type: string, data: TUpward): void;
1431
- /**
1432
- * Send audio frame with specified encoding and sample rate
1433
- * @param audioData - Audio data (any format: Int16Array, Uint8Array, ArrayBuffer, etc.)
1434
- * @param version - Audio frame version
1435
- * @param encodingId - Audio encoding ID (0-5, e.g., AudioEncoding.LINEAR16)
1436
- * @param sampleRate - Sample rate in Hz (e.g., 16000)
1437
- */
1438
- sendAudio(audioData: ArrayBuffer | ArrayBufferView, version: V, encodingId: number, sampleRate: number): void;
1439
- /**
1440
- * Get current WebSocket buffer size
1441
- */
1442
- getBufferedAmount(): number;
1443
- /**
1444
- * Check if local buffer is backpressured
1445
- */
1446
- isLocalBackpressured(): boolean;
1447
- /**
1448
- * Check if ready to send audio
1449
- * Verifies: connection open, no local buffer pressure
1450
- */
1451
- canSend(): boolean;
1452
- /**
1453
- * Check if connection is open
1454
- */
1455
- isOpen(): boolean;
1456
- /**
1457
- * Get current connection state
1458
- */
1459
- getReadyState(): number;
1460
- /**
1461
- * Close the WebSocket connection
1462
- * Protected method for subclasses to implement disconnect logic
1463
- * @param code - WebSocket close code (default: 1000 = normal closure)
1464
- * @param reason - Human-readable close reason
1465
- */
1466
- protected closeConnection(code?: number, reason?: string): void;
1467
- }
1468
-
1469
- /**
1470
- * Recognition Client Types
1471
- *
1472
- * Type definitions and interfaces for the recognition client SDK.
1473
- * These interfaces enable dependency injection, testing, and alternative implementations.
1474
- */
1475
-
1476
- /**
1477
- * Client connection state enum
1478
- * Represents the various states a recognition client can be in during its lifecycle
1479
- */
1480
- declare enum ClientState {
1481
- /** Initial state, no connection established */
1482
- INITIAL = "initial",
1483
- /** Actively establishing WebSocket connection */
1484
- CONNECTING = "connecting",
1485
- /** WebSocket connected but waiting for server ready signal */
1486
- CONNECTED = "connected",
1487
- /** Server ready, can send audio */
1488
- READY = "ready",
1489
- /** Sent stop signal, waiting for final transcript */
1490
- STOPPING = "stopping",
1491
- /** Connection closed normally after stop */
1492
- STOPPED = "stopped",
1493
- /** Connection failed or lost unexpectedly */
1494
- FAILED = "failed"
1495
- }
1496
- /**
1497
- * Callback URL configuration with message type filtering
1498
- */
1499
- interface RecognitionCallbackUrl {
1500
- /** The callback URL endpoint */
1501
- url: string;
1502
- /** Array of message types to send to this URL. If empty/undefined, all types are sent */
1503
- messageTypes?: Array<string | number>;
1504
- }
1505
- interface IRecognitionClientConfig {
1506
- /**
1507
- * WebSocket endpoint URL (optional)
1508
- * Either `url` or `stage` must be provided.
1509
- * If both are provided, `url` takes precedence.
1510
- *
1511
- * Example with explicit URL:
1512
- * ```typescript
1513
- * { url: 'wss://custom-endpoint.example.com/ws/v1/recognize' }
1514
- * ```
1515
- */
1516
- url?: string;
1517
- /**
1518
- * Stage for recognition service (recommended)
1519
- * Either `url` or `stage` must be provided.
1520
- * If both are provided, `url` takes precedence.
1521
- * Defaults to production if neither is provided.
1522
- *
1523
- * Example with STAGES enum (recommended):
1524
- * ```typescript
1525
- * import { STAGES } from '@recog/shared-types';
1526
- * { stage: STAGES.STAGING }
1527
- * ```
1528
- *
1529
- * String values also accepted:
1530
- * ```typescript
1531
- * { stage: 'staging' } // STAGES.LOCAL | STAGES.DEV | STAGES.STAGING | STAGES.PRODUCTION
1532
- * ```
1533
- */
1534
- stage?: Stage | string;
1535
- /** ASR configuration (provider, model, language, etc.) - optional */
1536
- asrRequestConfig?: ASRRequestConfig;
1537
- /** Game context for improved recognition accuracy */
1538
- gameContext?: GameContextV1;
1539
- /**
1540
- * Game ID for tracking and routing purposes (optional)
1541
- * If provided, this is added to the WebSocket URL as a query parameter.
1542
- * If gameContext is also provided, this takes precedence over gameContext.gameId.
1543
- */
1544
- gameId?: string;
1545
- /** Audio utterance ID (optional) - if not provided, a UUID v4 will be generated */
1546
- audioUtteranceId?: string;
1547
- /** Callback URLs for server-side notifications with optional message type filtering (optional)
1548
- * Game side only need to use it if another service need to be notified about the transcription results.
1549
- */
1550
- callbackUrls?: RecognitionCallbackUrl[];
1551
- /** User identification (optional) */
1552
- userId?: string;
1553
- /** Game session identification (optional). called 'sessionId' in Platform and most games. */
1554
- gameSessionId?: string;
1555
- /** Device identification (optional) */
1556
- deviceId?: string;
1557
- /** Account identification (optional) */
1558
- accountId?: string;
1559
- /** Question answer identifier for tracking Q&A sessions (optional and tracking purpose only) */
1560
- questionAnswerId?: string;
1561
- /** Platform for audio recording device (optional, e.g., 'ios', 'android', 'web', 'unity') */
1562
- platform?: string;
1563
- /** Callback when transcript is received */
1564
- onTranscript?: (result: TranscriptionResultV1) => void;
1565
- /**
1566
- * Callback when function call is received
1567
- * Note: Not supported in 2025. P2 feature for future speech-to-function-call capability.
1568
- */
1569
- onFunctionCall?: (result: FunctionCallResultV1) => void;
1570
- /** Callback when metadata is received. Only once after transcription is complete.*/
1571
- onMetadata?: (metadata: MetadataResultV1) => void;
1572
- /** Callback when error occurs */
1573
- onError?: (error: ErrorResultV1) => void;
1574
- /** Callback when connected to WebSocket */
1575
- onConnected?: () => void;
1576
- /**
1577
- * Callback when WebSocket disconnects
1578
- * @param code - WebSocket close code (1000 = normal, 1006 = abnormal, etc.)
1579
- * @param reason - Close reason string
1580
- */
1581
- onDisconnected?: (code: number, reason: string) => void;
1582
- /** High water mark for backpressure control (bytes) */
1583
- highWaterMark?: number;
1584
- /** Low water mark for backpressure control (bytes) */
1585
- lowWaterMark?: number;
1586
- /** Maximum buffer duration in seconds (default: 60s) */
1587
- maxBufferDurationSec?: number;
1588
- /** Expected chunks per second for ring buffer sizing (default: 100) */
1589
- chunksPerSecond?: number;
1590
- /**
1591
- * Connection retry configuration (optional)
1592
- * Only applies to initial connection establishment, not mid-stream interruptions.
1593
- *
1594
- * Default: { maxAttempts: 4, delayMs: 200 } (try once, retry 3 times = 4 total attempts)
1595
- *
1596
- * Timing: Attempt 1 → FAIL → wait 200ms → Attempt 2 → FAIL → wait 200ms → Attempt 3 → FAIL → wait 200ms → Attempt 4
1597
- *
1598
- * Example:
1599
- * ```typescript
1600
- * {
1601
- * connectionRetry: {
1602
- * maxAttempts: 2, // Try connecting up to 2 times (1 retry)
1603
- * delayMs: 500 // Wait 500ms between attempts
1604
- * }
1605
- * }
1606
- * ```
1607
- */
1608
- connectionRetry?: {
1609
- /** Maximum number of connection attempts (default: 4, min: 1, max: 5) */
1610
- maxAttempts?: number;
1611
- /** Delay in milliseconds between retry attempts (default: 200ms) */
1612
- delayMs?: number;
1613
- };
1614
- /**
1615
- * Optional logger function for debugging
1616
- * If not provided, no logging will occur
1617
- * @param level - Log level: 'debug', 'info', 'warn', 'error'
1618
- * @param message - Log message
1619
- * @param data - Optional additional data
1620
- */
1621
- logger?: (level: 'debug' | 'info' | 'warn' | 'error', message: string, data?: any) => void;
1622
- }
1623
- /**
1624
- * Recognition Client Interface
1625
- *
1626
- * Main interface for real-time speech recognition clients.
1627
- * Provides methods for connection management, audio streaming, and session control.
1628
- */
1629
- interface IRecognitionClient {
1630
- /**
1631
- * Connect to the WebSocket endpoint
1632
- * @returns Promise that resolves when connected
1633
- * @throws Error if connection fails or times out
1634
- */
1635
- connect(): Promise<void>;
1636
- /**
1637
- * Send audio data to the recognition service
1638
- * Audio is buffered locally and sent when connection is ready.
1639
- * @param audioData - PCM audio data as ArrayBuffer, typed array view, or Blob
1640
- */
1641
- sendAudio(audioData: ArrayBuffer | ArrayBufferView | Blob): void;
1642
- /**
1643
- * Stop recording and wait for final transcript
1644
- * The server will close the connection after sending the final transcript.
1645
- * @returns Promise that resolves when final transcript is received
1646
- */
1647
- stopRecording(): Promise<void>;
1648
- /**
1649
- * Force stop and immediately close connection without waiting for server
1650
- *
1651
- * WARNING: This is an abnormal shutdown that bypasses the graceful stop flow:
1652
- * - Does NOT wait for server to process remaining audio
1653
- * - Does NOT receive final transcript from server
1654
- * - Immediately closes WebSocket connection
1655
- * - Cleans up resources (buffers, listeners)
1656
- *
1657
- * Use Cases:
1658
- * - User explicitly cancels/abandons session
1659
- * - Timeout scenarios where waiting is not acceptable
1660
- * - Need immediate cleanup and can't wait for server
1661
- *
1662
- * RECOMMENDED: Use stopRecording() for normal shutdown.
1663
- * Only use this when immediate disconnection is required.
1664
- */
1665
- stopAbnormally(): void;
1666
- /**
1667
- * Get the audio utterance ID for this session
1668
- * Available immediately after client construction.
1669
- * @returns UUID v4 string identifying this recognition session
1670
- */
1671
- getAudioUtteranceId(): string;
1672
- /**
1673
- * Get the current state of the client
1674
- * @returns Current ClientState value
1675
- */
1676
- getState(): ClientState;
1677
- /**
1678
- * Check if WebSocket connection is open
1679
- * @returns true if connected and ready to communicate
1680
- */
1681
- isConnected(): boolean;
1682
- /**
1683
- * Check if client is currently connecting
1684
- * @returns true if connection is in progress
1685
- */
1686
- isConnecting(): boolean;
1687
- /**
1688
- * Check if client is currently stopping
1689
- * @returns true if stopRecording() is in progress
1690
- */
1691
- isStopping(): boolean;
1692
- /**
1693
- * Check if transcription has finished
1694
- * @returns true if the transcription is complete
1695
- */
1696
- isTranscriptionFinished(): boolean;
1697
- /**
1698
- * Check if the audio buffer has overflowed
1699
- * @returns true if the ring buffer has wrapped around
1700
- */
1701
- isBufferOverflowing(): boolean;
1702
- /**
1703
- * Get client statistics
1704
- * @returns Statistics about audio transmission and buffering
1705
- */
1706
- getStats(): IRecognitionClientStats;
1707
- /**
1708
- * Get the WebSocket URL being used by this client
1709
- * Available immediately after client construction.
1710
- * @returns WebSocket URL string
1711
- */
1712
- getUrl(): string;
1713
- }
1714
- /**
1715
- * Client statistics interface
1716
- */
1717
- interface IRecognitionClientStats {
1718
- /** Total audio bytes sent to server */
1719
- audioBytesSent: number;
1720
- /** Total number of audio chunks sent */
1721
- audioChunksSent: number;
1722
- /** Total number of audio chunks buffered */
1723
- audioChunksBuffered: number;
1724
- /** Number of times the ring buffer overflowed */
1725
- bufferOverflowCount: number;
1726
- /** Current number of chunks in buffer */
1727
- currentBufferedChunks: number;
1728
- /** Whether the ring buffer has wrapped (overwritten old data) */
1729
- hasWrapped: boolean;
1730
- }
1731
- /**
1732
- * Configuration for RealTimeTwoWayWebSocketRecognitionClient
1733
- * This extends IRecognitionClientConfig and is the main configuration interface
1734
- * for creating a new RealTimeTwoWayWebSocketRecognitionClient instance.
1735
- */
1736
- interface RealTimeTwoWayWebSocketRecognitionClientConfig extends IRecognitionClientConfig {
1737
- }
1738
-
1739
- /**
1740
- * RealTimeTwoWayWebSocketRecognitionClient - Clean, compact SDK for real-time speech recognition
1741
- *
1742
- * Features:
1743
- * - Ring buffer-based audio storage with fixed memory footprint
1744
- * - Automatic buffering when disconnected, immediate send when connected
1745
- * - Buffer persists after flush (for future retry/reconnection scenarios)
1746
- * - Built on WebSocketAudioClient for robust protocol handling
1747
- * - Simple API: connect() → sendAudio() → stopRecording()
1748
- * - Type-safe message handling with callbacks
1749
- * - Automatic backpressure management
1750
- * - Overflow detection with buffer state tracking
1751
- *
1752
- * Example:
1753
- * ```typescript
1754
- * const client = new RealTimeTwoWayWebSocketRecognitionClient({
1755
- * url: 'ws://localhost:3101/ws/v1/recognize',
1756
- * onTranscript: (result) => console.log(result.finalTranscript),
1757
- * onError: (error) => console.error(error),
1758
- * maxBufferDurationSec: 60 // Ring buffer for 60 seconds
1759
- * });
1760
- *
1761
- * await client.connect();
1762
- *
1763
- * // Send audio chunks - always stored in ring buffer, sent if connected
1764
- * micStream.on('data', (chunk) => client.sendAudio(chunk));
1765
- *
1766
- * // Signal end of audio and wait for final results
1767
- * await client.stopRecording();
1768
- *
1769
- * // Server will close connection after sending finals
1770
- * // No manual cleanup needed - browser handles it
1771
- * ```
1772
- */
1773
-
1774
- /**
1775
- * Check if a WebSocket close code indicates normal closure
1776
- * @param code - WebSocket close code
1777
- * @returns true if the disconnection was normal/expected, false if it was an error
1778
- */
1779
- declare function isNormalDisconnection(code: number): boolean;
1780
- /**
1781
- * Re-export TranscriptionResultV1 as TranscriptionResult for backward compatibility
1782
- */
1783
- type TranscriptionResult = TranscriptionResultV1;
1784
-
1785
- /**
1786
- * RealTimeTwoWayWebSocketRecognitionClient - SDK-level client for real-time speech recognition
1787
- *
1788
- * Implements IRecognitionClient interface for dependency injection and testing.
1789
- * Extends WebSocketAudioClient with local audio buffering and simple callback-based API.
1790
- */
1791
- declare class RealTimeTwoWayWebSocketRecognitionClient extends WebSocketAudioClient<number, any, any> implements IRecognitionClient {
1792
- private static readonly PROTOCOL_VERSION;
1793
- private config;
1794
- private audioBuffer;
1795
- private messageHandler;
1796
- private state;
1797
- private connectionPromise;
1798
- private isDebugLogEnabled;
1799
- private audioBytesSent;
1800
- private audioChunksSent;
1801
- private audioStatsLogInterval;
1802
- private lastAudioStatsLog;
1803
- constructor(config: RealTimeTwoWayWebSocketRecognitionClientConfig);
1804
- /**
1805
- * Internal logging helper - only logs if a logger was provided in config
1806
- * Debug logs are additionally gated by isDebugLogEnabled flag
1807
- * @param level - Log level: debug, info, warn, or error
1808
- * @param message - Message to log
1809
- * @param data - Optional additional data to log
1810
- */
1811
- private log;
1812
- /**
1813
- * Clean up internal resources to free memory
1814
- * Called when connection closes (normally or abnormally)
1815
- */
1816
- private cleanup;
1817
- connect(): Promise<void>;
1818
- /**
1819
- * Attempt to connect with retry logic
1820
- * Only retries on initial connection establishment, not mid-stream interruptions
1821
- */
1822
- private connectWithRetry;
1823
- sendAudio(audioData: ArrayBuffer | ArrayBufferView | Blob): void;
1824
- private sendAudioInternal;
1825
- stopRecording(): Promise<void>;
1826
- stopAbnormally(): void;
1827
- getAudioUtteranceId(): string;
1828
- getUrl(): string;
1829
- getState(): ClientState;
1830
- isConnected(): boolean;
1831
- isConnecting(): boolean;
1832
- isStopping(): boolean;
1833
- isTranscriptionFinished(): boolean;
1834
- isBufferOverflowing(): boolean;
1835
- getStats(): IRecognitionClientStats;
1836
- protected onConnected(): void;
1837
- protected onDisconnected(code: number, reason: string): void;
1838
- /**
1839
- * Get human-readable description for WebSocket close code
1840
- */
1841
- private getCloseCodeDescription;
1842
- protected onError(error: Event): void;
1843
- protected onMessage(msg: {
1844
- v: number;
1845
- type: string;
1846
- data: any;
1847
- }): void;
1848
- /**
1849
- * Handle control messages from server
1850
- * @param msg - Control message containing server actions
1851
- */
1852
- private handleControlMessage;
1853
- /**
1854
- * Send audio immediately to the server (without buffering)
1855
- * @param audioData - Audio data to send
1856
- */
1857
- private sendAudioNow;
1858
- }
1859
-
1860
- /**
1861
- * Configuration Builder for Recognition Client
1862
- *
1863
- * Simple builder pattern for RealTimeTwoWayWebSocketRecognitionClientConfig
1864
- */
1865
-
1866
- /**
1867
- * Builder for RealTimeTwoWayWebSocketRecognitionClientConfig
1868
- *
1869
- * Provides a fluent API for building client configurations.
1870
- *
1871
- * Example:
1872
- * ```typescript
1873
- * import { STAGES } from '@recog/shared-types';
1874
- *
1875
- * const config = new ConfigBuilder()
1876
- * .stage(STAGES.STAGING) // Recommended: automatic environment selection
1877
- * .asrRequestConfig({
1878
- * provider: RecognitionProvider.DEEPGRAM,
1879
- * model: 'nova-2-general'
1880
- * })
1881
- * .onTranscript((result) => console.log(result))
1882
- * .build();
1883
- * ```
1884
- */
1885
- declare class ConfigBuilder {
1886
- private config;
1887
- /**
1888
- * Set the WebSocket URL (advanced usage)
1889
- * For standard environments, use stage() instead
1890
- */
1891
- url(url: string): this;
1892
- /**
1893
- * Set the stage for automatic environment selection (recommended)
1894
- * @param stage - STAGES.LOCAL | STAGES.DEV | STAGES.STAGING | STAGES.PRODUCTION
1895
- * @example
1896
- * ```typescript
1897
- * import { STAGES } from '@recog/shared-types';
1898
- * builder.stage(STAGES.STAGING)
1899
- * ```
1900
- */
1901
- stage(stage: Stage | string): this;
1902
- /**
1903
- * Set ASR request configuration
1904
- */
1905
- asrRequestConfig(config: ASRRequestConfig): this;
1906
- /**
1907
- * Set game context
1908
- */
1909
- gameContext(context: GameContextV1): this;
1910
- /**
1911
- * Set game ID directly (takes precedence over gameContext.gameId)
1912
- * Use this when you only need to identify the game without full context.
1913
- */
1914
- gameId(id: string): this;
1915
- /**
1916
- * Set audio utterance ID
1917
- */
1918
- audioUtteranceId(id: string): this;
1919
- /**
1920
- * Set callback URLs
1921
- */
1922
- callbackUrls(urls: RecognitionCallbackUrl[]): this;
1923
- /**
1924
- * Set user ID
1925
- */
1926
- userId(id: string): this;
1927
- /**
1928
- * Set game session ID
1929
- */
1930
- gameSessionId(id: string): this;
1931
- /**
1932
- * Set device ID
1933
- */
1934
- deviceId(id: string): this;
1935
- /**
1936
- * Set account ID
1937
- */
1938
- accountId(id: string): this;
1939
- /**
1940
- * Set question answer ID
1941
- */
1942
- questionAnswerId(id: string): this;
1943
- /**
1944
- * Set platform
1945
- */
1946
- platform(platform: string): this;
1947
- /**
1948
- * Set transcript callback
1949
- */
1950
- onTranscript(callback: (result: TranscriptionResultV1) => void): this;
1951
- /**
1952
- * Set metadata callback
1953
- */
1954
- onMetadata(callback: (metadata: MetadataResultV1) => void): this;
1955
- /**
1956
- * Set error callback
1957
- */
1958
- onError(callback: (error: ErrorResultV1) => void): this;
1959
- /**
1960
- * Set connected callback
1961
- */
1962
- onConnected(callback: () => void): this;
1963
- /**
1964
- * Set disconnected callback
1965
- */
1966
- onDisconnected(callback: (code: number, reason: string) => void): this;
1967
- /**
1968
- * Set high water mark
1969
- */
1970
- highWaterMark(bytes: number): this;
1971
- /**
1972
- * Set low water mark
1973
- */
1974
- lowWaterMark(bytes: number): this;
1975
- /**
1976
- * Set max buffer duration in seconds
1977
- */
1978
- maxBufferDurationSec(seconds: number): this;
1979
- /**
1980
- * Set chunks per second
1981
- */
1982
- chunksPerSecond(chunks: number): this;
1983
- /**
1984
- * Set logger function
1985
- */
1986
- logger(logger: (level: 'debug' | 'info' | 'warn' | 'error', message: string, data?: any) => void): this;
1987
- /**
1988
- * Build the configuration
1989
- */
1990
- build(): RealTimeTwoWayWebSocketRecognitionClientConfig;
1991
- }
1992
-
1993
- /**
1994
- * Factory function for creating Recognition Client instances
1995
- */
1996
-
1997
- /**
1998
- * Create a recognition client from a configuration object
1999
- *
2000
- * Example:
2001
- * ```typescript
2002
- * const client = createClient({
2003
- * url: 'ws://localhost:3101/ws/v1/recognize',
2004
- * audioUtteranceId: 'unique-id',
2005
- * onTranscript: (result) => console.log(result)
2006
- * });
2007
- * ```
2008
- *
2009
- * @param config - Client configuration
2010
- * @returns Configured recognition client instance
2011
- */
2012
- declare function createClient(config: RealTimeTwoWayWebSocketRecognitionClientConfig): IRecognitionClient;
2013
- /**
2014
- * Create a recognition client using the builder pattern
2015
- *
2016
- * Example:
2017
- * ```typescript
2018
- * const client = createClientWithBuilder((builder) =>
2019
- * builder
2020
- * .url('ws://localhost:3101/ws/v1/recognize')
2021
- * .onTranscript((result) => console.log(result))
2022
- * .onError((error) => console.error(error))
2023
- * );
2024
- * ```
2025
- */
2026
- declare function createClientWithBuilder(configure: (builder: ConfigBuilder) => ConfigBuilder): IRecognitionClient;
2027
-
2028
- /**
2029
- * SDK Error Classes
2030
- *
2031
- * Typed error classes that extend native Error with recognition-specific metadata
2032
- */
2033
-
2034
- /**
2035
- * Base class for all recognition SDK errors
2036
- */
2037
- declare class RecognitionError extends Error {
2038
- readonly errorType: ErrorTypeV1;
2039
- readonly timestamp: number;
2040
- constructor(errorType: ErrorTypeV1, message: string);
2041
- }
2042
- /**
2043
- * Connection error - thrown when WebSocket connection fails after all retry attempts
2044
- */
2045
- declare class ConnectionError extends RecognitionError {
2046
- readonly attempts: number;
2047
- readonly url: string;
2048
- readonly underlyingError?: Error;
2049
- constructor(message: string, attempts: number, url: string, underlyingError?: Error);
2050
- }
2051
- /**
2052
- * Timeout error - thrown when operations exceed timeout limits
2053
- */
2054
- declare class TimeoutError extends RecognitionError {
2055
- readonly timeoutMs: number;
2056
- readonly operation: string;
2057
- constructor(message: string, timeoutMs: number, operation: string);
2058
- }
2059
- /**
2060
- * Validation error - thrown when invalid configuration or input is provided
2061
- */
2062
- declare class ValidationError extends RecognitionError {
2063
- readonly field?: string;
2064
- readonly expected?: string;
2065
- readonly received?: string;
2066
- constructor(message: string, field?: string, expected?: string, received?: string);
2067
- }
2068
-
2069
- /**
2070
- * VGF-style state schema for game-side recognition state/results management.
2071
- *
2072
- * This schema provides a standardized way for game developers to manage
2073
- * voice recognition state and results in their applications. It supports:
2074
- *
2075
- * STEP 1: Basic transcription flow
2076
- * STEP 2: Mic auto-stop upon correct answer (using partial transcripts)
2077
- * STEP 3: Semantic/function-call outcomes for game actions
2078
- *
2079
- * Ideally this should be part of a more centralized shared type library to free
2080
- * game developers and provide helper functions (VGF? Platform SDK?).
2081
- */
2082
- declare const RecognitionVGFStateSchema: z.ZodObject<{
2083
- audioUtteranceId: z.ZodString;
2084
- startRecordingStatus: z.ZodOptional<z.ZodString>;
2085
- transcriptionStatus: z.ZodOptional<z.ZodString>;
2086
- finalTranscript: z.ZodOptional<z.ZodString>;
2087
- finalConfidence: z.ZodOptional<z.ZodNumber>;
2088
- asrConfig: z.ZodOptional<z.ZodString>;
2089
- startRecordingTimestamp: z.ZodOptional<z.ZodString>;
2090
- finalRecordingTimestamp: z.ZodOptional<z.ZodString>;
2091
- finalTranscriptionTimestamp: z.ZodOptional<z.ZodString>;
2092
- pendingTranscript: z.ZodDefault<z.ZodOptional<z.ZodString>>;
2093
- pendingConfidence: z.ZodOptional<z.ZodNumber>;
2094
- functionCallMetadata: z.ZodOptional<z.ZodString>;
2095
- functionCallConfidence: z.ZodOptional<z.ZodNumber>;
2096
- finalFunctionCallTimestamp: z.ZodOptional<z.ZodString>;
2097
- promptSlotMap: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
2098
- recognitionActionProcessingState: z.ZodOptional<z.ZodString>;
2099
- }, "strip", z.ZodTypeAny, {
2100
- audioUtteranceId: string;
2101
- pendingTranscript: string;
2102
- startRecordingStatus?: string | undefined;
2103
- transcriptionStatus?: string | undefined;
2104
- finalTranscript?: string | undefined;
2105
- finalConfidence?: number | undefined;
2106
- asrConfig?: string | undefined;
2107
- startRecordingTimestamp?: string | undefined;
2108
- finalRecordingTimestamp?: string | undefined;
2109
- finalTranscriptionTimestamp?: string | undefined;
2110
- pendingConfidence?: number | undefined;
2111
- functionCallMetadata?: string | undefined;
2112
- functionCallConfidence?: number | undefined;
2113
- finalFunctionCallTimestamp?: string | undefined;
2114
- promptSlotMap?: Record<string, string[]> | undefined;
2115
- recognitionActionProcessingState?: string | undefined;
2116
- }, {
2117
- audioUtteranceId: string;
2118
- startRecordingStatus?: string | undefined;
2119
- transcriptionStatus?: string | undefined;
2120
- finalTranscript?: string | undefined;
2121
- finalConfidence?: number | undefined;
2122
- asrConfig?: string | undefined;
2123
- startRecordingTimestamp?: string | undefined;
2124
- finalRecordingTimestamp?: string | undefined;
2125
- finalTranscriptionTimestamp?: string | undefined;
2126
- pendingTranscript?: string | undefined;
2127
- pendingConfidence?: number | undefined;
2128
- functionCallMetadata?: string | undefined;
2129
- functionCallConfidence?: number | undefined;
2130
- finalFunctionCallTimestamp?: string | undefined;
2131
- promptSlotMap?: Record<string, string[]> | undefined;
2132
- recognitionActionProcessingState?: string | undefined;
2133
- }>;
2134
- type RecognitionState = z.infer<typeof RecognitionVGFStateSchema>;
2135
- declare const RecordingStatus: {
2136
- readonly NOT_READY: "NOT_READY";
2137
- readonly READY: "READY";
2138
- readonly RECORDING: "RECORDING";
2139
- readonly FINISHED: "FINISHED";
2140
- };
2141
- type RecordingStatusType = typeof RecordingStatus[keyof typeof RecordingStatus];
2142
- declare const TranscriptionStatus: {
2143
- readonly NOT_STARTED: "NOT_STARTED";
2144
- readonly IN_PROGRESS: "IN_PROGRESS";
2145
- readonly FINALIZED: "FINALIZED";
2146
- readonly ABORTED: "ABORTED";
2147
- readonly ERROR: "ERROR";
2148
- };
2149
- type TranscriptionStatusType = typeof TranscriptionStatus[keyof typeof TranscriptionStatus];
2150
- declare function createInitialRecognitionState(audioUtteranceId: string): RecognitionState;
2151
- declare function isValidRecordingStatusTransition(from: string | undefined, to: string): boolean;
2152
-
2153
- /**
2154
- * Simplified VGF Recognition Client
2155
- *
2156
- * A thin wrapper around RealTimeTwoWayWebSocketRecognitionClient that maintains
2157
- * a VGF RecognitionState as a pure sink/output of recognition events.
2158
- *
2159
- * The VGF state is updated based on events but never influences client behavior.
2160
- * All functionality is delegated to the underlying client.
2161
- */
2162
-
2163
- /**
2164
- * Configuration for SimplifiedVGFRecognitionClient
2165
- */
2166
- interface SimplifiedVGFClientConfig extends IRecognitionClientConfig {
2167
- /**
2168
- * Callback invoked whenever the VGF state changes
2169
- * Use this to update your UI or React state
2170
- */
2171
- onStateChange?: (state: RecognitionState) => void;
2172
- /**
2173
- * Optional initial state to restore from a previous session
2174
- * If provided, audioUtteranceId will be extracted and used
2175
- */
2176
- initialState?: RecognitionState;
2177
- }
2178
- /**
2179
- * Interface for SimplifiedVGFRecognitionClient
2180
- *
2181
- * A simplified client that maintains VGF state for game developers.
2182
- * All methods from the underlying client are available, plus VGF state management.
2183
- */
2184
- interface ISimplifiedVGFRecognitionClient {
2185
- /**
2186
- * Connect to the recognition service WebSocket
2187
- * @returns Promise that resolves when connected and ready
2188
- */
2189
- connect(): Promise<void>;
2190
- /**
2191
- * Send audio data for transcription
2192
- * @param audioData - PCM audio data as ArrayBuffer, typed array, or Blob
2193
- */
2194
- sendAudio(audioData: ArrayBuffer | ArrayBufferView | Blob): void;
2195
- /**
2196
- * Stop recording and wait for final transcription
2197
- * @returns Promise that resolves when transcription is complete
2198
- */
2199
- stopRecording(): Promise<void>;
2200
- /**
2201
- * Force stop and immediately close connection without waiting for server
2202
- *
2203
- * WARNING: This is an abnormal shutdown that bypasses the graceful stop flow:
2204
- * - Does NOT wait for server to process remaining audio
2205
- * - Does NOT receive final transcript from server (VGF state set to empty)
2206
- * - Immediately closes WebSocket connection
2207
- * - Cleans up resources (buffers, listeners)
2208
- *
2209
- * Use Cases:
2210
- * - User explicitly cancels/abandons the session
2211
- * - Timeout scenarios where waiting is not acceptable
2212
- * - Need immediate cleanup and can't wait for server
2213
- *
2214
- * RECOMMENDED: Use stopRecording() for normal shutdown.
2215
- * Only use this when immediate disconnection is required.
2216
- */
2217
- stopAbnormally(): void;
2218
- /**
2219
- * Get the current VGF recognition state
2220
- * @returns Current RecognitionState with all transcription data
2221
- */
2222
- getVGFState(): RecognitionState;
2223
- /**
2224
- * Check if connected to the WebSocket
2225
- */
2226
- isConnected(): boolean;
2227
- /**
2228
- * Check if currently connecting
2229
- */
2230
- isConnecting(): boolean;
2231
- /**
2232
- * Check if currently stopping
2233
- */
2234
- isStopping(): boolean;
2235
- /**
2236
- * Check if transcription has finished
2237
- */
2238
- isTranscriptionFinished(): boolean;
2239
- /**
2240
- * Check if the audio buffer has overflowed
2241
- */
2242
- isBufferOverflowing(): boolean;
2243
- /**
2244
- * Get the audio utterance ID for this session
2245
- */
2246
- getAudioUtteranceId(): string;
2247
- /**
2248
- * Get the WebSocket URL being used
2249
- */
2250
- getUrl(): string;
2251
- /**
2252
- * Get the underlying client state (for advanced usage)
2253
- */
2254
- getState(): ClientState;
2255
- }
2256
- /**
2257
- * This wrapper ONLY maintains VGF state as a sink.
2258
- * All actual functionality is delegated to the underlying client.
2259
- */
2260
- declare class SimplifiedVGFRecognitionClient implements ISimplifiedVGFRecognitionClient {
2261
- private client;
2262
- private state;
2263
- private isRecordingAudio;
2264
- private stateChangeCallback;
2265
- private expectedUuid;
2266
- private logger;
2267
- private lastSentTerminalUuid;
2268
- constructor(config: SimplifiedVGFClientConfig);
2269
- connect(): Promise<void>;
2270
- sendAudio(audioData: ArrayBuffer | ArrayBufferView | Blob): void;
2271
- stopRecording(): Promise<void>;
2272
- stopAbnormally(): void;
2273
- getAudioUtteranceId(): string;
2274
- getUrl(): string;
2275
- getState(): ClientState;
2276
- isConnected(): boolean;
2277
- isConnecting(): boolean;
2278
- isStopping(): boolean;
2279
- isTranscriptionFinished(): boolean;
2280
- isBufferOverflowing(): boolean;
2281
- getVGFState(): RecognitionState;
2282
- private isTerminalStatus;
2283
- private notifyStateChange;
2284
- }
2285
- /**
2286
- * Factory function for creating simplified client
2287
- * Usage examples:
2288
- *
2289
- * // Basic usage
2290
- * const client = createSimplifiedVGFClient({
2291
- * asrRequestConfig: { provider: 'deepgram', language: 'en' },
2292
- * onStateChange: (state) => {
2293
- * console.log('VGF State updated:', state);
2294
- * // Update React state, game UI, etc.
2295
- * }
2296
- * });
2297
- *
2298
- * // With initial state (e.g., restoring from previous session)
2299
- * const client = createSimplifiedVGFClient({
2300
- * asrRequestConfig: { provider: 'deepgram', language: 'en' },
2301
- * initialState: previousState, // Will use audioUtteranceId from state
2302
- * onStateChange: (state) => setVGFState(state)
2303
- * });
2304
- *
2305
- * // With initial state containing promptSlotMap for enhanced recognition
2306
- * const stateWithSlots: RecognitionState = {
2307
- * audioUtteranceId: 'session-123',
2308
- * promptSlotMap: {
2309
- * 'song_title': ['one time', 'baby'],
2310
- * 'artists': ['justin bieber']
2311
- * }
2312
- * };
2313
- * const client = createSimplifiedVGFClient({
2314
- * asrRequestConfig: { provider: 'deepgram', language: 'en' },
2315
- * gameContext: {
2316
- * type: RecognitionContextTypeV1.GAME_CONTEXT,
2317
- * gameId: 'music-quiz', // Your game's ID
2318
- * gamePhase: 'song-guessing' // Current game phase
2319
- * },
2320
- * initialState: stateWithSlots, // promptSlotMap will be added to gameContext
2321
- * onStateChange: (state) => setVGFState(state)
2322
- * });
2323
- *
2324
- * await client.connect();
2325
- * client.sendAudio(audioData);
2326
- * // VGF state automatically updates based on transcription results
2327
- */
2328
- declare function createSimplifiedVGFClient(config: SimplifiedVGFClientConfig): ISimplifiedVGFRecognitionClient;
2329
-
2330
- /**
2331
- * Base URL schema shared across service endpoint helpers.
2332
- */
2333
- type ServiceBaseUrls = {
2334
- httpBase: string;
2335
- wsBase: string;
2336
- };
2337
- /**
2338
- * Base URL mappings keyed by stage.
2339
- */
2340
- declare const RECOGNITION_SERVICE_BASES: Record<Stage, ServiceBaseUrls>;
2341
- declare const RECOGNITION_CONDUCTOR_BASES: Record<Stage, ServiceBaseUrls>;
2342
- /**
2343
- * Normalize arbitrary stage input into a known `Stage`, defaulting to `local`.
2344
- */
2345
- declare function normalizeStage(input?: Stage | string | null | undefined): Stage;
2346
- /**
2347
- * Resolve the recognition-service base URLs for a given stage.
2348
- */
2349
- declare function getRecognitionServiceBase(stage?: Stage | string | null | undefined): ServiceBaseUrls;
2350
- /**
2351
- * Convenience helper for retrieving the HTTP base URL.
2352
- */
2353
- declare function getRecognitionServiceHttpBase(stage?: Stage | string | null | undefined): string;
2354
- /**
2355
- * Convenience helper for retrieving the WebSocket base URL.
2356
- */
2357
- declare function getRecognitionServiceWsBase(stage?: Stage | string | null | undefined): string;
2358
- /**
2359
- * Expose hostname lookup separately for callers that need raw host strings.
2360
- */
2361
- declare function getRecognitionServiceHost(stage?: Stage | string | null | undefined): string;
2362
- /**
2363
- * Resolve the recognition-conductor base URLs for a given stage.
2364
- */
2365
- declare function getRecognitionConductorBase(stage?: Stage | string | null | undefined): ServiceBaseUrls;
2366
- declare function getRecognitionConductorHttpBase(stage?: Stage | string | null | undefined): string;
2367
- declare function getRecognitionConductorWsBase(stage?: Stage | string | null | undefined): string;
2368
- declare function getRecognitionConductorHost(stage?: Stage | string | null | undefined): string;
2369
-
2370
- export { AudioEncoding, ClientControlActionV1, ClientState, ConfigBuilder, ConnectionError, ControlSignalTypeV1 as ControlSignal, ControlSignalTypeV1, DeepgramModel, ElevenLabsModel, ErrorTypeV1, FinalTranscriptStability, FireworksModel, GeminiModel, GoogleModel, Language, OpenAIModel, RECOGNITION_CONDUCTOR_BASES, RECOGNITION_SERVICE_BASES, RealTimeTwoWayWebSocketRecognitionClient, RecognitionContextTypeV1, RecognitionError, RecognitionProvider, RecognitionResultTypeV1, RecognitionVGFStateSchema, RecordingStatus, STAGES, SampleRate, SimplifiedVGFRecognitionClient, TimeoutError, TranscriptionStatus, ValidationError, createClient, createClientWithBuilder, createDefaultASRConfig, createInitialRecognitionState, createSimplifiedVGFClient, getRecognitionConductorBase, getRecognitionConductorHost, getRecognitionConductorHttpBase, getRecognitionConductorWsBase, getRecognitionServiceBase, getRecognitionServiceHost, getRecognitionServiceHttpBase, getRecognitionServiceWsBase, getUserFriendlyMessage, isExceptionImmediatelyAvailable, isNormalDisconnection, isValidRecordingStatusTransition, normalizeStage };
2371
- export type { ASRRequestConfig, ASRRequestV1, AuthenticationException, ConnectionException, ErrorResultV1, FunctionCallResultV1, GameContextV1, IRecognitionClient, IRecognitionClientConfig, IRecognitionClientStats, ISimplifiedVGFRecognitionClient, MetadataResultV1, ProviderException, QuotaExceededException, RealTimeTwoWayWebSocketRecognitionClientConfig, RecognitionCallbackUrl, RecognitionException, RecognitionState, RecordingStatusType, SimplifiedVGFClientConfig, SlotMap, Stage, TimeoutException, TranscriptionResult, TranscriptionResultV1, TranscriptionStatusType, UnknownException, ValidationException };