@absolutejs/voice-deepgram 0.0.20-beta.98 → 0.0.20-beta.99
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/index.js +10 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -375,6 +375,8 @@ var deepgram = (config) => ({
|
|
|
375
375
|
const connection = await createTransport(url, config.apiKey, config.authMode);
|
|
376
376
|
const connectTimeoutMs = config.connectTimeoutMs ?? 8000;
|
|
377
377
|
const keepAliveMs = config.keepAliveMs ?? 4000;
|
|
378
|
+
const silenceKeepAliveFrame = new Uint8Array(Math.max(2, Math.round(runtimeOptions.format.sampleRateHz * 0.1) * 2));
|
|
379
|
+
let lastRealAudioAt = 0;
|
|
378
380
|
const pendingAudio = [];
|
|
379
381
|
const deduper = createSignalDeduper();
|
|
380
382
|
let keepAliveTimer = null;
|
|
@@ -424,6 +426,7 @@ var deepgram = (config) => ({
|
|
|
424
426
|
const next = pendingAudio.shift();
|
|
425
427
|
if (next) {
|
|
426
428
|
connection.send(next);
|
|
429
|
+
lastRealAudioAt = Date.now();
|
|
427
430
|
}
|
|
428
431
|
}
|
|
429
432
|
clearKeepAlive();
|
|
@@ -436,6 +439,12 @@ var deepgram = (config) => ({
|
|
|
436
439
|
clearKeepAlive();
|
|
437
440
|
return;
|
|
438
441
|
}
|
|
442
|
+
if (emitsNativeEndOfTurn) {
|
|
443
|
+
if (Date.now() - lastRealAudioAt >= keepAliveMs) {
|
|
444
|
+
connection.send(silenceKeepAliveFrame);
|
|
445
|
+
}
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
439
448
|
connection.send(JSON.stringify({ type: "KeepAlive" }));
|
|
440
449
|
}, keepAliveMs);
|
|
441
450
|
resolve();
|
|
@@ -613,6 +622,7 @@ var deepgram = (config) => ({
|
|
|
613
622
|
}
|
|
614
623
|
if (opened && connection.readyState === WebSocket.OPEN) {
|
|
615
624
|
connection.send(audio);
|
|
625
|
+
lastRealAudioAt = Date.now();
|
|
616
626
|
return;
|
|
617
627
|
}
|
|
618
628
|
pendingAudio.push(audio);
|