@absolutejs/voice 0.0.22-beta.596 → 0.0.22-beta.597
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 +22 -0
- package/dist/testing/index.js +22 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3757,6 +3757,8 @@ var getBufferedAudioDurationMs = (chunks) => chunks.reduce((total, chunk) => tot
|
|
|
3757
3757
|
var STREAM_SENTENCE_BOUNDARY = /[.!?\u2026]['")\]]*\s/;
|
|
3758
3758
|
var STREAM_CLAUSE_BOUNDARY = /[,;:]\s/g;
|
|
3759
3759
|
var MAX_TTS_CHUNK_CHARS = 320;
|
|
3760
|
+
var STREAM_SENTENCE_END = /[.!?\u2026]['")\]]*$/;
|
|
3761
|
+
var STREAM_IDLE_FLUSH_MS = 350;
|
|
3760
3762
|
var nextSpeakableBoundary = (buffer) => {
|
|
3761
3763
|
const match = STREAM_SENTENCE_BOUNDARY.exec(buffer);
|
|
3762
3764
|
return match ? match.index + match[0].length : -1;
|
|
@@ -5448,6 +5450,7 @@ var createVoiceSession = (options) => {
|
|
|
5448
5450
|
let charsSent = 0;
|
|
5449
5451
|
let started = false;
|
|
5450
5452
|
let streamed = false;
|
|
5453
|
+
let idleFlushTimer = null;
|
|
5451
5454
|
let sendChain = Promise.resolve();
|
|
5452
5455
|
let ttsSessionRequest = null;
|
|
5453
5456
|
const ttsStartedAt = Date.now();
|
|
@@ -5507,8 +5510,23 @@ var createVoiceSession = (options) => {
|
|
|
5507
5510
|
}
|
|
5508
5511
|
})();
|
|
5509
5512
|
};
|
|
5513
|
+
const clearIdleFlush = () => {
|
|
5514
|
+
if (idleFlushTimer) {
|
|
5515
|
+
clearTimeout(idleFlushTimer);
|
|
5516
|
+
idleFlushTimer = null;
|
|
5517
|
+
}
|
|
5518
|
+
};
|
|
5519
|
+
const flushOnIdle = () => {
|
|
5520
|
+
idleFlushTimer = null;
|
|
5521
|
+
const pending = buffer.trim();
|
|
5522
|
+
if (pending && STREAM_SENTENCE_END.test(pending)) {
|
|
5523
|
+
flush(buffer);
|
|
5524
|
+
buffer = "";
|
|
5525
|
+
}
|
|
5526
|
+
};
|
|
5510
5527
|
return {
|
|
5511
5528
|
finish: async () => {
|
|
5529
|
+
clearIdleFlush();
|
|
5512
5530
|
if (buffer.trim()) {
|
|
5513
5531
|
flush(buffer);
|
|
5514
5532
|
}
|
|
@@ -5554,6 +5572,10 @@ var createVoiceSession = (options) => {
|
|
|
5554
5572
|
flush(buffer.slice(0, cut));
|
|
5555
5573
|
buffer = buffer.slice(cut);
|
|
5556
5574
|
}
|
|
5575
|
+
clearIdleFlush();
|
|
5576
|
+
if (buffer.trim()) {
|
|
5577
|
+
idleFlushTimer = setTimeout(flushOnIdle, STREAM_IDLE_FLUSH_MS);
|
|
5578
|
+
}
|
|
5557
5579
|
}
|
|
5558
5580
|
};
|
|
5559
5581
|
};
|
package/dist/testing/index.js
CHANGED
|
@@ -5984,6 +5984,8 @@ var getBufferedAudioDurationMs = (chunks) => chunks.reduce((total, chunk) => tot
|
|
|
5984
5984
|
var STREAM_SENTENCE_BOUNDARY = /[.!?\u2026]['")\]]*\s/;
|
|
5985
5985
|
var STREAM_CLAUSE_BOUNDARY = /[,;:]\s/g;
|
|
5986
5986
|
var MAX_TTS_CHUNK_CHARS = 320;
|
|
5987
|
+
var STREAM_SENTENCE_END = /[.!?\u2026]['")\]]*$/;
|
|
5988
|
+
var STREAM_IDLE_FLUSH_MS = 350;
|
|
5987
5989
|
var nextSpeakableBoundary = (buffer) => {
|
|
5988
5990
|
const match = STREAM_SENTENCE_BOUNDARY.exec(buffer);
|
|
5989
5991
|
return match ? match.index + match[0].length : -1;
|
|
@@ -7675,6 +7677,7 @@ var createVoiceSession = (options) => {
|
|
|
7675
7677
|
let charsSent = 0;
|
|
7676
7678
|
let started = false;
|
|
7677
7679
|
let streamed = false;
|
|
7680
|
+
let idleFlushTimer = null;
|
|
7678
7681
|
let sendChain = Promise.resolve();
|
|
7679
7682
|
let ttsSessionRequest = null;
|
|
7680
7683
|
const ttsStartedAt = Date.now();
|
|
@@ -7734,8 +7737,23 @@ var createVoiceSession = (options) => {
|
|
|
7734
7737
|
}
|
|
7735
7738
|
})();
|
|
7736
7739
|
};
|
|
7740
|
+
const clearIdleFlush = () => {
|
|
7741
|
+
if (idleFlushTimer) {
|
|
7742
|
+
clearTimeout(idleFlushTimer);
|
|
7743
|
+
idleFlushTimer = null;
|
|
7744
|
+
}
|
|
7745
|
+
};
|
|
7746
|
+
const flushOnIdle = () => {
|
|
7747
|
+
idleFlushTimer = null;
|
|
7748
|
+
const pending = buffer.trim();
|
|
7749
|
+
if (pending && STREAM_SENTENCE_END.test(pending)) {
|
|
7750
|
+
flush(buffer);
|
|
7751
|
+
buffer = "";
|
|
7752
|
+
}
|
|
7753
|
+
};
|
|
7737
7754
|
return {
|
|
7738
7755
|
finish: async () => {
|
|
7756
|
+
clearIdleFlush();
|
|
7739
7757
|
if (buffer.trim()) {
|
|
7740
7758
|
flush(buffer);
|
|
7741
7759
|
}
|
|
@@ -7781,6 +7799,10 @@ var createVoiceSession = (options) => {
|
|
|
7781
7799
|
flush(buffer.slice(0, cut));
|
|
7782
7800
|
buffer = buffer.slice(cut);
|
|
7783
7801
|
}
|
|
7802
|
+
clearIdleFlush();
|
|
7803
|
+
if (buffer.trim()) {
|
|
7804
|
+
idleFlushTimer = setTimeout(flushOnIdle, STREAM_IDLE_FLUSH_MS);
|
|
7805
|
+
}
|
|
7784
7806
|
}
|
|
7785
7807
|
};
|
|
7786
7808
|
};
|