@todoforai/voiceloop 0.1.21 → 0.1.22

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.
Files changed (3) hide show
  1. package/README.md +7 -0
  2. package/package.json +1 -1
  3. package/src/stt.js +12 -10
package/README.md CHANGED
@@ -108,12 +108,19 @@ into the mic (no AEC):
108
108
  | system | latency (clean) | talked through user | cut itself under echo |
109
109
  |---|---|---|---|
110
110
  | OpenAI Realtime (own LLM)* | 870ms | **0/30** | **17/30** |
111
+ | **voiceloop** (soniox + ElevenLabs flash)† | **770ms** | 7/30 | 0/30 |
111
112
  | **voiceloop** (deepgram + ElevenLabs flash) | **980ms** | **0/30** | **0/30** |
112
113
  | **voiceloop** (deepgram + Piper, free local TTS) | **970ms** | **0/30** | — |
113
114
  | **voiceloop** (webspeech + Piper, zero-key default) | 2110ms | — | — |
114
115
  | Pipecat 1.8.1 (same providers) | 1050ms | 2/30 | **20/30** |
115
116
  | ElevenLabs ConvAI | 1450ms | **0/30** | 0/30 |
116
117
 
118
+ † Soniox row measured 2026-09-16 (5 runs × 6 turns each, scoring v2; the other rows are the
119
+ 2026-08-31 v1 numbers). Soniox is the faster and cheaper STT ($0.12/hr vs $0.39/hr, 60+ languages)
120
+ but its endpointing is acoustic-leaning: it enters a mid-sentence pause on 15/30 hesitation turns and
121
+ talks through 7 of them (Flux: 2 → 0). Pick Flux when never-interrupt matters more than 100–400ms.
122
+ Full tables: [bench/results/SONIOX-VS-DEEPGRAM.md](bench/results/SONIOX-VS-DEEPGRAM.md).
123
+
117
124
  The separating failure is echo: with no AEC, the other fast stacks hear their own voice as the
118
125
  user and cut their own replies. voiceloop's word-level echo filter runs echo-coupled turns at
119
126
  full speed (930ms — parity with clean).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@todoforai/voiceloop",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
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",
package/src/stt.js CHANGED
@@ -635,13 +635,19 @@ const SONIOX_HOLD_MS = 1500;
635
635
  // Same token cache/prewarm as Deepgram (see dgToken): the temporary-key mint + WS open cost ~2s on
636
636
  // the first utterance when paid cold on the mic click.
637
637
  let sxToken = null, sxTokenExp = 0, sxMintPromise = null;
638
- export function warmSonioxToken(sttTokenUrl, apiKey, getToken) {
639
- if (sxToken && performance.now() < sxTokenExp - 30000) return Promise.resolve();
638
+ // One acquisition path for prewarm AND open(): a click landing mid-prewarm joins that mint
639
+ // instead of starting a second one. `slackMs` = how much life the cached key must have left.
640
+ function acquireSonioxToken(sttTokenUrl, apiKey, onFatal, getToken, slackMs) {
641
+ if (sxToken && performance.now() < sxTokenExp - slackMs) return Promise.resolve(sxToken);
640
642
  return (sxMintPromise ??= (async () => {
641
- const body = await mintSttToken(sttTokenUrl, apiKey, () => {}, getToken);
643
+ const body = await mintSttToken(sttTokenUrl, apiKey, onFatal, getToken);
642
644
  if (body) { sxToken = body.token; sxTokenExp = performance.now() + (body.expires_in ?? 300) * 1000; }
645
+ return body?.token ?? null;
643
646
  })().finally(() => { sxMintPromise = null; }));
644
647
  }
648
+ export function warmSonioxToken(sttTokenUrl, apiKey, getToken) {
649
+ return acquireSonioxToken(sttTokenUrl, apiKey, () => {}, getToken, 30000).then(() => {}); // best-effort: open() re-mints
650
+ }
645
651
  const sonioxContinues = (t) => /[—–-]$/.test(t) || /^(um+|uh+|hmm+|er+|ah+)[.,]?$/i.test(t);
646
652
  export function makeSonioxSTT(opts) {
647
653
  const { apiKey, sttModel, sttLang = 'en', keyterms = [], sttTokenUrl, getToken, sttUsageUrl,
@@ -698,17 +704,13 @@ export function makeSonioxSTT(opts) {
698
704
  if (opening) return;
699
705
  opening = true;
700
706
  try {
701
- let token = (sxToken && performance.now() < sxTokenExp - 15000) ? sxToken : null;
702
- if (!token) {
703
- const body = await mintSttToken(sttTokenUrl, apiKey, onFatal, getToken);
704
- if (!body) { outbox = []; outboxSamples = 0; return; }
705
- token = sxToken = body.token; sxTokenExp = performance.now() + (body.expires_in ?? 300) * 1000;
706
- }
707
+ const token = await acquireSonioxToken(sttTokenUrl, apiKey, onFatal, getToken, 15000);
708
+ if (!token) { outbox = []; outboxSamples = 0; return; }
707
709
  if (isClosed()) return;
708
710
  // NEW SOCKET = NEW STREAM: whatever the old one left half-finalized is gone with it. A pending
709
711
  // commit() survives (its finalize is re-sent on open, its safety timer still closes the turn)
710
712
  // so the host's closing latch always resolves.
711
- resetText();
713
+ resetText(); dropHold(); // a held cut-off phrase belongs to the dead stream too
712
714
  clearInterval(keepalive); keepalive = null; // the superseded socket's timer must not outlive it
713
715
  const sock = ws = newSocket(sttUrl);
714
716
  sock.binaryType = 'arraybuffer';