@todoforai/voiceloop 0.1.9 → 0.1.11
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/package.json +2 -2
- package/src/voice-agent.js +24 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@todoforai/voiceloop",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "Fast, interruptible browser voice agent: VAD → STT → LLM → TTS with real barge-in, echo filtering, streaming first-sentence TTS and tap-to-seek. Zero runtime dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"index.html"
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
|
-
"test": "node --test src/*.test.js"
|
|
24
|
+
"test": "node --test src/*.test.js bench/*.test.js bench/blackbox/energy.test.js"
|
|
25
25
|
},
|
|
26
26
|
"keywords": [
|
|
27
27
|
"voice",
|
package/src/voice-agent.js
CHANGED
|
@@ -982,7 +982,15 @@ export class VoiceAgent {
|
|
|
982
982
|
// call (llm.executesTools mode) must collapse too, or it would execute the tool a second time.
|
|
983
983
|
const dup = calls.some((c) => callKey(c) === callKey(item) ||
|
|
984
984
|
((!c.id || !item.id) && c.tool === item.tool && callArgs(c) === callArgs(item)));
|
|
985
|
-
if (!dup) {
|
|
985
|
+
if (!dup) {
|
|
986
|
+
calls.push(item); self._runTool(item);
|
|
987
|
+
// Late outcome: the turn already closed (barge-in mid-execution) and its ledger is
|
|
988
|
+
// written, so this result would reach the transcript chip but never the model. Relay it
|
|
989
|
+
// as a soft [TOOL RESULT] turn — the same channel out-of-band receipts use — so the next
|
|
990
|
+
// reply knows what the tool returned instead of seeing a call that vanished.
|
|
991
|
+
if (finalized && ('result' in item || 'error' in item))
|
|
992
|
+
self.notify(`[TOOL RESULT ${item.tool}] ${callArgs(item)}${ledgerOutcome(item)}`);
|
|
993
|
+
}
|
|
986
994
|
continue;
|
|
987
995
|
}
|
|
988
996
|
if (self.state === 'thinking') self._set('speaking'); // first token → TTS stage
|
|
@@ -1641,7 +1649,7 @@ export class StreamingTTS {
|
|
|
1641
1649
|
// predict()s, and presynth() below may fire while a previous reply's chain is still draining.
|
|
1642
1650
|
// Returns a promise that RESOLVES (wav or null-on-error) — callers surface errors per-entry.
|
|
1643
1651
|
_enqueueSynth(text, signal) {
|
|
1644
|
-
const run = this._synthQ.then(() => this._synth(stripMd(text) || text, signal), () => null); // || raw: a pure-syntax chunk strips to empty — voice the raw rather than abort
|
|
1652
|
+
const run = this._synthQ.then(() => signal?.aborted ? null : this._synth(stripMd(text) || text, signal), () => null); // || raw: a pure-syntax chunk strips to empty — voice the raw rather than abort
|
|
1645
1653
|
this._synthQ = run.catch(() => null);
|
|
1646
1654
|
return run;
|
|
1647
1655
|
}
|
|
@@ -1822,7 +1830,14 @@ export class StreamingTTS {
|
|
|
1822
1830
|
catch (e) { if (e?.name !== 'AbortError') streamErr = e; } // LLM/iterator failure → surface via awaitEntry, not a silent truncation
|
|
1823
1831
|
finally { streamDone = true; bump(); }
|
|
1824
1832
|
})();
|
|
1825
|
-
|
|
1833
|
+
// Stop waiting for an in-flight synth on abort, without releasing the serial synth queue:
|
|
1834
|
+
// Piper inference (and speculative clips without a signal) can finish only in their own time.
|
|
1835
|
+
let onAbort;
|
|
1836
|
+
const aborted = signal && new Promise((resolve) => { onAbort = () => { resolve(null); bump(); }; });
|
|
1837
|
+
if (signal) {
|
|
1838
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
1839
|
+
if (signal.aborted) onAbort();
|
|
1840
|
+
}
|
|
1826
1841
|
// Wait until the tape has an entry at `i` — or the stream ends, we abort, or a seek arrives (a
|
|
1827
1842
|
// backward tap while we're parked waiting for a FUTURE clip must be honored now, not after the
|
|
1828
1843
|
// stream advances). Producer runs ahead, so this usually returns immediately; it only blocks when
|
|
@@ -1859,7 +1874,11 @@ export class StreamingTTS {
|
|
|
1859
1874
|
while (true) {
|
|
1860
1875
|
if (idx >= tape.length) { await awaitEntry(idx); if (takePending()) continue; if (idx >= tape.length) break; } // wait for the producer to reach this sentence (stream end → done)
|
|
1861
1876
|
const e = tape[idx];
|
|
1862
|
-
const buf = await e.blobP;
|
|
1877
|
+
const buf = await (aborted ? Promise.race([e.blobP, aborted]) : e.blobP);
|
|
1878
|
+
// Barge-in while this clip was mid-synth: the abort cancels the synth fetch, which rejects with
|
|
1879
|
+
// AbortError ("signal is aborted without reason"). That's the cancellation we asked for, not a
|
|
1880
|
+
// failed render — stop quietly, exactly like an abort during playback.
|
|
1881
|
+
if (signal?.aborted) break;
|
|
1863
1882
|
// A clip that failed to RENDER is a voice problem, not an answer problem: the model already
|
|
1864
1883
|
// produced this text and the user is already reading it. Throwing here abandoned every
|
|
1865
1884
|
// REMAINING sentence — the reply went silent partway through and speak() resolved with only
|
|
@@ -1884,7 +1903,7 @@ export class StreamingTTS {
|
|
|
1884
1903
|
idx++; startNw = 0; // natural end → next sentence
|
|
1885
1904
|
}
|
|
1886
1905
|
} finally {
|
|
1887
|
-
signal?.removeEventListener('abort',
|
|
1906
|
+
signal?.removeEventListener('abort', onAbort);
|
|
1888
1907
|
// A finished stream is joined (it's already done — this just collects a trailing synth). An
|
|
1889
1908
|
// ABORTED one is DETACHED: the producer sits in it.next() on the HOST's llm generator, which
|
|
1890
1909
|
// may ignore the abort signal and never yield again, so awaiting it here would never return
|