voice-router-dev 0.2.8 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.mts +515 -0
- package/dist/constants.d.ts +515 -0
- package/dist/constants.js +371 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +333 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/index.d.mts +714 -509
- package/dist/index.d.ts +714 -509
- package/dist/index.js +1573 -681
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1560 -681
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -1
package/dist/index.js
CHANGED
|
@@ -32,6 +32,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
32
32
|
var src_exports = {};
|
|
33
33
|
__export(src_exports, {
|
|
34
34
|
AssemblyAIAdapter: () => AssemblyAIAdapter,
|
|
35
|
+
AssemblyAIEncoding: () => AssemblyAIEncoding,
|
|
36
|
+
AssemblyAISampleRate: () => AssemblyAISampleRate,
|
|
37
|
+
AssemblyAISpeechModel: () => AssemblyAISpeechModel,
|
|
35
38
|
AssemblyAITypes: () => schema_exports2,
|
|
36
39
|
AssemblyAIWebhookHandler: () => AssemblyAIWebhookHandler,
|
|
37
40
|
AzureSTTAdapter: () => AzureSTTAdapter,
|
|
@@ -39,8 +42,18 @@ __export(src_exports, {
|
|
|
39
42
|
BaseAdapter: () => BaseAdapter,
|
|
40
43
|
BaseWebhookHandler: () => BaseWebhookHandler,
|
|
41
44
|
DeepgramAdapter: () => DeepgramAdapter,
|
|
45
|
+
DeepgramEncoding: () => ListenV1EncodingParameter,
|
|
46
|
+
DeepgramModel: () => DeepgramModel,
|
|
47
|
+
DeepgramRedact: () => ListenV1RedactParameterOneOfItem,
|
|
48
|
+
DeepgramTopicMode: () => SharedCustomTopicModeParameter,
|
|
42
49
|
DeepgramWebhookHandler: () => DeepgramWebhookHandler,
|
|
43
50
|
GladiaAdapter: () => GladiaAdapter,
|
|
51
|
+
GladiaBitDepth: () => StreamingSupportedBitDepthEnum,
|
|
52
|
+
GladiaEncoding: () => StreamingSupportedEncodingEnum,
|
|
53
|
+
GladiaLanguage: () => TranscriptionLanguageCodeEnum,
|
|
54
|
+
GladiaModel: () => StreamingSupportedModels,
|
|
55
|
+
GladiaSampleRate: () => StreamingSupportedSampleRateEnum,
|
|
56
|
+
GladiaTranslationLanguage: () => TranslationLanguageCodeEnum,
|
|
44
57
|
GladiaTypes: () => schema_exports,
|
|
45
58
|
GladiaWebhookHandler: () => GladiaWebhookHandler,
|
|
46
59
|
ListenV1EncodingParameter: () => ListenV1EncodingParameter,
|
|
@@ -285,33 +298,17 @@ var ListenV1EncodingParameter = {
|
|
|
285
298
|
g729: "g729"
|
|
286
299
|
};
|
|
287
300
|
|
|
288
|
-
// src/generated/deepgram/schema/
|
|
289
|
-
var
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
mp3: "mp3",
|
|
294
|
-
flac: "flac",
|
|
295
|
-
mulaw: "mulaw",
|
|
296
|
-
alaw: "alaw"
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
// src/generated/deepgram/schema/speakV1ContainerParameter.ts
|
|
300
|
-
var SpeakV1ContainerParameter = {
|
|
301
|
-
none: "none",
|
|
302
|
-
wav: "wav",
|
|
303
|
-
ogg: "ogg"
|
|
301
|
+
// src/generated/deepgram/schema/listenV1RedactParameterOneOfItem.ts
|
|
302
|
+
var ListenV1RedactParameterOneOfItem = {
|
|
303
|
+
pci: "pci",
|
|
304
|
+
pii: "pii",
|
|
305
|
+
numbers: "numbers"
|
|
304
306
|
};
|
|
305
307
|
|
|
306
|
-
// src/generated/deepgram/schema/
|
|
307
|
-
var
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
NUMBER_32000: 32e3,
|
|
311
|
-
NUMBER_48000: 48e3,
|
|
312
|
-
null: null,
|
|
313
|
-
NUMBER_8000: 8e3,
|
|
314
|
-
NUMBER_22050: 22050
|
|
308
|
+
// src/generated/deepgram/schema/sharedCustomTopicModeParameter.ts
|
|
309
|
+
var SharedCustomTopicModeParameter = {
|
|
310
|
+
extended: "extended",
|
|
311
|
+
strict: "strict"
|
|
315
312
|
};
|
|
316
313
|
|
|
317
314
|
// src/generated/gladia/schema/streamingSupportedEncodingEnum.ts
|
|
@@ -338,137 +335,435 @@ var StreamingSupportedBitDepthEnum = {
|
|
|
338
335
|
NUMBER_32: 32
|
|
339
336
|
};
|
|
340
337
|
|
|
341
|
-
// src/
|
|
342
|
-
var
|
|
343
|
-
|
|
344
|
-
HTTP_REQUEST: 6e4,
|
|
345
|
-
/** Audio processing timeout for long audio files (120 seconds) */
|
|
346
|
-
AUDIO_PROCESSING: 12e4,
|
|
347
|
-
/** WebSocket connection establishment timeout (10 seconds) */
|
|
348
|
-
WS_CONNECTION: 1e4,
|
|
349
|
-
/** WebSocket graceful close timeout (5 seconds) */
|
|
350
|
-
WS_CLOSE: 5e3
|
|
351
|
-
};
|
|
352
|
-
var DEFAULT_POLLING = {
|
|
353
|
-
/** Maximum number of polling attempts before timing out */
|
|
354
|
-
MAX_ATTEMPTS: 60,
|
|
355
|
-
/** Standard interval between polling attempts (2 seconds) */
|
|
356
|
-
INTERVAL_MS: 2e3,
|
|
357
|
-
/** Slower interval for long-running jobs (3 seconds) */
|
|
358
|
-
SLOW_INTERVAL_MS: 3e3
|
|
338
|
+
// src/generated/gladia/schema/streamingSupportedModels.ts
|
|
339
|
+
var StreamingSupportedModels = {
|
|
340
|
+
"solaria-1": "solaria-1"
|
|
359
341
|
};
|
|
360
342
|
|
|
361
|
-
// src/
|
|
362
|
-
var
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
343
|
+
// src/generated/gladia/schema/transcriptionLanguageCodeEnum.ts
|
|
344
|
+
var TranscriptionLanguageCodeEnum = {
|
|
345
|
+
af: "af",
|
|
346
|
+
am: "am",
|
|
347
|
+
ar: "ar",
|
|
348
|
+
as: "as",
|
|
349
|
+
az: "az",
|
|
350
|
+
ba: "ba",
|
|
351
|
+
be: "be",
|
|
352
|
+
bg: "bg",
|
|
353
|
+
bn: "bn",
|
|
354
|
+
bo: "bo",
|
|
355
|
+
br: "br",
|
|
356
|
+
bs: "bs",
|
|
357
|
+
ca: "ca",
|
|
358
|
+
cs: "cs",
|
|
359
|
+
cy: "cy",
|
|
360
|
+
da: "da",
|
|
361
|
+
de: "de",
|
|
362
|
+
el: "el",
|
|
363
|
+
en: "en",
|
|
364
|
+
es: "es",
|
|
365
|
+
et: "et",
|
|
366
|
+
eu: "eu",
|
|
367
|
+
fa: "fa",
|
|
368
|
+
fi: "fi",
|
|
369
|
+
fo: "fo",
|
|
370
|
+
fr: "fr",
|
|
371
|
+
gl: "gl",
|
|
372
|
+
gu: "gu",
|
|
373
|
+
ha: "ha",
|
|
374
|
+
haw: "haw",
|
|
375
|
+
he: "he",
|
|
376
|
+
hi: "hi",
|
|
377
|
+
hr: "hr",
|
|
378
|
+
ht: "ht",
|
|
379
|
+
hu: "hu",
|
|
380
|
+
hy: "hy",
|
|
381
|
+
id: "id",
|
|
382
|
+
is: "is",
|
|
383
|
+
it: "it",
|
|
384
|
+
ja: "ja",
|
|
385
|
+
jw: "jw",
|
|
386
|
+
ka: "ka",
|
|
387
|
+
kk: "kk",
|
|
388
|
+
km: "km",
|
|
389
|
+
kn: "kn",
|
|
390
|
+
ko: "ko",
|
|
391
|
+
la: "la",
|
|
392
|
+
lb: "lb",
|
|
393
|
+
ln: "ln",
|
|
394
|
+
lo: "lo",
|
|
395
|
+
lt: "lt",
|
|
396
|
+
lv: "lv",
|
|
397
|
+
mg: "mg",
|
|
398
|
+
mi: "mi",
|
|
399
|
+
mk: "mk",
|
|
400
|
+
ml: "ml",
|
|
401
|
+
mn: "mn",
|
|
402
|
+
mr: "mr",
|
|
403
|
+
ms: "ms",
|
|
404
|
+
mt: "mt",
|
|
405
|
+
my: "my",
|
|
406
|
+
ne: "ne",
|
|
407
|
+
nl: "nl",
|
|
408
|
+
nn: "nn",
|
|
409
|
+
no: "no",
|
|
410
|
+
oc: "oc",
|
|
411
|
+
pa: "pa",
|
|
412
|
+
pl: "pl",
|
|
413
|
+
ps: "ps",
|
|
414
|
+
pt: "pt",
|
|
415
|
+
ro: "ro",
|
|
416
|
+
ru: "ru",
|
|
417
|
+
sa: "sa",
|
|
418
|
+
sd: "sd",
|
|
419
|
+
si: "si",
|
|
420
|
+
sk: "sk",
|
|
421
|
+
sl: "sl",
|
|
422
|
+
sn: "sn",
|
|
423
|
+
so: "so",
|
|
424
|
+
sq: "sq",
|
|
425
|
+
sr: "sr",
|
|
426
|
+
su: "su",
|
|
427
|
+
sv: "sv",
|
|
428
|
+
sw: "sw",
|
|
429
|
+
ta: "ta",
|
|
430
|
+
te: "te",
|
|
431
|
+
tg: "tg",
|
|
432
|
+
th: "th",
|
|
433
|
+
tk: "tk",
|
|
434
|
+
tl: "tl",
|
|
435
|
+
tr: "tr",
|
|
436
|
+
tt: "tt",
|
|
437
|
+
uk: "uk",
|
|
438
|
+
ur: "ur",
|
|
439
|
+
uz: "uz",
|
|
440
|
+
vi: "vi",
|
|
441
|
+
yi: "yi",
|
|
442
|
+
yo: "yo",
|
|
443
|
+
zh: "zh"
|
|
392
444
|
};
|
|
393
|
-
function createError(code, customMessage, details) {
|
|
394
|
-
return {
|
|
395
|
-
code,
|
|
396
|
-
message: customMessage || ERROR_MESSAGES[code],
|
|
397
|
-
details
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
445
|
|
|
401
|
-
// src/
|
|
402
|
-
var
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
446
|
+
// src/generated/gladia/schema/translationLanguageCodeEnum.ts
|
|
447
|
+
var TranslationLanguageCodeEnum = {
|
|
448
|
+
af: "af",
|
|
449
|
+
am: "am",
|
|
450
|
+
ar: "ar",
|
|
451
|
+
as: "as",
|
|
452
|
+
az: "az",
|
|
453
|
+
ba: "ba",
|
|
454
|
+
be: "be",
|
|
455
|
+
bg: "bg",
|
|
456
|
+
bn: "bn",
|
|
457
|
+
bo: "bo",
|
|
458
|
+
br: "br",
|
|
459
|
+
bs: "bs",
|
|
460
|
+
ca: "ca",
|
|
461
|
+
cs: "cs",
|
|
462
|
+
cy: "cy",
|
|
463
|
+
da: "da",
|
|
464
|
+
de: "de",
|
|
465
|
+
el: "el",
|
|
466
|
+
en: "en",
|
|
467
|
+
es: "es",
|
|
468
|
+
et: "et",
|
|
469
|
+
eu: "eu",
|
|
470
|
+
fa: "fa",
|
|
471
|
+
fi: "fi",
|
|
472
|
+
fo: "fo",
|
|
473
|
+
fr: "fr",
|
|
474
|
+
gl: "gl",
|
|
475
|
+
gu: "gu",
|
|
476
|
+
ha: "ha",
|
|
477
|
+
haw: "haw",
|
|
478
|
+
he: "he",
|
|
479
|
+
hi: "hi",
|
|
480
|
+
hr: "hr",
|
|
481
|
+
ht: "ht",
|
|
482
|
+
hu: "hu",
|
|
483
|
+
hy: "hy",
|
|
484
|
+
id: "id",
|
|
485
|
+
is: "is",
|
|
486
|
+
it: "it",
|
|
487
|
+
ja: "ja",
|
|
488
|
+
jw: "jw",
|
|
489
|
+
ka: "ka",
|
|
490
|
+
kk: "kk",
|
|
491
|
+
km: "km",
|
|
492
|
+
kn: "kn",
|
|
493
|
+
ko: "ko",
|
|
494
|
+
la: "la",
|
|
495
|
+
lb: "lb",
|
|
496
|
+
ln: "ln",
|
|
497
|
+
lo: "lo",
|
|
498
|
+
lt: "lt",
|
|
499
|
+
lv: "lv",
|
|
500
|
+
mg: "mg",
|
|
501
|
+
mi: "mi",
|
|
502
|
+
mk: "mk",
|
|
503
|
+
ml: "ml",
|
|
504
|
+
mn: "mn",
|
|
505
|
+
mr: "mr",
|
|
506
|
+
ms: "ms",
|
|
507
|
+
mt: "mt",
|
|
508
|
+
my: "my",
|
|
509
|
+
ne: "ne",
|
|
510
|
+
nl: "nl",
|
|
511
|
+
nn: "nn",
|
|
512
|
+
no: "no",
|
|
513
|
+
oc: "oc",
|
|
514
|
+
pa: "pa",
|
|
515
|
+
pl: "pl",
|
|
516
|
+
ps: "ps",
|
|
517
|
+
pt: "pt",
|
|
518
|
+
ro: "ro",
|
|
519
|
+
ru: "ru",
|
|
520
|
+
sa: "sa",
|
|
521
|
+
sd: "sd",
|
|
522
|
+
si: "si",
|
|
523
|
+
sk: "sk",
|
|
524
|
+
sl: "sl",
|
|
525
|
+
sn: "sn",
|
|
526
|
+
so: "so",
|
|
527
|
+
sq: "sq",
|
|
528
|
+
sr: "sr",
|
|
529
|
+
su: "su",
|
|
530
|
+
sv: "sv",
|
|
531
|
+
sw: "sw",
|
|
532
|
+
ta: "ta",
|
|
533
|
+
te: "te",
|
|
534
|
+
tg: "tg",
|
|
535
|
+
th: "th",
|
|
536
|
+
tk: "tk",
|
|
537
|
+
tl: "tl",
|
|
538
|
+
tr: "tr",
|
|
539
|
+
tt: "tt",
|
|
540
|
+
uk: "uk",
|
|
541
|
+
ur: "ur",
|
|
542
|
+
uz: "uz",
|
|
543
|
+
vi: "vi",
|
|
544
|
+
wo: "wo",
|
|
545
|
+
yi: "yi",
|
|
546
|
+
yo: "yo",
|
|
547
|
+
zh: "zh"
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
// src/constants.ts
|
|
551
|
+
var DeepgramModel = {
|
|
552
|
+
// Nova 3 models (latest)
|
|
553
|
+
"nova-3": "nova-3",
|
|
554
|
+
"nova-3-general": "nova-3-general",
|
|
555
|
+
"nova-3-medical": "nova-3-medical",
|
|
556
|
+
// Nova 2 models
|
|
557
|
+
"nova-2": "nova-2",
|
|
558
|
+
"nova-2-general": "nova-2-general",
|
|
559
|
+
"nova-2-meeting": "nova-2-meeting",
|
|
560
|
+
"nova-2-finance": "nova-2-finance",
|
|
561
|
+
"nova-2-conversationalai": "nova-2-conversationalai",
|
|
562
|
+
"nova-2-voicemail": "nova-2-voicemail",
|
|
563
|
+
"nova-2-video": "nova-2-video",
|
|
564
|
+
"nova-2-medical": "nova-2-medical",
|
|
565
|
+
"nova-2-drivethru": "nova-2-drivethru",
|
|
566
|
+
"nova-2-automotive": "nova-2-automotive",
|
|
567
|
+
// Nova 1 models
|
|
568
|
+
nova: "nova",
|
|
569
|
+
"nova-general": "nova-general",
|
|
570
|
+
"nova-phonecall": "nova-phonecall",
|
|
571
|
+
"nova-medical": "nova-medical",
|
|
572
|
+
// Enhanced models
|
|
573
|
+
enhanced: "enhanced",
|
|
574
|
+
"enhanced-general": "enhanced-general",
|
|
575
|
+
"enhanced-meeting": "enhanced-meeting",
|
|
576
|
+
"enhanced-phonecall": "enhanced-phonecall",
|
|
577
|
+
"enhanced-finance": "enhanced-finance",
|
|
578
|
+
// Base models
|
|
579
|
+
base: "base",
|
|
580
|
+
meeting: "meeting",
|
|
581
|
+
phonecall: "phonecall",
|
|
582
|
+
finance: "finance",
|
|
583
|
+
conversationalai: "conversationalai",
|
|
584
|
+
voicemail: "voicemail",
|
|
585
|
+
video: "video"
|
|
586
|
+
};
|
|
587
|
+
var AssemblyAIEncoding = {
|
|
588
|
+
/** PCM signed 16-bit little-endian (recommended) */
|
|
589
|
+
pcmS16le: "pcm_s16le",
|
|
590
|
+
/** μ-law (telephony) */
|
|
591
|
+
pcmMulaw: "pcm_mulaw"
|
|
592
|
+
};
|
|
593
|
+
var AssemblyAISpeechModel = {
|
|
594
|
+
/** Optimized for English */
|
|
595
|
+
english: "universal-streaming-english",
|
|
596
|
+
/** Supports 20+ languages */
|
|
597
|
+
multilingual: "universal-streaming-multilingual"
|
|
598
|
+
};
|
|
599
|
+
var AssemblyAISampleRate = {
|
|
600
|
+
rate8000: 8e3,
|
|
601
|
+
rate16000: 16e3,
|
|
602
|
+
rate22050: 22050,
|
|
603
|
+
rate44100: 44100,
|
|
604
|
+
rate48000: 48e3
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
// src/generated/deepgram/schema/speakV1EncodingParameter.ts
|
|
608
|
+
var SpeakV1EncodingParameter = {
|
|
609
|
+
linear16: "linear16",
|
|
610
|
+
aac: "aac",
|
|
611
|
+
opus: "opus",
|
|
612
|
+
mp3: "mp3",
|
|
613
|
+
flac: "flac",
|
|
614
|
+
mulaw: "mulaw",
|
|
615
|
+
alaw: "alaw"
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
// src/generated/deepgram/schema/speakV1ContainerParameter.ts
|
|
619
|
+
var SpeakV1ContainerParameter = {
|
|
620
|
+
none: "none",
|
|
621
|
+
wav: "wav",
|
|
622
|
+
ogg: "ogg"
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
// src/generated/deepgram/schema/speakV1SampleRateParameter.ts
|
|
626
|
+
var SpeakV1SampleRateParameter = {
|
|
627
|
+
NUMBER_16000: 16e3,
|
|
628
|
+
NUMBER_24000: 24e3,
|
|
629
|
+
NUMBER_32000: 32e3,
|
|
630
|
+
NUMBER_48000: 48e3,
|
|
631
|
+
null: null,
|
|
632
|
+
NUMBER_8000: 8e3,
|
|
633
|
+
NUMBER_22050: 22050
|
|
634
|
+
};
|
|
635
|
+
|
|
636
|
+
// src/constants/defaults.ts
|
|
637
|
+
var DEFAULT_TIMEOUTS = {
|
|
638
|
+
/** Standard HTTP request timeout for API calls (60 seconds) */
|
|
639
|
+
HTTP_REQUEST: 6e4,
|
|
640
|
+
/** Audio processing timeout for long audio files (120 seconds) */
|
|
641
|
+
AUDIO_PROCESSING: 12e4,
|
|
642
|
+
/** WebSocket connection establishment timeout (10 seconds) */
|
|
643
|
+
WS_CONNECTION: 1e4,
|
|
644
|
+
/** WebSocket graceful close timeout (5 seconds) */
|
|
645
|
+
WS_CLOSE: 5e3
|
|
646
|
+
};
|
|
647
|
+
var DEFAULT_POLLING = {
|
|
648
|
+
/** Maximum number of polling attempts before timing out */
|
|
649
|
+
MAX_ATTEMPTS: 60,
|
|
650
|
+
/** Standard interval between polling attempts (2 seconds) */
|
|
651
|
+
INTERVAL_MS: 2e3,
|
|
652
|
+
/** Slower interval for long-running jobs (3 seconds) */
|
|
653
|
+
SLOW_INTERVAL_MS: 3e3
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
// src/utils/errors.ts
|
|
657
|
+
var ERROR_CODES = {
|
|
658
|
+
/** Failed to parse API response or WebSocket message */
|
|
659
|
+
PARSE_ERROR: "PARSE_ERROR",
|
|
660
|
+
/** WebSocket connection error */
|
|
661
|
+
WEBSOCKET_ERROR: "WEBSOCKET_ERROR",
|
|
662
|
+
/** Async transcription job did not complete within timeout */
|
|
663
|
+
POLLING_TIMEOUT: "POLLING_TIMEOUT",
|
|
664
|
+
/** Transcription processing failed on provider side */
|
|
665
|
+
TRANSCRIPTION_ERROR: "TRANSCRIPTION_ERROR",
|
|
666
|
+
/** Connection attempt timed out */
|
|
667
|
+
CONNECTION_TIMEOUT: "CONNECTION_TIMEOUT",
|
|
668
|
+
/** Invalid input provided to API */
|
|
669
|
+
INVALID_INPUT: "INVALID_INPUT",
|
|
670
|
+
/** Requested operation not supported by provider */
|
|
671
|
+
NOT_SUPPORTED: "NOT_SUPPORTED",
|
|
672
|
+
/** No transcription results available */
|
|
673
|
+
NO_RESULTS: "NO_RESULTS",
|
|
674
|
+
/** Unspecified or unknown error */
|
|
675
|
+
UNKNOWN_ERROR: "UNKNOWN_ERROR"
|
|
676
|
+
};
|
|
677
|
+
var ERROR_MESSAGES = {
|
|
678
|
+
PARSE_ERROR: "Failed to parse response data",
|
|
679
|
+
WEBSOCKET_ERROR: "WebSocket connection error",
|
|
680
|
+
POLLING_TIMEOUT: "Transcription did not complete within timeout period",
|
|
681
|
+
TRANSCRIPTION_ERROR: "Transcription processing failed",
|
|
682
|
+
CONNECTION_TIMEOUT: "Connection attempt timed out",
|
|
683
|
+
INVALID_INPUT: "Invalid input provided",
|
|
684
|
+
NOT_SUPPORTED: "Operation not supported by this provider",
|
|
685
|
+
NO_RESULTS: "No transcription results available",
|
|
686
|
+
UNKNOWN_ERROR: "An unknown error occurred"
|
|
687
|
+
};
|
|
688
|
+
function createError(code, customMessage, details) {
|
|
689
|
+
return {
|
|
690
|
+
code,
|
|
691
|
+
message: customMessage || ERROR_MESSAGES[code],
|
|
692
|
+
details
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// src/adapters/base-adapter.ts
|
|
697
|
+
var BaseAdapter = class {
|
|
698
|
+
initialize(config) {
|
|
699
|
+
this.config = config;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Helper method to create error responses with stack traces
|
|
703
|
+
*
|
|
704
|
+
* @param error - Error object or unknown error
|
|
705
|
+
* @param statusCode - Optional HTTP status code
|
|
706
|
+
* @param code - Optional error code (defaults to extracted or UNKNOWN_ERROR)
|
|
707
|
+
*/
|
|
708
|
+
createErrorResponse(error, statusCode, code) {
|
|
709
|
+
const err = error;
|
|
710
|
+
const httpStatus = statusCode || err.statusCode || err.response?.status;
|
|
711
|
+
const httpStatusText = err.response?.statusText;
|
|
712
|
+
const responseData = err.response?.data;
|
|
713
|
+
return {
|
|
714
|
+
success: false,
|
|
715
|
+
provider: this.name,
|
|
716
|
+
error: {
|
|
717
|
+
code: code || err.code || ERROR_CODES.UNKNOWN_ERROR,
|
|
718
|
+
message: err.message || "An unknown error occurred",
|
|
719
|
+
statusCode: httpStatus,
|
|
720
|
+
details: {
|
|
721
|
+
// Include full error object
|
|
722
|
+
error,
|
|
723
|
+
// Include stack trace if available
|
|
724
|
+
stack: err.stack,
|
|
725
|
+
// Include HTTP response details
|
|
726
|
+
httpStatus,
|
|
727
|
+
httpStatusText,
|
|
728
|
+
responseData,
|
|
729
|
+
// Include provider name for debugging
|
|
730
|
+
provider: this.name
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Helper method to validate configuration
|
|
737
|
+
*/
|
|
738
|
+
validateConfig() {
|
|
739
|
+
if (!this.config) {
|
|
740
|
+
throw new Error(`Adapter ${this.name} is not initialized. Call initialize() first.`);
|
|
741
|
+
}
|
|
742
|
+
if (!this.config.apiKey) {
|
|
743
|
+
throw new Error(`API key is required for ${this.name} provider`);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Build axios config for generated API client functions
|
|
748
|
+
*
|
|
749
|
+
* @param authHeaderName - Header name for API key (e.g., "Authorization", "x-gladia-key")
|
|
750
|
+
* @param authHeaderValue - Optional function to format auth header value (defaults to raw API key)
|
|
751
|
+
* @returns Axios config object
|
|
752
|
+
*/
|
|
753
|
+
getAxiosConfig(authHeaderName = "Authorization", authHeaderValue) {
|
|
754
|
+
this.validateConfig();
|
|
755
|
+
const authValue = authHeaderValue ? authHeaderValue(this.config.apiKey) : this.config.apiKey;
|
|
756
|
+
return {
|
|
757
|
+
baseURL: this.config.baseUrl || this.baseUrl,
|
|
758
|
+
timeout: this.config.timeout || DEFAULT_TIMEOUTS.HTTP_REQUEST,
|
|
759
|
+
headers: {
|
|
760
|
+
[authHeaderName]: authValue,
|
|
761
|
+
"Content-Type": "application/json",
|
|
762
|
+
...this.config.headers
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
472
767
|
* Generic polling helper for async transcription jobs
|
|
473
768
|
*
|
|
474
769
|
* Polls getTranscript() until job completes or times out.
|
|
@@ -1120,365 +1415,153 @@ var HistoryControllerGetListV1StatusItem = {
|
|
|
1120
1415
|
queued: "queued",
|
|
1121
1416
|
processing: "processing",
|
|
1122
1417
|
done: "done",
|
|
1123
|
-
error: "error"
|
|
1124
|
-
};
|
|
1125
|
-
|
|
1126
|
-
// src/generated/gladia/schema/namedEntityRecognitionMessageType.ts
|
|
1127
|
-
var NamedEntityRecognitionMessageType = {
|
|
1128
|
-
named_entity_recognition: "named_entity_recognition"
|
|
1129
|
-
};
|
|
1130
|
-
|
|
1131
|
-
// src/generated/gladia/schema/postChapterizationMessageType.ts
|
|
1132
|
-
var PostChapterizationMessageType = {
|
|
1133
|
-
post_chapterization: "post_chapterization"
|
|
1134
|
-
};
|
|
1135
|
-
|
|
1136
|
-
// src/generated/gladia/schema/postFinalTranscriptMessageType.ts
|
|
1137
|
-
var PostFinalTranscriptMessageType = {
|
|
1138
|
-
post_final_transcript: "post_final_transcript"
|
|
1139
|
-
};
|
|
1140
|
-
|
|
1141
|
-
// src/generated/gladia/schema/postSummarizationMessageType.ts
|
|
1142
|
-
var PostSummarizationMessageType = {
|
|
1143
|
-
post_summarization: "post_summarization"
|
|
1144
|
-
};
|
|
1145
|
-
|
|
1146
|
-
// src/generated/gladia/schema/postTranscriptMessageType.ts
|
|
1147
|
-
var PostTranscriptMessageType = {
|
|
1148
|
-
post_transcript: "post_transcript"
|
|
1149
|
-
};
|
|
1150
|
-
|
|
1151
|
-
// src/generated/gladia/schema/preRecordedControllerGetPreRecordedJobsV2StatusItem.ts
|
|
1152
|
-
var PreRecordedControllerGetPreRecordedJobsV2StatusItem = {
|
|
1153
|
-
queued: "queued",
|
|
1154
|
-
processing: "processing",
|
|
1155
|
-
done: "done",
|
|
1156
|
-
error: "error"
|
|
1157
|
-
};
|
|
1158
|
-
|
|
1159
|
-
// src/generated/gladia/schema/preRecordedResponseKind.ts
|
|
1160
|
-
var PreRecordedResponseKind = {
|
|
1161
|
-
"pre-recorded": "pre-recorded"
|
|
1162
|
-
};
|
|
1163
|
-
|
|
1164
|
-
// src/generated/gladia/schema/preRecordedResponseStatus.ts
|
|
1165
|
-
var PreRecordedResponseStatus = {
|
|
1166
|
-
queued: "queued",
|
|
1167
|
-
processing: "processing",
|
|
1168
|
-
done: "done",
|
|
1169
|
-
error: "error"
|
|
1170
|
-
};
|
|
1171
|
-
|
|
1172
|
-
// src/generated/gladia/schema/sentimentAnalysisMessageType.ts
|
|
1173
|
-
var SentimentAnalysisMessageType = {
|
|
1174
|
-
sentiment_analysis: "sentiment_analysis"
|
|
1175
|
-
};
|
|
1176
|
-
|
|
1177
|
-
// src/generated/gladia/schema/speechEndMessageType.ts
|
|
1178
|
-
var SpeechEndMessageType = {
|
|
1179
|
-
speech_end: "speech_end"
|
|
1180
|
-
};
|
|
1181
|
-
|
|
1182
|
-
// src/generated/gladia/schema/speechStartMessageType.ts
|
|
1183
|
-
var SpeechStartMessageType = {
|
|
1184
|
-
speech_start: "speech_start"
|
|
1185
|
-
};
|
|
1186
|
-
|
|
1187
|
-
// src/generated/gladia/schema/startRecordingMessageType.ts
|
|
1188
|
-
var StartRecordingMessageType = {
|
|
1189
|
-
start_recording: "start_recording"
|
|
1190
|
-
};
|
|
1191
|
-
|
|
1192
|
-
// src/generated/gladia/schema/startSessionMessageType.ts
|
|
1193
|
-
var StartSessionMessageType = {
|
|
1194
|
-
start_session: "start_session"
|
|
1195
|
-
};
|
|
1196
|
-
|
|
1197
|
-
// src/generated/gladia/schema/stopRecordingAckMessageType.ts
|
|
1198
|
-
var StopRecordingAckMessageType = {
|
|
1199
|
-
stop_recording: "stop_recording"
|
|
1200
|
-
};
|
|
1201
|
-
|
|
1202
|
-
// src/generated/gladia/schema/stopRecordingActionType.ts
|
|
1203
|
-
var StopRecordingActionType = {
|
|
1204
|
-
stop_recording: "stop_recording"
|
|
1205
|
-
};
|
|
1206
|
-
|
|
1207
|
-
// src/generated/gladia/schema/streamingControllerGetStreamingJobsV2StatusItem.ts
|
|
1208
|
-
var StreamingControllerGetStreamingJobsV2StatusItem = {
|
|
1209
|
-
queued: "queued",
|
|
1210
|
-
processing: "processing",
|
|
1211
|
-
done: "done",
|
|
1212
|
-
error: "error"
|
|
1213
|
-
};
|
|
1214
|
-
|
|
1215
|
-
// src/generated/gladia/schema/streamingResponseKind.ts
|
|
1216
|
-
var StreamingResponseKind = {
|
|
1217
|
-
live: "live"
|
|
1218
|
-
};
|
|
1219
|
-
|
|
1220
|
-
// src/generated/gladia/schema/streamingResponseStatus.ts
|
|
1221
|
-
var StreamingResponseStatus = {
|
|
1222
|
-
queued: "queued",
|
|
1223
|
-
processing: "processing",
|
|
1224
|
-
done: "done",
|
|
1225
|
-
error: "error"
|
|
1226
|
-
};
|
|
1227
|
-
|
|
1228
|
-
// src/generated/gladia/schema/streamingSupportedModels.ts
|
|
1229
|
-
var StreamingSupportedModels = {
|
|
1230
|
-
"solaria-1": "solaria-1"
|
|
1418
|
+
error: "error"
|
|
1231
1419
|
};
|
|
1232
1420
|
|
|
1233
|
-
// src/generated/gladia/schema/
|
|
1234
|
-
var
|
|
1235
|
-
|
|
1236
|
-
"eu-west": "eu-west"
|
|
1421
|
+
// src/generated/gladia/schema/namedEntityRecognitionMessageType.ts
|
|
1422
|
+
var NamedEntityRecognitionMessageType = {
|
|
1423
|
+
named_entity_recognition: "named_entity_recognition"
|
|
1237
1424
|
};
|
|
1238
1425
|
|
|
1239
|
-
// src/generated/gladia/schema/
|
|
1240
|
-
var
|
|
1241
|
-
|
|
1242
|
-
vtt: "vtt"
|
|
1426
|
+
// src/generated/gladia/schema/postChapterizationMessageType.ts
|
|
1427
|
+
var PostChapterizationMessageType = {
|
|
1428
|
+
post_chapterization: "post_chapterization"
|
|
1243
1429
|
};
|
|
1244
1430
|
|
|
1245
|
-
// src/generated/gladia/schema/
|
|
1246
|
-
var
|
|
1247
|
-
|
|
1248
|
-
compliance: "compliance"
|
|
1431
|
+
// src/generated/gladia/schema/postFinalTranscriptMessageType.ts
|
|
1432
|
+
var PostFinalTranscriptMessageType = {
|
|
1433
|
+
post_final_transcript: "post_final_transcript"
|
|
1249
1434
|
};
|
|
1250
1435
|
|
|
1251
|
-
// src/generated/gladia/schema/
|
|
1252
|
-
var
|
|
1253
|
-
|
|
1254
|
-
bullet_points: "bullet_points",
|
|
1255
|
-
concise: "concise"
|
|
1436
|
+
// src/generated/gladia/schema/postSummarizationMessageType.ts
|
|
1437
|
+
var PostSummarizationMessageType = {
|
|
1438
|
+
post_summarization: "post_summarization"
|
|
1256
1439
|
};
|
|
1257
1440
|
|
|
1258
|
-
// src/generated/gladia/schema/
|
|
1259
|
-
var
|
|
1260
|
-
|
|
1261
|
-
live: "live"
|
|
1441
|
+
// src/generated/gladia/schema/postTranscriptMessageType.ts
|
|
1442
|
+
var PostTranscriptMessageType = {
|
|
1443
|
+
post_transcript: "post_transcript"
|
|
1262
1444
|
};
|
|
1263
1445
|
|
|
1264
|
-
// src/generated/gladia/schema/
|
|
1265
|
-
var
|
|
1446
|
+
// src/generated/gladia/schema/preRecordedControllerGetPreRecordedJobsV2StatusItem.ts
|
|
1447
|
+
var PreRecordedControllerGetPreRecordedJobsV2StatusItem = {
|
|
1266
1448
|
queued: "queued",
|
|
1267
1449
|
processing: "processing",
|
|
1268
1450
|
done: "done",
|
|
1269
1451
|
error: "error"
|
|
1270
1452
|
};
|
|
1271
1453
|
|
|
1272
|
-
// src/generated/gladia/schema/
|
|
1273
|
-
var
|
|
1274
|
-
|
|
1275
|
-
am: "am",
|
|
1276
|
-
ar: "ar",
|
|
1277
|
-
as: "as",
|
|
1278
|
-
az: "az",
|
|
1279
|
-
ba: "ba",
|
|
1280
|
-
be: "be",
|
|
1281
|
-
bg: "bg",
|
|
1282
|
-
bn: "bn",
|
|
1283
|
-
bo: "bo",
|
|
1284
|
-
br: "br",
|
|
1285
|
-
bs: "bs",
|
|
1286
|
-
ca: "ca",
|
|
1287
|
-
cs: "cs",
|
|
1288
|
-
cy: "cy",
|
|
1289
|
-
da: "da",
|
|
1290
|
-
de: "de",
|
|
1291
|
-
el: "el",
|
|
1292
|
-
en: "en",
|
|
1293
|
-
es: "es",
|
|
1294
|
-
et: "et",
|
|
1295
|
-
eu: "eu",
|
|
1296
|
-
fa: "fa",
|
|
1297
|
-
fi: "fi",
|
|
1298
|
-
fo: "fo",
|
|
1299
|
-
fr: "fr",
|
|
1300
|
-
gl: "gl",
|
|
1301
|
-
gu: "gu",
|
|
1302
|
-
ha: "ha",
|
|
1303
|
-
haw: "haw",
|
|
1304
|
-
he: "he",
|
|
1305
|
-
hi: "hi",
|
|
1306
|
-
hr: "hr",
|
|
1307
|
-
ht: "ht",
|
|
1308
|
-
hu: "hu",
|
|
1309
|
-
hy: "hy",
|
|
1310
|
-
id: "id",
|
|
1311
|
-
is: "is",
|
|
1312
|
-
it: "it",
|
|
1313
|
-
ja: "ja",
|
|
1314
|
-
jw: "jw",
|
|
1315
|
-
ka: "ka",
|
|
1316
|
-
kk: "kk",
|
|
1317
|
-
km: "km",
|
|
1318
|
-
kn: "kn",
|
|
1319
|
-
ko: "ko",
|
|
1320
|
-
la: "la",
|
|
1321
|
-
lb: "lb",
|
|
1322
|
-
ln: "ln",
|
|
1323
|
-
lo: "lo",
|
|
1324
|
-
lt: "lt",
|
|
1325
|
-
lv: "lv",
|
|
1326
|
-
mg: "mg",
|
|
1327
|
-
mi: "mi",
|
|
1328
|
-
mk: "mk",
|
|
1329
|
-
ml: "ml",
|
|
1330
|
-
mn: "mn",
|
|
1331
|
-
mr: "mr",
|
|
1332
|
-
ms: "ms",
|
|
1333
|
-
mt: "mt",
|
|
1334
|
-
my: "my",
|
|
1335
|
-
ne: "ne",
|
|
1336
|
-
nl: "nl",
|
|
1337
|
-
nn: "nn",
|
|
1338
|
-
no: "no",
|
|
1339
|
-
oc: "oc",
|
|
1340
|
-
pa: "pa",
|
|
1341
|
-
pl: "pl",
|
|
1342
|
-
ps: "ps",
|
|
1343
|
-
pt: "pt",
|
|
1344
|
-
ro: "ro",
|
|
1345
|
-
ru: "ru",
|
|
1346
|
-
sa: "sa",
|
|
1347
|
-
sd: "sd",
|
|
1348
|
-
si: "si",
|
|
1349
|
-
sk: "sk",
|
|
1350
|
-
sl: "sl",
|
|
1351
|
-
sn: "sn",
|
|
1352
|
-
so: "so",
|
|
1353
|
-
sq: "sq",
|
|
1354
|
-
sr: "sr",
|
|
1355
|
-
su: "su",
|
|
1356
|
-
sv: "sv",
|
|
1357
|
-
sw: "sw",
|
|
1358
|
-
ta: "ta",
|
|
1359
|
-
te: "te",
|
|
1360
|
-
tg: "tg",
|
|
1361
|
-
th: "th",
|
|
1362
|
-
tk: "tk",
|
|
1363
|
-
tl: "tl",
|
|
1364
|
-
tr: "tr",
|
|
1365
|
-
tt: "tt",
|
|
1366
|
-
uk: "uk",
|
|
1367
|
-
ur: "ur",
|
|
1368
|
-
uz: "uz",
|
|
1369
|
-
vi: "vi",
|
|
1370
|
-
yi: "yi",
|
|
1371
|
-
yo: "yo",
|
|
1372
|
-
zh: "zh"
|
|
1454
|
+
// src/generated/gladia/schema/preRecordedResponseKind.ts
|
|
1455
|
+
var PreRecordedResponseKind = {
|
|
1456
|
+
"pre-recorded": "pre-recorded"
|
|
1373
1457
|
};
|
|
1374
1458
|
|
|
1375
|
-
// src/generated/gladia/schema/
|
|
1376
|
-
var
|
|
1377
|
-
|
|
1459
|
+
// src/generated/gladia/schema/preRecordedResponseStatus.ts
|
|
1460
|
+
var PreRecordedResponseStatus = {
|
|
1461
|
+
queued: "queued",
|
|
1462
|
+
processing: "processing",
|
|
1463
|
+
done: "done",
|
|
1464
|
+
error: "error"
|
|
1378
1465
|
};
|
|
1379
1466
|
|
|
1380
|
-
// src/generated/gladia/schema/
|
|
1381
|
-
var
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
wo: "wo",
|
|
1479
|
-
yi: "yi",
|
|
1480
|
-
yo: "yo",
|
|
1481
|
-
zh: "zh"
|
|
1467
|
+
// src/generated/gladia/schema/sentimentAnalysisMessageType.ts
|
|
1468
|
+
var SentimentAnalysisMessageType = {
|
|
1469
|
+
sentiment_analysis: "sentiment_analysis"
|
|
1470
|
+
};
|
|
1471
|
+
|
|
1472
|
+
// src/generated/gladia/schema/speechEndMessageType.ts
|
|
1473
|
+
var SpeechEndMessageType = {
|
|
1474
|
+
speech_end: "speech_end"
|
|
1475
|
+
};
|
|
1476
|
+
|
|
1477
|
+
// src/generated/gladia/schema/speechStartMessageType.ts
|
|
1478
|
+
var SpeechStartMessageType = {
|
|
1479
|
+
speech_start: "speech_start"
|
|
1480
|
+
};
|
|
1481
|
+
|
|
1482
|
+
// src/generated/gladia/schema/startRecordingMessageType.ts
|
|
1483
|
+
var StartRecordingMessageType = {
|
|
1484
|
+
start_recording: "start_recording"
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1487
|
+
// src/generated/gladia/schema/startSessionMessageType.ts
|
|
1488
|
+
var StartSessionMessageType = {
|
|
1489
|
+
start_session: "start_session"
|
|
1490
|
+
};
|
|
1491
|
+
|
|
1492
|
+
// src/generated/gladia/schema/stopRecordingAckMessageType.ts
|
|
1493
|
+
var StopRecordingAckMessageType = {
|
|
1494
|
+
stop_recording: "stop_recording"
|
|
1495
|
+
};
|
|
1496
|
+
|
|
1497
|
+
// src/generated/gladia/schema/stopRecordingActionType.ts
|
|
1498
|
+
var StopRecordingActionType = {
|
|
1499
|
+
stop_recording: "stop_recording"
|
|
1500
|
+
};
|
|
1501
|
+
|
|
1502
|
+
// src/generated/gladia/schema/streamingControllerGetStreamingJobsV2StatusItem.ts
|
|
1503
|
+
var StreamingControllerGetStreamingJobsV2StatusItem = {
|
|
1504
|
+
queued: "queued",
|
|
1505
|
+
processing: "processing",
|
|
1506
|
+
done: "done",
|
|
1507
|
+
error: "error"
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1510
|
+
// src/generated/gladia/schema/streamingResponseKind.ts
|
|
1511
|
+
var StreamingResponseKind = {
|
|
1512
|
+
live: "live"
|
|
1513
|
+
};
|
|
1514
|
+
|
|
1515
|
+
// src/generated/gladia/schema/streamingResponseStatus.ts
|
|
1516
|
+
var StreamingResponseStatus = {
|
|
1517
|
+
queued: "queued",
|
|
1518
|
+
processing: "processing",
|
|
1519
|
+
done: "done",
|
|
1520
|
+
error: "error"
|
|
1521
|
+
};
|
|
1522
|
+
|
|
1523
|
+
// src/generated/gladia/schema/streamingSupportedRegions.ts
|
|
1524
|
+
var StreamingSupportedRegions = {
|
|
1525
|
+
"us-west": "us-west",
|
|
1526
|
+
"eu-west": "eu-west"
|
|
1527
|
+
};
|
|
1528
|
+
|
|
1529
|
+
// src/generated/gladia/schema/subtitlesFormatEnum.ts
|
|
1530
|
+
var SubtitlesFormatEnum = {
|
|
1531
|
+
srt: "srt",
|
|
1532
|
+
vtt: "vtt"
|
|
1533
|
+
};
|
|
1534
|
+
|
|
1535
|
+
// src/generated/gladia/schema/subtitlesStyleEnum.ts
|
|
1536
|
+
var SubtitlesStyleEnum = {
|
|
1537
|
+
default: "default",
|
|
1538
|
+
compliance: "compliance"
|
|
1539
|
+
};
|
|
1540
|
+
|
|
1541
|
+
// src/generated/gladia/schema/summaryTypesEnum.ts
|
|
1542
|
+
var SummaryTypesEnum = {
|
|
1543
|
+
general: "general",
|
|
1544
|
+
bullet_points: "bullet_points",
|
|
1545
|
+
concise: "concise"
|
|
1546
|
+
};
|
|
1547
|
+
|
|
1548
|
+
// src/generated/gladia/schema/transcriptionControllerListV2KindItem.ts
|
|
1549
|
+
var TranscriptionControllerListV2KindItem = {
|
|
1550
|
+
"pre-recorded": "pre-recorded",
|
|
1551
|
+
live: "live"
|
|
1552
|
+
};
|
|
1553
|
+
|
|
1554
|
+
// src/generated/gladia/schema/transcriptionControllerListV2StatusItem.ts
|
|
1555
|
+
var TranscriptionControllerListV2StatusItem = {
|
|
1556
|
+
queued: "queued",
|
|
1557
|
+
processing: "processing",
|
|
1558
|
+
done: "done",
|
|
1559
|
+
error: "error"
|
|
1560
|
+
};
|
|
1561
|
+
|
|
1562
|
+
// src/generated/gladia/schema/transcriptMessageType.ts
|
|
1563
|
+
var TranscriptMessageType = {
|
|
1564
|
+
transcript: "transcript"
|
|
1482
1565
|
};
|
|
1483
1566
|
|
|
1484
1567
|
// src/generated/gladia/schema/translationMessageType.ts
|
|
@@ -2124,11 +2207,46 @@ var GladiaAdapter = class extends BaseAdapter {
|
|
|
2124
2207
|
* Creates a WebSocket connection to Gladia for streaming transcription.
|
|
2125
2208
|
* First initializes a session via REST API, then connects to WebSocket.
|
|
2126
2209
|
*
|
|
2210
|
+
* Supports all Gladia streaming features:
|
|
2211
|
+
* - Real-time transcription with interim/final results
|
|
2212
|
+
* - Speech detection events (speech_start, speech_end)
|
|
2213
|
+
* - Real-time translation to other languages
|
|
2214
|
+
* - Real-time sentiment analysis
|
|
2215
|
+
* - Real-time named entity recognition
|
|
2216
|
+
* - Post-processing summarization and chapterization
|
|
2217
|
+
* - Audio preprocessing (audio enhancement, speech threshold)
|
|
2218
|
+
* - Custom vocabulary and spelling
|
|
2219
|
+
* - Multi-language code switching
|
|
2220
|
+
*
|
|
2127
2221
|
* @param options - Streaming configuration options
|
|
2222
|
+
* @param options.encoding - Audio encoding (wav/pcm, wav/alaw, wav/ulaw)
|
|
2223
|
+
* @param options.sampleRate - Sample rate (8000, 16000, 32000, 44100, 48000)
|
|
2224
|
+
* @param options.bitDepth - Bit depth (8, 16, 24, 32)
|
|
2225
|
+
* @param options.channels - Number of channels (1-8)
|
|
2226
|
+
* @param options.language - Language code for transcription
|
|
2227
|
+
* @param options.interimResults - Enable partial/interim transcripts
|
|
2228
|
+
* @param options.endpointing - Silence duration to end utterance (0.01-10 seconds)
|
|
2229
|
+
* @param options.maxSilence - Max duration without endpointing (5-60 seconds)
|
|
2230
|
+
* @param options.customVocabulary - Words to boost in recognition
|
|
2231
|
+
* @param options.sentimentAnalysis - Enable real-time sentiment analysis
|
|
2232
|
+
* @param options.entityDetection - Enable named entity recognition
|
|
2233
|
+
* @param options.summarization - Enable post-processing summarization
|
|
2234
|
+
* @param options.gladiaStreaming - Full Gladia streaming options (pre_processing, realtime_processing, post_processing, messages_config)
|
|
2128
2235
|
* @param callbacks - Event callbacks for transcription results
|
|
2236
|
+
* @param callbacks.onTranscript - Interim/final transcript received
|
|
2237
|
+
* @param callbacks.onUtterance - Complete utterance detected
|
|
2238
|
+
* @param callbacks.onSpeechStart - Speech detected (requires messages_config.receive_speech_events)
|
|
2239
|
+
* @param callbacks.onSpeechEnd - Speech ended (requires messages_config.receive_speech_events)
|
|
2240
|
+
* @param callbacks.onTranslation - Translation result (requires translation enabled)
|
|
2241
|
+
* @param callbacks.onSentiment - Sentiment analysis result
|
|
2242
|
+
* @param callbacks.onEntity - Named entity detected
|
|
2243
|
+
* @param callbacks.onSummarization - Summarization completed
|
|
2244
|
+
* @param callbacks.onChapterization - Chapterization completed
|
|
2245
|
+
* @param callbacks.onAudioAck - Audio chunk acknowledged
|
|
2246
|
+
* @param callbacks.onLifecycle - Session lifecycle events
|
|
2129
2247
|
* @returns Promise that resolves with a StreamingSession
|
|
2130
2248
|
*
|
|
2131
|
-
* @example
|
|
2249
|
+
* @example Basic real-time streaming
|
|
2132
2250
|
* ```typescript
|
|
2133
2251
|
* const session = await adapter.transcribeStream({
|
|
2134
2252
|
* encoding: 'wav/pcm',
|
|
@@ -2150,36 +2268,57 @@ var GladiaAdapter = class extends BaseAdapter {
|
|
|
2150
2268
|
* });
|
|
2151
2269
|
*
|
|
2152
2270
|
* // Send audio chunks
|
|
2153
|
-
* const audioChunk = getAudioChunk();
|
|
2271
|
+
* const audioChunk = getAudioChunk();
|
|
2154
2272
|
* await session.sendAudio({ data: audioChunk });
|
|
2155
2273
|
*
|
|
2156
2274
|
* // Close when done
|
|
2157
2275
|
* await session.close();
|
|
2158
2276
|
* ```
|
|
2277
|
+
*
|
|
2278
|
+
* @example Advanced streaming with all features
|
|
2279
|
+
* ```typescript
|
|
2280
|
+
* const session = await adapter.transcribeStream({
|
|
2281
|
+
* encoding: 'wav/pcm',
|
|
2282
|
+
* sampleRate: 16000,
|
|
2283
|
+
* language: 'en',
|
|
2284
|
+
* sentimentAnalysis: true,
|
|
2285
|
+
* entityDetection: true,
|
|
2286
|
+
* summarization: true,
|
|
2287
|
+
* gladiaStreaming: {
|
|
2288
|
+
* pre_processing: {
|
|
2289
|
+
* audio_enhancer: true,
|
|
2290
|
+
* speech_threshold: 0.5
|
|
2291
|
+
* },
|
|
2292
|
+
* realtime_processing: {
|
|
2293
|
+
* translation: true,
|
|
2294
|
+
* translation_config: { target_languages: ['fr', 'es'] }
|
|
2295
|
+
* },
|
|
2296
|
+
* post_processing: {
|
|
2297
|
+
* chapterization: true
|
|
2298
|
+
* },
|
|
2299
|
+
* messages_config: {
|
|
2300
|
+
* receive_speech_events: true,
|
|
2301
|
+
* receive_acknowledgments: true,
|
|
2302
|
+
* receive_lifecycle_events: true
|
|
2303
|
+
* }
|
|
2304
|
+
* }
|
|
2305
|
+
* }, {
|
|
2306
|
+
* onTranscript: (e) => console.log('Transcript:', e.text),
|
|
2307
|
+
* onSpeechStart: (e) => console.log('Speech started at:', e.timestamp),
|
|
2308
|
+
* onSpeechEnd: (e) => console.log('Speech ended at:', e.timestamp),
|
|
2309
|
+
* onTranslation: (e) => console.log(`${e.targetLanguage}: ${e.translatedText}`),
|
|
2310
|
+
* onSentiment: (e) => console.log('Sentiment:', e.sentiment),
|
|
2311
|
+
* onEntity: (e) => console.log(`Entity: ${e.type} - ${e.text}`),
|
|
2312
|
+
* onSummarization: (e) => console.log('Summary:', e.summary),
|
|
2313
|
+
* onChapterization: (e) => console.log('Chapters:', e.chapters),
|
|
2314
|
+
* onAudioAck: (e) => console.log('Audio ack:', e.byteRange),
|
|
2315
|
+
* onLifecycle: (e) => console.log('Lifecycle:', e.eventType)
|
|
2316
|
+
* });
|
|
2317
|
+
* ```
|
|
2159
2318
|
*/
|
|
2160
2319
|
async transcribeStream(options, callbacks) {
|
|
2161
2320
|
this.validateConfig();
|
|
2162
|
-
|
|
2163
|
-
if (options?.sampleRate) {
|
|
2164
|
-
validatedSampleRate = validateEnumValue(
|
|
2165
|
-
options.sampleRate,
|
|
2166
|
-
StreamingSupportedSampleRateEnum,
|
|
2167
|
-
"sample rate",
|
|
2168
|
-
"Gladia"
|
|
2169
|
-
);
|
|
2170
|
-
}
|
|
2171
|
-
const streamingRequest = {
|
|
2172
|
-
encoding: options?.encoding ? mapEncodingToProvider(options.encoding, "gladia") : void 0,
|
|
2173
|
-
sample_rate: validatedSampleRate,
|
|
2174
|
-
channels: options?.channels,
|
|
2175
|
-
endpointing: options?.endpointing,
|
|
2176
|
-
model: options?.model
|
|
2177
|
-
};
|
|
2178
|
-
if (options?.language) {
|
|
2179
|
-
streamingRequest.language_config = {
|
|
2180
|
-
languages: [options.language]
|
|
2181
|
-
};
|
|
2182
|
-
}
|
|
2321
|
+
const streamingRequest = this.buildStreamingRequest(options);
|
|
2183
2322
|
const initResponse = await streamingControllerInitStreamingSessionV2(
|
|
2184
2323
|
streamingRequest,
|
|
2185
2324
|
void 0,
|
|
@@ -2195,44 +2334,7 @@ var GladiaAdapter = class extends BaseAdapter {
|
|
|
2195
2334
|
ws.on("message", (data) => {
|
|
2196
2335
|
try {
|
|
2197
2336
|
const message = JSON.parse(data.toString());
|
|
2198
|
-
|
|
2199
|
-
const transcriptMessage = message;
|
|
2200
|
-
const messageData = transcriptMessage.data;
|
|
2201
|
-
const utterance = messageData.utterance;
|
|
2202
|
-
callbacks?.onTranscript?.({
|
|
2203
|
-
type: "transcript",
|
|
2204
|
-
text: utterance.text,
|
|
2205
|
-
isFinal: messageData.is_final,
|
|
2206
|
-
confidence: utterance.confidence,
|
|
2207
|
-
words: utterance.words.map((w) => ({
|
|
2208
|
-
word: w.word,
|
|
2209
|
-
start: w.start,
|
|
2210
|
-
end: w.end,
|
|
2211
|
-
confidence: w.confidence
|
|
2212
|
-
})),
|
|
2213
|
-
data: message
|
|
2214
|
-
});
|
|
2215
|
-
} else if (message.type === "utterance") {
|
|
2216
|
-
const transcriptMessage = message;
|
|
2217
|
-
const messageData = transcriptMessage.data;
|
|
2218
|
-
const utterance = messageData.utterance;
|
|
2219
|
-
const utteranceData = {
|
|
2220
|
-
text: utterance.text,
|
|
2221
|
-
start: utterance.start,
|
|
2222
|
-
end: utterance.end,
|
|
2223
|
-
speaker: utterance.speaker?.toString(),
|
|
2224
|
-
confidence: utterance.confidence,
|
|
2225
|
-
words: utterance.words.map((w) => ({
|
|
2226
|
-
word: w.word,
|
|
2227
|
-
start: w.start,
|
|
2228
|
-
end: w.end,
|
|
2229
|
-
confidence: w.confidence
|
|
2230
|
-
}))
|
|
2231
|
-
};
|
|
2232
|
-
callbacks?.onUtterance?.(utteranceData);
|
|
2233
|
-
} else if (message.type === "metadata") {
|
|
2234
|
-
callbacks?.onMetadata?.(message);
|
|
2235
|
-
}
|
|
2337
|
+
this.handleWebSocketMessage(message, callbacks);
|
|
2236
2338
|
} catch (error) {
|
|
2237
2339
|
callbacks?.onError?.({
|
|
2238
2340
|
code: ERROR_CODES.PARSE_ERROR,
|
|
@@ -2240,40 +2342,429 @@ var GladiaAdapter = class extends BaseAdapter {
|
|
|
2240
2342
|
details: error
|
|
2241
2343
|
});
|
|
2242
2344
|
}
|
|
2243
|
-
});
|
|
2244
|
-
await waitForWebSocketOpen(ws);
|
|
2245
|
-
return {
|
|
2246
|
-
id,
|
|
2247
|
-
provider: this.name,
|
|
2248
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
2249
|
-
getStatus: () => sessionStatus,
|
|
2250
|
-
sendAudio: async (chunk) => {
|
|
2251
|
-
validateSessionForAudio(sessionStatus, ws.readyState, import_ws.default.OPEN);
|
|
2252
|
-
ws.send(chunk.data);
|
|
2253
|
-
if (chunk.isLast) {
|
|
2254
|
-
ws.send(
|
|
2255
|
-
JSON.stringify({
|
|
2256
|
-
type: "stop_recording"
|
|
2257
|
-
})
|
|
2258
|
-
);
|
|
2345
|
+
});
|
|
2346
|
+
await waitForWebSocketOpen(ws);
|
|
2347
|
+
return {
|
|
2348
|
+
id,
|
|
2349
|
+
provider: this.name,
|
|
2350
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2351
|
+
getStatus: () => sessionStatus,
|
|
2352
|
+
sendAudio: async (chunk) => {
|
|
2353
|
+
validateSessionForAudio(sessionStatus, ws.readyState, import_ws.default.OPEN);
|
|
2354
|
+
ws.send(chunk.data);
|
|
2355
|
+
if (chunk.isLast) {
|
|
2356
|
+
ws.send(
|
|
2357
|
+
JSON.stringify({
|
|
2358
|
+
type: "stop_recording"
|
|
2359
|
+
})
|
|
2360
|
+
);
|
|
2361
|
+
}
|
|
2362
|
+
},
|
|
2363
|
+
close: async () => {
|
|
2364
|
+
if (sessionStatus === "closed" || sessionStatus === "closing") {
|
|
2365
|
+
return;
|
|
2366
|
+
}
|
|
2367
|
+
sessionStatus = "closing";
|
|
2368
|
+
if (ws.readyState === import_ws.default.OPEN) {
|
|
2369
|
+
ws.send(
|
|
2370
|
+
JSON.stringify({
|
|
2371
|
+
type: "stop_recording"
|
|
2372
|
+
})
|
|
2373
|
+
);
|
|
2374
|
+
}
|
|
2375
|
+
await closeWebSocket(ws);
|
|
2376
|
+
sessionStatus = "closed";
|
|
2377
|
+
}
|
|
2378
|
+
};
|
|
2379
|
+
}
|
|
2380
|
+
/**
|
|
2381
|
+
* Build streaming request with full type safety from OpenAPI specs
|
|
2382
|
+
*
|
|
2383
|
+
* Maps normalized options to Gladia streaming request format,
|
|
2384
|
+
* including all advanced features like pre-processing, real-time
|
|
2385
|
+
* processing, post-processing, and message configuration.
|
|
2386
|
+
*/
|
|
2387
|
+
buildStreamingRequest(options) {
|
|
2388
|
+
const gladiaOpts = options?.gladiaStreaming || {};
|
|
2389
|
+
let validatedSampleRate;
|
|
2390
|
+
if (options?.sampleRate) {
|
|
2391
|
+
validatedSampleRate = validateEnumValue(
|
|
2392
|
+
options.sampleRate,
|
|
2393
|
+
StreamingSupportedSampleRateEnum,
|
|
2394
|
+
"sample rate",
|
|
2395
|
+
"Gladia"
|
|
2396
|
+
);
|
|
2397
|
+
}
|
|
2398
|
+
let validatedBitDepth;
|
|
2399
|
+
if (options?.bitDepth) {
|
|
2400
|
+
validatedBitDepth = validateEnumValue(
|
|
2401
|
+
options.bitDepth,
|
|
2402
|
+
StreamingSupportedBitDepthEnum,
|
|
2403
|
+
"bit depth",
|
|
2404
|
+
"Gladia"
|
|
2405
|
+
);
|
|
2406
|
+
}
|
|
2407
|
+
const streamingRequest = {
|
|
2408
|
+
// Spread any direct Gladia streaming options first
|
|
2409
|
+
...gladiaOpts,
|
|
2410
|
+
// Audio format configuration (these are excluded from gladiaStreaming to avoid conflicts)
|
|
2411
|
+
encoding: options?.encoding ? mapEncodingToProvider(options.encoding, "gladia") : void 0,
|
|
2412
|
+
sample_rate: validatedSampleRate,
|
|
2413
|
+
bit_depth: validatedBitDepth,
|
|
2414
|
+
channels: options?.channels,
|
|
2415
|
+
// Model and processing
|
|
2416
|
+
model: options?.model ?? gladiaOpts.model,
|
|
2417
|
+
endpointing: options?.endpointing ?? gladiaOpts.endpointing,
|
|
2418
|
+
maximum_duration_without_endpointing: options?.maxSilence ?? gladiaOpts.maximum_duration_without_endpointing
|
|
2419
|
+
};
|
|
2420
|
+
if (options?.language || options?.codeSwitching || gladiaOpts.language_config) {
|
|
2421
|
+
streamingRequest.language_config = {
|
|
2422
|
+
...gladiaOpts.language_config,
|
|
2423
|
+
languages: options?.language ? [options.language] : gladiaOpts.language_config?.languages,
|
|
2424
|
+
code_switching: options?.codeSwitching ?? gladiaOpts.language_config?.code_switching
|
|
2425
|
+
};
|
|
2426
|
+
}
|
|
2427
|
+
if (gladiaOpts.pre_processing) {
|
|
2428
|
+
streamingRequest.pre_processing = gladiaOpts.pre_processing;
|
|
2429
|
+
}
|
|
2430
|
+
const realtimeProcessing = gladiaOpts.realtime_processing || {};
|
|
2431
|
+
const hasRealtimeOptions = options?.customVocabulary || options?.sentimentAnalysis || options?.entityDetection || realtimeProcessing.translation || realtimeProcessing.custom_vocabulary || realtimeProcessing.custom_spelling || realtimeProcessing.named_entity_recognition || realtimeProcessing.sentiment_analysis;
|
|
2432
|
+
if (hasRealtimeOptions) {
|
|
2433
|
+
streamingRequest.realtime_processing = {
|
|
2434
|
+
...realtimeProcessing,
|
|
2435
|
+
// Custom vocabulary
|
|
2436
|
+
custom_vocabulary: options?.customVocabulary && options.customVocabulary.length > 0 || realtimeProcessing.custom_vocabulary,
|
|
2437
|
+
custom_vocabulary_config: options?.customVocabulary && options.customVocabulary.length > 0 ? {
|
|
2438
|
+
...realtimeProcessing.custom_vocabulary_config,
|
|
2439
|
+
vocabulary: options.customVocabulary
|
|
2440
|
+
} : realtimeProcessing.custom_vocabulary_config,
|
|
2441
|
+
// Sentiment analysis
|
|
2442
|
+
sentiment_analysis: options?.sentimentAnalysis ?? realtimeProcessing.sentiment_analysis,
|
|
2443
|
+
// Named entity recognition
|
|
2444
|
+
named_entity_recognition: options?.entityDetection ?? realtimeProcessing.named_entity_recognition
|
|
2445
|
+
};
|
|
2446
|
+
}
|
|
2447
|
+
const postProcessing = gladiaOpts.post_processing || {};
|
|
2448
|
+
if (options?.summarization || postProcessing.summarization || postProcessing.chapterization) {
|
|
2449
|
+
streamingRequest.post_processing = {
|
|
2450
|
+
...postProcessing,
|
|
2451
|
+
summarization: options?.summarization ?? postProcessing.summarization
|
|
2452
|
+
};
|
|
2453
|
+
}
|
|
2454
|
+
if (gladiaOpts.messages_config) {
|
|
2455
|
+
streamingRequest.messages_config = gladiaOpts.messages_config;
|
|
2456
|
+
} else if (options?.interimResults !== void 0) {
|
|
2457
|
+
streamingRequest.messages_config = {
|
|
2458
|
+
receive_partial_transcripts: options.interimResults,
|
|
2459
|
+
receive_final_transcripts: true
|
|
2460
|
+
};
|
|
2461
|
+
}
|
|
2462
|
+
if (gladiaOpts.callback || gladiaOpts.callback_config) {
|
|
2463
|
+
streamingRequest.callback = gladiaOpts.callback;
|
|
2464
|
+
streamingRequest.callback_config = gladiaOpts.callback_config;
|
|
2465
|
+
}
|
|
2466
|
+
if (gladiaOpts.custom_metadata) {
|
|
2467
|
+
streamingRequest.custom_metadata = gladiaOpts.custom_metadata;
|
|
2468
|
+
}
|
|
2469
|
+
return streamingRequest;
|
|
2470
|
+
}
|
|
2471
|
+
/**
|
|
2472
|
+
* Handle all WebSocket message types from Gladia streaming
|
|
2473
|
+
*
|
|
2474
|
+
* Processes transcript, utterance, speech events, real-time processing
|
|
2475
|
+
* results (translation, sentiment, NER), post-processing results
|
|
2476
|
+
* (summarization, chapterization), acknowledgments, and lifecycle events.
|
|
2477
|
+
*/
|
|
2478
|
+
handleWebSocketMessage(message, callbacks) {
|
|
2479
|
+
const msg = message;
|
|
2480
|
+
const messageType = msg.type;
|
|
2481
|
+
switch (messageType) {
|
|
2482
|
+
// ─────────────────────────────────────────────────────────────────
|
|
2483
|
+
// Transcript events
|
|
2484
|
+
// ─────────────────────────────────────────────────────────────────
|
|
2485
|
+
case "transcript": {
|
|
2486
|
+
const transcriptMessage = message;
|
|
2487
|
+
const messageData = transcriptMessage.data;
|
|
2488
|
+
const utterance = messageData.utterance;
|
|
2489
|
+
callbacks?.onTranscript?.({
|
|
2490
|
+
type: "transcript",
|
|
2491
|
+
text: utterance.text,
|
|
2492
|
+
isFinal: messageData.is_final,
|
|
2493
|
+
confidence: utterance.confidence,
|
|
2494
|
+
language: utterance.language,
|
|
2495
|
+
channel: utterance.channel,
|
|
2496
|
+
speaker: utterance.speaker?.toString(),
|
|
2497
|
+
words: utterance.words.map((w) => ({
|
|
2498
|
+
word: w.word,
|
|
2499
|
+
start: w.start,
|
|
2500
|
+
end: w.end,
|
|
2501
|
+
confidence: w.confidence
|
|
2502
|
+
})),
|
|
2503
|
+
data: message
|
|
2504
|
+
});
|
|
2505
|
+
break;
|
|
2506
|
+
}
|
|
2507
|
+
case "utterance": {
|
|
2508
|
+
const transcriptMessage = message;
|
|
2509
|
+
const messageData = transcriptMessage.data;
|
|
2510
|
+
const utterance = messageData.utterance;
|
|
2511
|
+
callbacks?.onUtterance?.({
|
|
2512
|
+
text: utterance.text,
|
|
2513
|
+
start: utterance.start,
|
|
2514
|
+
end: utterance.end,
|
|
2515
|
+
speaker: utterance.speaker?.toString(),
|
|
2516
|
+
confidence: utterance.confidence,
|
|
2517
|
+
words: utterance.words.map((w) => ({
|
|
2518
|
+
word: w.word,
|
|
2519
|
+
start: w.start,
|
|
2520
|
+
end: w.end,
|
|
2521
|
+
confidence: w.confidence
|
|
2522
|
+
}))
|
|
2523
|
+
});
|
|
2524
|
+
break;
|
|
2525
|
+
}
|
|
2526
|
+
// Post-processing transcripts (final accumulated transcript)
|
|
2527
|
+
case "post_transcript": {
|
|
2528
|
+
const postTranscript = message;
|
|
2529
|
+
callbacks?.onTranscript?.({
|
|
2530
|
+
type: "transcript",
|
|
2531
|
+
text: postTranscript.data?.full_transcript || "",
|
|
2532
|
+
isFinal: true,
|
|
2533
|
+
data: message
|
|
2534
|
+
});
|
|
2535
|
+
break;
|
|
2536
|
+
}
|
|
2537
|
+
case "post_final_transcript": {
|
|
2538
|
+
const postFinal = message;
|
|
2539
|
+
callbacks?.onTranscript?.({
|
|
2540
|
+
type: "transcript",
|
|
2541
|
+
text: postFinal.data?.transcription?.full_transcript || "",
|
|
2542
|
+
isFinal: true,
|
|
2543
|
+
data: message
|
|
2544
|
+
});
|
|
2545
|
+
break;
|
|
2546
|
+
}
|
|
2547
|
+
// ─────────────────────────────────────────────────────────────────
|
|
2548
|
+
// Speech detection events
|
|
2549
|
+
// ─────────────────────────────────────────────────────────────────
|
|
2550
|
+
case "speech_start": {
|
|
2551
|
+
const speechStart = message;
|
|
2552
|
+
const event = {
|
|
2553
|
+
type: "speech_start",
|
|
2554
|
+
timestamp: speechStart.data.time,
|
|
2555
|
+
channel: speechStart.data.channel,
|
|
2556
|
+
sessionId: speechStart.session_id
|
|
2557
|
+
};
|
|
2558
|
+
callbacks?.onSpeechStart?.(event);
|
|
2559
|
+
break;
|
|
2560
|
+
}
|
|
2561
|
+
case "speech_end": {
|
|
2562
|
+
const speechEnd = message;
|
|
2563
|
+
const event = {
|
|
2564
|
+
type: "speech_end",
|
|
2565
|
+
timestamp: speechEnd.data.time,
|
|
2566
|
+
channel: speechEnd.data.channel,
|
|
2567
|
+
sessionId: speechEnd.session_id
|
|
2568
|
+
};
|
|
2569
|
+
callbacks?.onSpeechEnd?.(event);
|
|
2570
|
+
break;
|
|
2571
|
+
}
|
|
2572
|
+
// ─────────────────────────────────────────────────────────────────
|
|
2573
|
+
// Real-time processing events
|
|
2574
|
+
// ─────────────────────────────────────────────────────────────────
|
|
2575
|
+
case "translation": {
|
|
2576
|
+
const translationMsg = message;
|
|
2577
|
+
if (translationMsg.error) {
|
|
2578
|
+
callbacks?.onError?.({
|
|
2579
|
+
code: ERROR_CODES.TRANSCRIPTION_ERROR,
|
|
2580
|
+
message: "Translation failed",
|
|
2581
|
+
details: translationMsg.error
|
|
2582
|
+
});
|
|
2583
|
+
} else if (translationMsg.data) {
|
|
2584
|
+
const event = {
|
|
2585
|
+
utteranceId: translationMsg.data.utterance_id,
|
|
2586
|
+
original: translationMsg.data.utterance.text,
|
|
2587
|
+
targetLanguage: translationMsg.data.target_language,
|
|
2588
|
+
translatedText: translationMsg.data.translated_utterance.text,
|
|
2589
|
+
isFinal: true
|
|
2590
|
+
};
|
|
2591
|
+
callbacks?.onTranslation?.(event);
|
|
2592
|
+
}
|
|
2593
|
+
break;
|
|
2594
|
+
}
|
|
2595
|
+
case "sentiment_analysis": {
|
|
2596
|
+
const sentimentMsg = message;
|
|
2597
|
+
if (sentimentMsg.error) {
|
|
2598
|
+
callbacks?.onError?.({
|
|
2599
|
+
code: ERROR_CODES.TRANSCRIPTION_ERROR,
|
|
2600
|
+
message: "Sentiment analysis failed",
|
|
2601
|
+
details: sentimentMsg.error
|
|
2602
|
+
});
|
|
2603
|
+
} else if (sentimentMsg.data) {
|
|
2604
|
+
for (const result of sentimentMsg.data.results) {
|
|
2605
|
+
const event = {
|
|
2606
|
+
utteranceId: sentimentMsg.data.utterance_id,
|
|
2607
|
+
sentiment: result.sentiment,
|
|
2608
|
+
confidence: void 0
|
|
2609
|
+
// Gladia doesn't provide confidence for sentiment
|
|
2610
|
+
};
|
|
2611
|
+
callbacks?.onSentiment?.(event);
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
break;
|
|
2615
|
+
}
|
|
2616
|
+
case "named_entity_recognition": {
|
|
2617
|
+
const nerMsg = message;
|
|
2618
|
+
if (nerMsg.error) {
|
|
2619
|
+
callbacks?.onError?.({
|
|
2620
|
+
code: ERROR_CODES.TRANSCRIPTION_ERROR,
|
|
2621
|
+
message: "Named entity recognition failed",
|
|
2622
|
+
details: nerMsg.error
|
|
2623
|
+
});
|
|
2624
|
+
} else if (nerMsg.data) {
|
|
2625
|
+
for (const entity of nerMsg.data.results) {
|
|
2626
|
+
const event = {
|
|
2627
|
+
utteranceId: nerMsg.data.utterance_id,
|
|
2628
|
+
text: entity.text,
|
|
2629
|
+
type: entity.entity_type,
|
|
2630
|
+
start: entity.start,
|
|
2631
|
+
end: entity.end
|
|
2632
|
+
};
|
|
2633
|
+
callbacks?.onEntity?.(event);
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
break;
|
|
2637
|
+
}
|
|
2638
|
+
// ─────────────────────────────────────────────────────────────────
|
|
2639
|
+
// Post-processing events
|
|
2640
|
+
// ─────────────────────────────────────────────────────────────────
|
|
2641
|
+
case "post_summarization": {
|
|
2642
|
+
const summaryMsg = message;
|
|
2643
|
+
if (summaryMsg.error) {
|
|
2644
|
+
callbacks?.onSummarization?.({
|
|
2645
|
+
summary: "",
|
|
2646
|
+
error: typeof summaryMsg.error === "string" ? summaryMsg.error : "Summarization failed"
|
|
2647
|
+
});
|
|
2648
|
+
} else if (summaryMsg.data) {
|
|
2649
|
+
callbacks?.onSummarization?.({
|
|
2650
|
+
summary: summaryMsg.data.results
|
|
2651
|
+
});
|
|
2652
|
+
}
|
|
2653
|
+
break;
|
|
2654
|
+
}
|
|
2655
|
+
case "post_chapterization": {
|
|
2656
|
+
const chapterMsg = message;
|
|
2657
|
+
if (chapterMsg.error) {
|
|
2658
|
+
callbacks?.onChapterization?.({
|
|
2659
|
+
chapters: [],
|
|
2660
|
+
error: typeof chapterMsg.error === "string" ? chapterMsg.error : "Chapterization failed"
|
|
2661
|
+
});
|
|
2662
|
+
} else if (chapterMsg.data) {
|
|
2663
|
+
callbacks?.onChapterization?.({
|
|
2664
|
+
chapters: chapterMsg.data.results.map((ch) => ({
|
|
2665
|
+
headline: ch.headline,
|
|
2666
|
+
summary: ch.summary || ch.abstractive_summary || ch.extractive_summary || "",
|
|
2667
|
+
start: ch.start,
|
|
2668
|
+
end: ch.end
|
|
2669
|
+
}))
|
|
2670
|
+
});
|
|
2259
2671
|
}
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2672
|
+
break;
|
|
2673
|
+
}
|
|
2674
|
+
// ─────────────────────────────────────────────────────────────────
|
|
2675
|
+
// Acknowledgment events
|
|
2676
|
+
// ─────────────────────────────────────────────────────────────────
|
|
2677
|
+
case "audio_chunk_ack": {
|
|
2678
|
+
const ackMsg = message;
|
|
2679
|
+
if (ackMsg.error) {
|
|
2680
|
+
callbacks?.onError?.({
|
|
2681
|
+
code: ERROR_CODES.TRANSCRIPTION_ERROR,
|
|
2682
|
+
message: "Audio chunk not acknowledged",
|
|
2683
|
+
details: ackMsg.error
|
|
2684
|
+
});
|
|
2685
|
+
} else if (ackMsg.data) {
|
|
2686
|
+
const event = {
|
|
2687
|
+
byteRange: ackMsg.data.byte_range,
|
|
2688
|
+
timeRange: ackMsg.data.time_range,
|
|
2689
|
+
timestamp: ackMsg.created_at
|
|
2690
|
+
};
|
|
2691
|
+
callbacks?.onAudioAck?.(event);
|
|
2264
2692
|
}
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2693
|
+
break;
|
|
2694
|
+
}
|
|
2695
|
+
case "stop_recording_ack": {
|
|
2696
|
+
const stopAck = message;
|
|
2697
|
+
if (stopAck.error) {
|
|
2698
|
+
callbacks?.onError?.({
|
|
2699
|
+
code: ERROR_CODES.TRANSCRIPTION_ERROR,
|
|
2700
|
+
message: "Stop recording not acknowledged",
|
|
2701
|
+
details: stopAck.error
|
|
2702
|
+
});
|
|
2272
2703
|
}
|
|
2273
|
-
|
|
2274
|
-
sessionStatus = "closed";
|
|
2704
|
+
break;
|
|
2275
2705
|
}
|
|
2276
|
-
|
|
2706
|
+
// ─────────────────────────────────────────────────────────────────
|
|
2707
|
+
// Lifecycle events
|
|
2708
|
+
// ─────────────────────────────────────────────────────────────────
|
|
2709
|
+
case "start_session": {
|
|
2710
|
+
const startSession = message;
|
|
2711
|
+
const event = {
|
|
2712
|
+
eventType: "start_session",
|
|
2713
|
+
timestamp: startSession.created_at,
|
|
2714
|
+
sessionId: startSession.session_id
|
|
2715
|
+
};
|
|
2716
|
+
callbacks?.onLifecycle?.(event);
|
|
2717
|
+
break;
|
|
2718
|
+
}
|
|
2719
|
+
case "start_recording": {
|
|
2720
|
+
const startRecording = message;
|
|
2721
|
+
const event = {
|
|
2722
|
+
eventType: "start_recording",
|
|
2723
|
+
timestamp: startRecording.created_at,
|
|
2724
|
+
sessionId: startRecording.session_id
|
|
2725
|
+
};
|
|
2726
|
+
callbacks?.onLifecycle?.(event);
|
|
2727
|
+
break;
|
|
2728
|
+
}
|
|
2729
|
+
case "end_recording": {
|
|
2730
|
+
const endRecording = message;
|
|
2731
|
+
const event = {
|
|
2732
|
+
eventType: "end_recording",
|
|
2733
|
+
timestamp: endRecording.created_at,
|
|
2734
|
+
sessionId: endRecording.session_id
|
|
2735
|
+
};
|
|
2736
|
+
callbacks?.onLifecycle?.(event);
|
|
2737
|
+
break;
|
|
2738
|
+
}
|
|
2739
|
+
case "end_session": {
|
|
2740
|
+
const endSession = message;
|
|
2741
|
+
const event = {
|
|
2742
|
+
eventType: "end_session",
|
|
2743
|
+
timestamp: endSession.created_at,
|
|
2744
|
+
sessionId: endSession.session_id
|
|
2745
|
+
};
|
|
2746
|
+
callbacks?.onLifecycle?.(event);
|
|
2747
|
+
break;
|
|
2748
|
+
}
|
|
2749
|
+
// ─────────────────────────────────────────────────────────────────
|
|
2750
|
+
// Metadata and other events
|
|
2751
|
+
// ─────────────────────────────────────────────────────────────────
|
|
2752
|
+
case "metadata":
|
|
2753
|
+
callbacks?.onMetadata?.(msg);
|
|
2754
|
+
break;
|
|
2755
|
+
case "error": {
|
|
2756
|
+
const errorMsg = msg;
|
|
2757
|
+
callbacks?.onError?.({
|
|
2758
|
+
code: errorMsg.error?.code || ERROR_CODES.TRANSCRIPTION_ERROR,
|
|
2759
|
+
message: errorMsg.error?.message || "Unknown streaming error",
|
|
2760
|
+
details: msg
|
|
2761
|
+
});
|
|
2762
|
+
break;
|
|
2763
|
+
}
|
|
2764
|
+
default:
|
|
2765
|
+
callbacks?.onMetadata?.(msg);
|
|
2766
|
+
break;
|
|
2767
|
+
}
|
|
2277
2768
|
}
|
|
2278
2769
|
};
|
|
2279
2770
|
function createGladiaAdapter(config) {
|
|
@@ -2968,19 +3459,37 @@ var AssemblyAIAdapter = class extends BaseAdapter {
|
|
|
2968
3459
|
* Stream audio for real-time transcription
|
|
2969
3460
|
*
|
|
2970
3461
|
* Creates a WebSocket connection to AssemblyAI for streaming transcription.
|
|
2971
|
-
*
|
|
3462
|
+
* Uses the v3 Universal Streaming API with full support for all parameters.
|
|
3463
|
+
*
|
|
3464
|
+
* Supports all AssemblyAI streaming features:
|
|
3465
|
+
* - Real-time transcription with interim/final results (Turn events)
|
|
3466
|
+
* - End-of-turn detection tuning (confidence threshold, silence duration)
|
|
3467
|
+
* - Voice Activity Detection (VAD) threshold tuning
|
|
3468
|
+
* - Real-time text formatting
|
|
3469
|
+
* - Profanity filtering
|
|
3470
|
+
* - Custom vocabulary (keyterms)
|
|
3471
|
+
* - Language detection
|
|
3472
|
+
* - Model selection (English or Multilingual)
|
|
3473
|
+
* - Dynamic configuration updates mid-stream
|
|
3474
|
+
* - Force endpoint command
|
|
2972
3475
|
*
|
|
2973
3476
|
* @param options - Streaming configuration options
|
|
3477
|
+
* @param options.sampleRate - Sample rate (8000, 16000, 22050, 44100, 48000)
|
|
3478
|
+
* @param options.encoding - Audio encoding (pcm_s16le, pcm_mulaw)
|
|
3479
|
+
* @param options.assemblyaiStreaming - All AssemblyAI-specific streaming options
|
|
2974
3480
|
* @param callbacks - Event callbacks for transcription results
|
|
2975
|
-
* @
|
|
3481
|
+
* @param callbacks.onTranscript - Interim/final transcript received (Turn event)
|
|
3482
|
+
* @param callbacks.onUtterance - Complete utterance (Turn with end_of_turn=true)
|
|
3483
|
+
* @param callbacks.onMetadata - Session metadata (Begin, Termination events)
|
|
3484
|
+
* @param callbacks.onError - Error occurred
|
|
3485
|
+
* @param callbacks.onClose - Connection closed
|
|
3486
|
+
* @returns Promise that resolves with an extended StreamingSession
|
|
2976
3487
|
*
|
|
2977
|
-
* @example
|
|
3488
|
+
* @example Basic real-time streaming
|
|
2978
3489
|
* ```typescript
|
|
2979
3490
|
* const session = await adapter.transcribeStream({
|
|
2980
|
-
* encoding: 'pcm_s16le',
|
|
2981
3491
|
* sampleRate: 16000,
|
|
2982
|
-
*
|
|
2983
|
-
* interimResults: true
|
|
3492
|
+
* encoding: 'pcm_s16le'
|
|
2984
3493
|
* }, {
|
|
2985
3494
|
* onOpen: () => console.log('Connected'),
|
|
2986
3495
|
* onTranscript: (event) => {
|
|
@@ -2995,21 +3504,50 @@ var AssemblyAIAdapter = class extends BaseAdapter {
|
|
|
2995
3504
|
* });
|
|
2996
3505
|
*
|
|
2997
3506
|
* // Send audio chunks
|
|
2998
|
-
* const audioChunk = getAudioChunk();
|
|
3507
|
+
* const audioChunk = getAudioChunk();
|
|
2999
3508
|
* await session.sendAudio({ data: audioChunk });
|
|
3000
3509
|
*
|
|
3001
3510
|
* // Close when done
|
|
3002
3511
|
* await session.close();
|
|
3003
3512
|
* ```
|
|
3513
|
+
*
|
|
3514
|
+
* @example Advanced streaming with all features
|
|
3515
|
+
* ```typescript
|
|
3516
|
+
* const session = await adapter.transcribeStream({
|
|
3517
|
+
* sampleRate: 16000,
|
|
3518
|
+
* assemblyaiStreaming: {
|
|
3519
|
+
* speechModel: 'universal-streaming-multilingual',
|
|
3520
|
+
* languageDetection: true,
|
|
3521
|
+
* endOfTurnConfidenceThreshold: 0.7,
|
|
3522
|
+
* minEndOfTurnSilenceWhenConfident: 500,
|
|
3523
|
+
* maxTurnSilence: 15000,
|
|
3524
|
+
* vadThreshold: 0.3,
|
|
3525
|
+
* formatTurns: true,
|
|
3526
|
+
* filterProfanity: true,
|
|
3527
|
+
* keyterms: ['TypeScript', 'JavaScript', 'API'],
|
|
3528
|
+
* inactivityTimeout: 60000
|
|
3529
|
+
* }
|
|
3530
|
+
* }, {
|
|
3531
|
+
* onTranscript: (e) => console.log('Transcript:', e.text),
|
|
3532
|
+
* onMetadata: (m) => console.log('Metadata:', m)
|
|
3533
|
+
* });
|
|
3534
|
+
*
|
|
3535
|
+
* // Update configuration mid-stream
|
|
3536
|
+
* session.updateConfiguration?.({
|
|
3537
|
+
* end_of_turn_confidence_threshold: 0.5,
|
|
3538
|
+
* vad_threshold: 0.2
|
|
3539
|
+
* });
|
|
3540
|
+
*
|
|
3541
|
+
* // Force endpoint detection
|
|
3542
|
+
* session.forceEndpoint?.();
|
|
3543
|
+
* ```
|
|
3004
3544
|
*/
|
|
3005
3545
|
async transcribeStream(options, callbacks) {
|
|
3006
3546
|
this.validateConfig();
|
|
3007
3547
|
if (!this.config?.apiKey) {
|
|
3008
3548
|
throw new Error("API key is required for streaming");
|
|
3009
3549
|
}
|
|
3010
|
-
const
|
|
3011
|
-
const encoding = options?.encoding ? mapEncodingToProvider(options.encoding, "assemblyai") : "pcm_s16le";
|
|
3012
|
-
const wsUrl = `${this.wsBaseUrl}?sample_rate=${sampleRate}&encoding=${encoding}`;
|
|
3550
|
+
const wsUrl = this.buildStreamingUrl(options);
|
|
3013
3551
|
const ws = new import_ws2.default(wsUrl, {
|
|
3014
3552
|
headers: {
|
|
3015
3553
|
Authorization: this.config.apiKey
|
|
@@ -3033,43 +3571,7 @@ var AssemblyAIAdapter = class extends BaseAdapter {
|
|
|
3033
3571
|
ws.on("message", (data) => {
|
|
3034
3572
|
try {
|
|
3035
3573
|
const message = JSON.parse(data.toString());
|
|
3036
|
-
|
|
3037
|
-
callbacks?.onError?.({
|
|
3038
|
-
code: "API_ERROR",
|
|
3039
|
-
message: message.error
|
|
3040
|
-
});
|
|
3041
|
-
return;
|
|
3042
|
-
}
|
|
3043
|
-
if (message.type === "Begin") {
|
|
3044
|
-
const beginMsg = message;
|
|
3045
|
-
callbacks?.onMetadata?.({
|
|
3046
|
-
sessionId: beginMsg.id,
|
|
3047
|
-
expiresAt: new Date(beginMsg.expires_at).toISOString()
|
|
3048
|
-
});
|
|
3049
|
-
} else if (message.type === "Turn") {
|
|
3050
|
-
const turnMsg = message;
|
|
3051
|
-
callbacks?.onTranscript?.({
|
|
3052
|
-
type: "transcript",
|
|
3053
|
-
text: turnMsg.transcript,
|
|
3054
|
-
isFinal: turnMsg.end_of_turn,
|
|
3055
|
-
confidence: turnMsg.end_of_turn_confidence,
|
|
3056
|
-
words: turnMsg.words.map((w) => ({
|
|
3057
|
-
word: w.text,
|
|
3058
|
-
start: w.start / 1e3,
|
|
3059
|
-
// Convert ms to seconds
|
|
3060
|
-
end: w.end / 1e3,
|
|
3061
|
-
confidence: w.confidence
|
|
3062
|
-
})),
|
|
3063
|
-
data: turnMsg
|
|
3064
|
-
});
|
|
3065
|
-
} else if (message.type === "Termination") {
|
|
3066
|
-
const termMsg = message;
|
|
3067
|
-
callbacks?.onMetadata?.({
|
|
3068
|
-
terminated: true,
|
|
3069
|
-
audioDurationSeconds: termMsg.audio_duration_seconds,
|
|
3070
|
-
sessionDurationSeconds: termMsg.session_duration_seconds
|
|
3071
|
-
});
|
|
3072
|
-
}
|
|
3574
|
+
this.handleWebSocketMessage(message, callbacks);
|
|
3073
3575
|
} catch (error) {
|
|
3074
3576
|
callbacks?.onError?.({
|
|
3075
3577
|
code: "PARSE_ERROR",
|
|
@@ -3121,11 +3623,7 @@ var AssemblyAIAdapter = class extends BaseAdapter {
|
|
|
3121
3623
|
}
|
|
3122
3624
|
if (chunk.isLast) {
|
|
3123
3625
|
flushAudioBuffer();
|
|
3124
|
-
ws.send(
|
|
3125
|
-
JSON.stringify({
|
|
3126
|
-
terminate_session: true
|
|
3127
|
-
})
|
|
3128
|
-
);
|
|
3626
|
+
ws.send(JSON.stringify({ type: "Terminate" }));
|
|
3129
3627
|
}
|
|
3130
3628
|
},
|
|
3131
3629
|
close: async () => {
|
|
@@ -3135,11 +3633,7 @@ var AssemblyAIAdapter = class extends BaseAdapter {
|
|
|
3135
3633
|
sessionStatus = "closing";
|
|
3136
3634
|
flushAudioBuffer();
|
|
3137
3635
|
if (ws.readyState === import_ws2.default.OPEN) {
|
|
3138
|
-
ws.send(
|
|
3139
|
-
JSON.stringify({
|
|
3140
|
-
terminate_session: true
|
|
3141
|
-
})
|
|
3142
|
-
);
|
|
3636
|
+
ws.send(JSON.stringify({ type: "Terminate" }));
|
|
3143
3637
|
}
|
|
3144
3638
|
return new Promise((resolve) => {
|
|
3145
3639
|
const timeout = setTimeout(() => {
|
|
@@ -3153,9 +3647,166 @@ var AssemblyAIAdapter = class extends BaseAdapter {
|
|
|
3153
3647
|
resolve();
|
|
3154
3648
|
});
|
|
3155
3649
|
});
|
|
3650
|
+
},
|
|
3651
|
+
/**
|
|
3652
|
+
* Update streaming configuration mid-session
|
|
3653
|
+
*
|
|
3654
|
+
* Allows changing VAD, end-of-turn, and formatting settings
|
|
3655
|
+
* without restarting the stream.
|
|
3656
|
+
*
|
|
3657
|
+
* @param config - Configuration parameters to update
|
|
3658
|
+
*/
|
|
3659
|
+
updateConfiguration: (config) => {
|
|
3660
|
+
if (ws.readyState !== import_ws2.default.OPEN) {
|
|
3661
|
+
throw new Error("Cannot update configuration: WebSocket is not open");
|
|
3662
|
+
}
|
|
3663
|
+
const updateMsg = {
|
|
3664
|
+
type: "UpdateConfiguration",
|
|
3665
|
+
...config
|
|
3666
|
+
};
|
|
3667
|
+
ws.send(JSON.stringify(updateMsg));
|
|
3668
|
+
},
|
|
3669
|
+
/**
|
|
3670
|
+
* Force endpoint detection
|
|
3671
|
+
*
|
|
3672
|
+
* Immediately triggers end-of-turn, useful for manual control
|
|
3673
|
+
* of turn boundaries (e.g., when user presses a button).
|
|
3674
|
+
*/
|
|
3675
|
+
forceEndpoint: () => {
|
|
3676
|
+
if (ws.readyState !== import_ws2.default.OPEN) {
|
|
3677
|
+
throw new Error("Cannot force endpoint: WebSocket is not open");
|
|
3678
|
+
}
|
|
3679
|
+
const forceMsg = {
|
|
3680
|
+
type: "ForceEndpoint"
|
|
3681
|
+
};
|
|
3682
|
+
ws.send(JSON.stringify(forceMsg));
|
|
3156
3683
|
}
|
|
3157
3684
|
};
|
|
3158
3685
|
}
|
|
3686
|
+
/**
|
|
3687
|
+
* Build WebSocket URL with all streaming parameters
|
|
3688
|
+
*/
|
|
3689
|
+
buildStreamingUrl(options) {
|
|
3690
|
+
const params = new URLSearchParams();
|
|
3691
|
+
const aaiOpts = options?.assemblyaiStreaming || {};
|
|
3692
|
+
const sampleRate = options?.sampleRate || aaiOpts.sampleRate || 16e3;
|
|
3693
|
+
params.append("sample_rate", String(sampleRate));
|
|
3694
|
+
const encoding = options?.encoding ? mapEncodingToProvider(options.encoding, "assemblyai") : aaiOpts.encoding || "pcm_s16le";
|
|
3695
|
+
params.append("encoding", encoding);
|
|
3696
|
+
if (aaiOpts.speechModel) {
|
|
3697
|
+
params.append("speech_model", aaiOpts.speechModel);
|
|
3698
|
+
}
|
|
3699
|
+
if (aaiOpts.languageDetection) {
|
|
3700
|
+
params.append("language_detection", "true");
|
|
3701
|
+
}
|
|
3702
|
+
if (aaiOpts.endOfTurnConfidenceThreshold !== void 0) {
|
|
3703
|
+
params.append(
|
|
3704
|
+
"end_of_turn_confidence_threshold",
|
|
3705
|
+
String(aaiOpts.endOfTurnConfidenceThreshold)
|
|
3706
|
+
);
|
|
3707
|
+
}
|
|
3708
|
+
if (aaiOpts.minEndOfTurnSilenceWhenConfident !== void 0) {
|
|
3709
|
+
params.append(
|
|
3710
|
+
"min_end_of_turn_silence_when_confident",
|
|
3711
|
+
String(aaiOpts.minEndOfTurnSilenceWhenConfident)
|
|
3712
|
+
);
|
|
3713
|
+
}
|
|
3714
|
+
if (aaiOpts.maxTurnSilence !== void 0) {
|
|
3715
|
+
params.append("max_turn_silence", String(aaiOpts.maxTurnSilence));
|
|
3716
|
+
}
|
|
3717
|
+
if (aaiOpts.vadThreshold !== void 0) {
|
|
3718
|
+
params.append("vad_threshold", String(aaiOpts.vadThreshold));
|
|
3719
|
+
}
|
|
3720
|
+
if (aaiOpts.formatTurns !== void 0) {
|
|
3721
|
+
params.append("format_turns", String(aaiOpts.formatTurns));
|
|
3722
|
+
}
|
|
3723
|
+
if (aaiOpts.filterProfanity) {
|
|
3724
|
+
params.append("filter_profanity", "true");
|
|
3725
|
+
}
|
|
3726
|
+
const keyterms = options?.customVocabulary || aaiOpts.keyterms;
|
|
3727
|
+
if (keyterms && keyterms.length > 0) {
|
|
3728
|
+
keyterms.forEach((term) => params.append("keyterms", term));
|
|
3729
|
+
}
|
|
3730
|
+
if (aaiOpts.keytermsPrompt && aaiOpts.keytermsPrompt.length > 0) {
|
|
3731
|
+
aaiOpts.keytermsPrompt.forEach((prompt) => params.append("keyterms_prompt", prompt));
|
|
3732
|
+
}
|
|
3733
|
+
if (aaiOpts.inactivityTimeout !== void 0) {
|
|
3734
|
+
params.append("inactivity_timeout", String(aaiOpts.inactivityTimeout));
|
|
3735
|
+
}
|
|
3736
|
+
return `${this.wsBaseUrl}?${params.toString()}`;
|
|
3737
|
+
}
|
|
3738
|
+
/**
|
|
3739
|
+
* Handle all WebSocket message types from AssemblyAI streaming
|
|
3740
|
+
*/
|
|
3741
|
+
handleWebSocketMessage(message, callbacks) {
|
|
3742
|
+
if ("error" in message) {
|
|
3743
|
+
callbacks?.onError?.({
|
|
3744
|
+
code: "API_ERROR",
|
|
3745
|
+
message: message.error
|
|
3746
|
+
});
|
|
3747
|
+
return;
|
|
3748
|
+
}
|
|
3749
|
+
const typedMessage = message;
|
|
3750
|
+
switch (typedMessage.type) {
|
|
3751
|
+
case "Begin": {
|
|
3752
|
+
const beginMsg = typedMessage;
|
|
3753
|
+
callbacks?.onMetadata?.({
|
|
3754
|
+
type: "begin",
|
|
3755
|
+
sessionId: beginMsg.id,
|
|
3756
|
+
expiresAt: new Date(beginMsg.expires_at).toISOString()
|
|
3757
|
+
});
|
|
3758
|
+
break;
|
|
3759
|
+
}
|
|
3760
|
+
case "Turn": {
|
|
3761
|
+
const turnMsg = typedMessage;
|
|
3762
|
+
callbacks?.onTranscript?.({
|
|
3763
|
+
type: "transcript",
|
|
3764
|
+
text: turnMsg.transcript,
|
|
3765
|
+
isFinal: turnMsg.end_of_turn,
|
|
3766
|
+
confidence: turnMsg.end_of_turn_confidence,
|
|
3767
|
+
language: turnMsg.language_code,
|
|
3768
|
+
words: turnMsg.words.map((w) => ({
|
|
3769
|
+
word: w.text,
|
|
3770
|
+
start: w.start / 1e3,
|
|
3771
|
+
// Convert ms to seconds
|
|
3772
|
+
end: w.end / 1e3,
|
|
3773
|
+
confidence: w.confidence
|
|
3774
|
+
})),
|
|
3775
|
+
data: turnMsg
|
|
3776
|
+
});
|
|
3777
|
+
if (turnMsg.end_of_turn) {
|
|
3778
|
+
const words = turnMsg.words;
|
|
3779
|
+
const start = words.length > 0 ? words[0].start / 1e3 : 0;
|
|
3780
|
+
const end = words.length > 0 ? words[words.length - 1].end / 1e3 : 0;
|
|
3781
|
+
callbacks?.onUtterance?.({
|
|
3782
|
+
text: turnMsg.transcript,
|
|
3783
|
+
start,
|
|
3784
|
+
end,
|
|
3785
|
+
confidence: turnMsg.end_of_turn_confidence,
|
|
3786
|
+
words: turnMsg.words.map((w) => ({
|
|
3787
|
+
word: w.text,
|
|
3788
|
+
start: w.start / 1e3,
|
|
3789
|
+
end: w.end / 1e3,
|
|
3790
|
+
confidence: w.confidence
|
|
3791
|
+
}))
|
|
3792
|
+
});
|
|
3793
|
+
}
|
|
3794
|
+
break;
|
|
3795
|
+
}
|
|
3796
|
+
case "Termination": {
|
|
3797
|
+
const termMsg = typedMessage;
|
|
3798
|
+
callbacks?.onMetadata?.({
|
|
3799
|
+
type: "termination",
|
|
3800
|
+
audioDurationSeconds: termMsg.audio_duration_seconds,
|
|
3801
|
+
sessionDurationSeconds: termMsg.session_duration_seconds
|
|
3802
|
+
});
|
|
3803
|
+
break;
|
|
3804
|
+
}
|
|
3805
|
+
default:
|
|
3806
|
+
callbacks?.onMetadata?.(message);
|
|
3807
|
+
break;
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
3159
3810
|
};
|
|
3160
3811
|
function createAssemblyAIAdapter(config) {
|
|
3161
3812
|
const adapter = new AssemblyAIAdapter();
|
|
@@ -3464,11 +4115,44 @@ var DeepgramAdapter = class extends BaseAdapter {
|
|
|
3464
4115
|
* Creates a WebSocket connection to Deepgram for streaming transcription.
|
|
3465
4116
|
* Send audio chunks via session.sendAudio() and receive results via callbacks.
|
|
3466
4117
|
*
|
|
4118
|
+
* Supports all Deepgram streaming features:
|
|
4119
|
+
* - Real-time transcription with interim/final results
|
|
4120
|
+
* - Speech detection events (SpeechStarted, UtteranceEnd)
|
|
4121
|
+
* - Speaker diarization
|
|
4122
|
+
* - Language detection
|
|
4123
|
+
* - Real-time sentiment, entity detection, topics, intents
|
|
4124
|
+
* - Custom vocabulary (keywords, keyterms)
|
|
4125
|
+
* - PII redaction
|
|
4126
|
+
* - Filler words, numerals, measurements, paragraphs
|
|
4127
|
+
* - Profanity filtering
|
|
4128
|
+
* - Dictation mode
|
|
4129
|
+
*
|
|
3467
4130
|
* @param options - Streaming configuration options
|
|
4131
|
+
* @param options.encoding - Audio encoding (linear16, flac, mulaw, opus, speex, g729)
|
|
4132
|
+
* @param options.sampleRate - Sample rate in Hz
|
|
4133
|
+
* @param options.channels - Number of audio channels
|
|
4134
|
+
* @param options.language - Language code for transcription
|
|
4135
|
+
* @param options.model - Model to use (nova-2, nova-3, base, enhanced, etc.)
|
|
4136
|
+
* @param options.diarization - Enable speaker identification
|
|
4137
|
+
* @param options.languageDetection - Auto-detect language
|
|
4138
|
+
* @param options.interimResults - Enable partial transcripts
|
|
4139
|
+
* @param options.summarization - Enable summarization
|
|
4140
|
+
* @param options.sentimentAnalysis - Enable sentiment analysis
|
|
4141
|
+
* @param options.entityDetection - Enable entity detection
|
|
4142
|
+
* @param options.piiRedaction - Enable PII redaction
|
|
4143
|
+
* @param options.customVocabulary - Keywords to boost recognition
|
|
4144
|
+
* @param options.deepgramStreaming - All Deepgram-specific streaming options
|
|
3468
4145
|
* @param callbacks - Event callbacks for transcription results
|
|
4146
|
+
* @param callbacks.onTranscript - Interim/final transcript received
|
|
4147
|
+
* @param callbacks.onUtterance - Complete utterance detected
|
|
4148
|
+
* @param callbacks.onSpeechStart - Speech detected (Deepgram SpeechStarted)
|
|
4149
|
+
* @param callbacks.onSpeechEnd - Speech ended (Deepgram UtteranceEnd)
|
|
4150
|
+
* @param callbacks.onMetadata - Metadata received
|
|
4151
|
+
* @param callbacks.onError - Error occurred
|
|
4152
|
+
* @param callbacks.onClose - Connection closed
|
|
3469
4153
|
* @returns Promise that resolves with a StreamingSession
|
|
3470
4154
|
*
|
|
3471
|
-
* @example
|
|
4155
|
+
* @example Basic real-time streaming
|
|
3472
4156
|
* ```typescript
|
|
3473
4157
|
* const session = await adapter.transcribeStream({
|
|
3474
4158
|
* encoding: 'linear16',
|
|
@@ -3491,32 +4175,47 @@ var DeepgramAdapter = class extends BaseAdapter {
|
|
|
3491
4175
|
* });
|
|
3492
4176
|
*
|
|
3493
4177
|
* // Send audio chunks
|
|
3494
|
-
* const audioChunk = getAudioChunk();
|
|
4178
|
+
* const audioChunk = getAudioChunk();
|
|
3495
4179
|
* await session.sendAudio({ data: audioChunk });
|
|
3496
4180
|
*
|
|
3497
4181
|
* // Close when done
|
|
3498
4182
|
* await session.close();
|
|
3499
4183
|
* ```
|
|
4184
|
+
*
|
|
4185
|
+
* @example Advanced streaming with all features
|
|
4186
|
+
* ```typescript
|
|
4187
|
+
* const session = await adapter.transcribeStream({
|
|
4188
|
+
* encoding: 'linear16',
|
|
4189
|
+
* sampleRate: 16000,
|
|
4190
|
+
* language: 'en',
|
|
4191
|
+
* model: 'nova-3',
|
|
4192
|
+
* diarization: true,
|
|
4193
|
+
* sentimentAnalysis: true,
|
|
4194
|
+
* entityDetection: true,
|
|
4195
|
+
* deepgramStreaming: {
|
|
4196
|
+
* fillerWords: true,
|
|
4197
|
+
* numerals: true,
|
|
4198
|
+
* profanityFilter: true,
|
|
4199
|
+
* topics: true,
|
|
4200
|
+
* intents: true,
|
|
4201
|
+
* customTopic: ['sales', 'support'],
|
|
4202
|
+
* customIntent: ['purchase', 'complaint'],
|
|
4203
|
+
* keyterm: ['TypeScript', 'JavaScript'],
|
|
4204
|
+
* utteranceSplit: 800,
|
|
4205
|
+
* punctuate: true,
|
|
4206
|
+
* smartFormat: true
|
|
4207
|
+
* }
|
|
4208
|
+
* }, {
|
|
4209
|
+
* onTranscript: (e) => console.log('Transcript:', e.text),
|
|
4210
|
+
* onSpeechStart: (e) => console.log('Speech started at:', e.timestamp),
|
|
4211
|
+
* onSpeechEnd: (e) => console.log('Utterance ended'),
|
|
4212
|
+
* onMetadata: (m) => console.log('Metadata:', m)
|
|
4213
|
+
* });
|
|
4214
|
+
* ```
|
|
3500
4215
|
*/
|
|
3501
4216
|
async transcribeStream(options, callbacks) {
|
|
3502
4217
|
this.validateConfig();
|
|
3503
|
-
const
|
|
3504
|
-
if (options?.encoding) params.append("encoding", options.encoding);
|
|
3505
|
-
if (options?.sampleRate) params.append("sample_rate", options.sampleRate.toString());
|
|
3506
|
-
if (options?.channels) params.append("channels", options.channels.toString());
|
|
3507
|
-
if (options?.language) params.append("language", options.language);
|
|
3508
|
-
if (options?.model) params.append("model", options.model);
|
|
3509
|
-
if (options?.languageDetection) params.append("detect_language", "true");
|
|
3510
|
-
if (options?.diarization) params.append("diarize", "true");
|
|
3511
|
-
if (options?.interimResults) params.append("interim_results", "true");
|
|
3512
|
-
if (options?.summarization) params.append("summarize", "true");
|
|
3513
|
-
if (options?.sentimentAnalysis) params.append("sentiment", "true");
|
|
3514
|
-
if (options?.entityDetection) params.append("detect_entities", "true");
|
|
3515
|
-
if (options?.piiRedaction) params.append("redact", "pii");
|
|
3516
|
-
if (options?.customVocabulary && options.customVocabulary.length > 0) {
|
|
3517
|
-
params.append("keywords", options.customVocabulary.join(","));
|
|
3518
|
-
}
|
|
3519
|
-
const wsUrl = `${this.wsBaseUrl}?${params.toString()}`;
|
|
4218
|
+
const wsUrl = this.buildStreamingUrl(options);
|
|
3520
4219
|
const ws = new import_ws3.default(wsUrl, {
|
|
3521
4220
|
headers: {
|
|
3522
4221
|
Authorization: `Token ${this.config.apiKey}`
|
|
@@ -3531,31 +4230,7 @@ var DeepgramAdapter = class extends BaseAdapter {
|
|
|
3531
4230
|
ws.on("message", (data) => {
|
|
3532
4231
|
try {
|
|
3533
4232
|
const message = JSON.parse(data.toString());
|
|
3534
|
-
|
|
3535
|
-
const channel = message.channel.alternatives[0];
|
|
3536
|
-
if (channel) {
|
|
3537
|
-
const transcript = channel.transcript;
|
|
3538
|
-
const isFinal = message.is_final;
|
|
3539
|
-
const words = channel.words?.map((w) => ({
|
|
3540
|
-
word: w.word,
|
|
3541
|
-
start: w.start,
|
|
3542
|
-
end: w.end,
|
|
3543
|
-
confidence: w.confidence
|
|
3544
|
-
}));
|
|
3545
|
-
callbacks?.onTranscript?.({
|
|
3546
|
-
type: "transcript",
|
|
3547
|
-
text: transcript,
|
|
3548
|
-
isFinal,
|
|
3549
|
-
words,
|
|
3550
|
-
confidence: channel.confidence,
|
|
3551
|
-
data: message
|
|
3552
|
-
});
|
|
3553
|
-
}
|
|
3554
|
-
} else if (message.type === "UtteranceEnd") {
|
|
3555
|
-
callbacks?.onMetadata?.(message);
|
|
3556
|
-
} else if (message.type === "Metadata") {
|
|
3557
|
-
callbacks?.onMetadata?.(message);
|
|
3558
|
-
}
|
|
4233
|
+
this.handleWebSocketMessage(message, callbacks);
|
|
3559
4234
|
} catch (error) {
|
|
3560
4235
|
callbacks?.onError?.({
|
|
3561
4236
|
code: "PARSE_ERROR",
|
|
@@ -3628,6 +4303,210 @@ var DeepgramAdapter = class extends BaseAdapter {
|
|
|
3628
4303
|
}
|
|
3629
4304
|
};
|
|
3630
4305
|
}
|
|
4306
|
+
/**
|
|
4307
|
+
* Build WebSocket URL with all streaming parameters
|
|
4308
|
+
*/
|
|
4309
|
+
buildStreamingUrl(options) {
|
|
4310
|
+
const params = new URLSearchParams();
|
|
4311
|
+
const dgOpts = options?.deepgramStreaming || {};
|
|
4312
|
+
if (options?.encoding || dgOpts.encoding) {
|
|
4313
|
+
params.append("encoding", options?.encoding || dgOpts.encoding);
|
|
4314
|
+
}
|
|
4315
|
+
if (options?.sampleRate || dgOpts.sampleRate) {
|
|
4316
|
+
params.append("sample_rate", String(options?.sampleRate || dgOpts.sampleRate));
|
|
4317
|
+
}
|
|
4318
|
+
if (options?.channels || dgOpts.channels) {
|
|
4319
|
+
params.append("channels", String(options?.channels || dgOpts.channels));
|
|
4320
|
+
}
|
|
4321
|
+
if (options?.language || dgOpts.language) {
|
|
4322
|
+
params.append("language", options?.language || dgOpts.language);
|
|
4323
|
+
}
|
|
4324
|
+
if (options?.model || dgOpts.model) {
|
|
4325
|
+
params.append("model", options?.model || dgOpts.model);
|
|
4326
|
+
}
|
|
4327
|
+
if (dgOpts.version) {
|
|
4328
|
+
params.append("version", dgOpts.version);
|
|
4329
|
+
}
|
|
4330
|
+
if (options?.languageDetection || dgOpts.languageDetection) {
|
|
4331
|
+
params.append("detect_language", "true");
|
|
4332
|
+
}
|
|
4333
|
+
if (options?.diarization || dgOpts.diarization) {
|
|
4334
|
+
params.append("diarize", "true");
|
|
4335
|
+
}
|
|
4336
|
+
if (options?.interimResults || dgOpts.interimResults) {
|
|
4337
|
+
params.append("interim_results", "true");
|
|
4338
|
+
}
|
|
4339
|
+
if (dgOpts.punctuate !== void 0) {
|
|
4340
|
+
params.append("punctuate", String(dgOpts.punctuate));
|
|
4341
|
+
}
|
|
4342
|
+
if (dgOpts.smartFormat !== void 0) {
|
|
4343
|
+
params.append("smart_format", String(dgOpts.smartFormat));
|
|
4344
|
+
}
|
|
4345
|
+
if (dgOpts.fillerWords) {
|
|
4346
|
+
params.append("filler_words", "true");
|
|
4347
|
+
}
|
|
4348
|
+
if (dgOpts.numerals) {
|
|
4349
|
+
params.append("numerals", "true");
|
|
4350
|
+
}
|
|
4351
|
+
if (dgOpts.measurements) {
|
|
4352
|
+
params.append("measurements", "true");
|
|
4353
|
+
}
|
|
4354
|
+
if (dgOpts.paragraphs) {
|
|
4355
|
+
params.append("paragraphs", "true");
|
|
4356
|
+
}
|
|
4357
|
+
if (dgOpts.profanityFilter) {
|
|
4358
|
+
params.append("profanity_filter", "true");
|
|
4359
|
+
}
|
|
4360
|
+
if (dgOpts.dictation) {
|
|
4361
|
+
params.append("dictation", "true");
|
|
4362
|
+
}
|
|
4363
|
+
if (dgOpts.utteranceSplit) {
|
|
4364
|
+
params.append("utt_split", String(dgOpts.utteranceSplit));
|
|
4365
|
+
}
|
|
4366
|
+
if (options?.summarization || dgOpts.summarize) {
|
|
4367
|
+
params.append("summarize", "true");
|
|
4368
|
+
}
|
|
4369
|
+
if (options?.sentimentAnalysis || dgOpts.sentiment) {
|
|
4370
|
+
params.append("sentiment", "true");
|
|
4371
|
+
}
|
|
4372
|
+
if (options?.entityDetection || dgOpts.detectEntities) {
|
|
4373
|
+
params.append("detect_entities", "true");
|
|
4374
|
+
}
|
|
4375
|
+
if (dgOpts.topics) {
|
|
4376
|
+
params.append("topics", "true");
|
|
4377
|
+
}
|
|
4378
|
+
if (dgOpts.customTopic && dgOpts.customTopic.length > 0) {
|
|
4379
|
+
dgOpts.customTopic.forEach((topic) => params.append("custom_topic", topic));
|
|
4380
|
+
}
|
|
4381
|
+
if (dgOpts.customTopicMode) {
|
|
4382
|
+
params.append("custom_topic_mode", dgOpts.customTopicMode);
|
|
4383
|
+
}
|
|
4384
|
+
if (dgOpts.intents) {
|
|
4385
|
+
params.append("intents", "true");
|
|
4386
|
+
}
|
|
4387
|
+
if (dgOpts.customIntent && dgOpts.customIntent.length > 0) {
|
|
4388
|
+
dgOpts.customIntent.forEach((intent) => params.append("custom_intent", intent));
|
|
4389
|
+
}
|
|
4390
|
+
if (dgOpts.customIntentMode) {
|
|
4391
|
+
params.append("custom_intent_mode", dgOpts.customIntentMode);
|
|
4392
|
+
}
|
|
4393
|
+
const keywords = options?.customVocabulary || dgOpts.keywords;
|
|
4394
|
+
if (keywords) {
|
|
4395
|
+
const keywordList = Array.isArray(keywords) ? keywords : [keywords];
|
|
4396
|
+
keywordList.forEach((kw) => params.append("keywords", kw));
|
|
4397
|
+
}
|
|
4398
|
+
if (dgOpts.keyterm && dgOpts.keyterm.length > 0) {
|
|
4399
|
+
dgOpts.keyterm.forEach((term) => params.append("keyterm", term));
|
|
4400
|
+
}
|
|
4401
|
+
if (options?.piiRedaction || dgOpts.redact) {
|
|
4402
|
+
if (Array.isArray(dgOpts.redact)) {
|
|
4403
|
+
dgOpts.redact.forEach((r) => params.append("redact", r));
|
|
4404
|
+
} else if (dgOpts.redact === true || options?.piiRedaction) {
|
|
4405
|
+
params.append("redact", "pii");
|
|
4406
|
+
params.append("redact", "pci");
|
|
4407
|
+
}
|
|
4408
|
+
}
|
|
4409
|
+
if (dgOpts.callback) {
|
|
4410
|
+
params.append("callback", dgOpts.callback);
|
|
4411
|
+
}
|
|
4412
|
+
if (dgOpts.tag && dgOpts.tag.length > 0) {
|
|
4413
|
+
dgOpts.tag.forEach((t) => params.append("tag", t));
|
|
4414
|
+
}
|
|
4415
|
+
if (dgOpts.extra) {
|
|
4416
|
+
params.append("extra", JSON.stringify(dgOpts.extra));
|
|
4417
|
+
}
|
|
4418
|
+
if (options?.endpointing !== void 0 || dgOpts.endpointing !== void 0) {
|
|
4419
|
+
const ep = options?.endpointing ?? dgOpts.endpointing;
|
|
4420
|
+
if (ep === false) {
|
|
4421
|
+
params.append("endpointing", "false");
|
|
4422
|
+
} else if (typeof ep === "number") {
|
|
4423
|
+
params.append("endpointing", String(ep));
|
|
4424
|
+
}
|
|
4425
|
+
}
|
|
4426
|
+
if (dgOpts.vadThreshold !== void 0) {
|
|
4427
|
+
params.append("vad_events", "true");
|
|
4428
|
+
}
|
|
4429
|
+
return `${this.wsBaseUrl}?${params.toString()}`;
|
|
4430
|
+
}
|
|
4431
|
+
/**
|
|
4432
|
+
* Handle all WebSocket message types from Deepgram streaming
|
|
4433
|
+
*/
|
|
4434
|
+
handleWebSocketMessage(message, callbacks) {
|
|
4435
|
+
switch (message.type) {
|
|
4436
|
+
case "Results": {
|
|
4437
|
+
const channel = message.channel.alternatives[0];
|
|
4438
|
+
if (channel && channel.transcript) {
|
|
4439
|
+
callbacks?.onTranscript?.({
|
|
4440
|
+
type: "transcript",
|
|
4441
|
+
text: channel.transcript,
|
|
4442
|
+
isFinal: message.is_final,
|
|
4443
|
+
confidence: channel.confidence,
|
|
4444
|
+
language: message.channel.detected_language,
|
|
4445
|
+
words: channel.words?.map((w) => ({
|
|
4446
|
+
word: w.punctuated_word || w.word,
|
|
4447
|
+
start: w.start,
|
|
4448
|
+
end: w.end,
|
|
4449
|
+
confidence: w.confidence,
|
|
4450
|
+
speaker: w.speaker?.toString()
|
|
4451
|
+
})),
|
|
4452
|
+
data: message
|
|
4453
|
+
});
|
|
4454
|
+
}
|
|
4455
|
+
if (message.speech_final && channel && channel.transcript) {
|
|
4456
|
+
callbacks?.onUtterance?.({
|
|
4457
|
+
text: channel.transcript,
|
|
4458
|
+
start: message.start,
|
|
4459
|
+
end: message.start + message.duration,
|
|
4460
|
+
confidence: channel.confidence,
|
|
4461
|
+
words: channel.words?.map((w) => ({
|
|
4462
|
+
word: w.punctuated_word || w.word,
|
|
4463
|
+
start: w.start,
|
|
4464
|
+
end: w.end,
|
|
4465
|
+
confidence: w.confidence
|
|
4466
|
+
}))
|
|
4467
|
+
});
|
|
4468
|
+
}
|
|
4469
|
+
break;
|
|
4470
|
+
}
|
|
4471
|
+
case "SpeechStarted": {
|
|
4472
|
+
const event = {
|
|
4473
|
+
type: "speech_start",
|
|
4474
|
+
timestamp: message.timestamp,
|
|
4475
|
+
channel: message.channel[0]
|
|
4476
|
+
};
|
|
4477
|
+
callbacks?.onSpeechStart?.(event);
|
|
4478
|
+
break;
|
|
4479
|
+
}
|
|
4480
|
+
case "UtteranceEnd": {
|
|
4481
|
+
const event = {
|
|
4482
|
+
type: "speech_end",
|
|
4483
|
+
timestamp: message.last_word_end,
|
|
4484
|
+
channel: message.channel[0]
|
|
4485
|
+
};
|
|
4486
|
+
callbacks?.onSpeechEnd?.(event);
|
|
4487
|
+
break;
|
|
4488
|
+
}
|
|
4489
|
+
case "Metadata": {
|
|
4490
|
+
callbacks?.onMetadata?.(message);
|
|
4491
|
+
break;
|
|
4492
|
+
}
|
|
4493
|
+
case "Error": {
|
|
4494
|
+
callbacks?.onError?.({
|
|
4495
|
+
code: message.variant || "DEEPGRAM_ERROR",
|
|
4496
|
+
message: message.message || message.description || "Unknown error",
|
|
4497
|
+
details: message
|
|
4498
|
+
});
|
|
4499
|
+
break;
|
|
4500
|
+
}
|
|
4501
|
+
case "CloseStream": {
|
|
4502
|
+
break;
|
|
4503
|
+
}
|
|
4504
|
+
default: {
|
|
4505
|
+
callbacks?.onMetadata?.(message);
|
|
4506
|
+
break;
|
|
4507
|
+
}
|
|
4508
|
+
}
|
|
4509
|
+
}
|
|
3631
4510
|
};
|
|
3632
4511
|
function createDeepgramAdapter(config) {
|
|
3633
4512
|
const adapter = new DeepgramAdapter();
|
|
@@ -5464,6 +6343,9 @@ function createWebhookRouter() {
|
|
|
5464
6343
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5465
6344
|
0 && (module.exports = {
|
|
5466
6345
|
AssemblyAIAdapter,
|
|
6346
|
+
AssemblyAIEncoding,
|
|
6347
|
+
AssemblyAISampleRate,
|
|
6348
|
+
AssemblyAISpeechModel,
|
|
5467
6349
|
AssemblyAITypes,
|
|
5468
6350
|
AssemblyAIWebhookHandler,
|
|
5469
6351
|
AzureSTTAdapter,
|
|
@@ -5471,8 +6353,18 @@ function createWebhookRouter() {
|
|
|
5471
6353
|
BaseAdapter,
|
|
5472
6354
|
BaseWebhookHandler,
|
|
5473
6355
|
DeepgramAdapter,
|
|
6356
|
+
DeepgramEncoding,
|
|
6357
|
+
DeepgramModel,
|
|
6358
|
+
DeepgramRedact,
|
|
6359
|
+
DeepgramTopicMode,
|
|
5474
6360
|
DeepgramWebhookHandler,
|
|
5475
6361
|
GladiaAdapter,
|
|
6362
|
+
GladiaBitDepth,
|
|
6363
|
+
GladiaEncoding,
|
|
6364
|
+
GladiaLanguage,
|
|
6365
|
+
GladiaModel,
|
|
6366
|
+
GladiaSampleRate,
|
|
6367
|
+
GladiaTranslationLanguage,
|
|
5476
6368
|
GladiaTypes,
|
|
5477
6369
|
GladiaWebhookHandler,
|
|
5478
6370
|
ListenV1EncodingParameter,
|