@volley/recognition-client-sdk 0.1.296 → 0.1.381

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