@todoforai/voiceloop 0.1.21 → 0.1.23

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/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).
@@ -0,0 +1,6 @@
1
+ {
2
+ "account": {
3
+ "id": "16b8c73d88d470f6d39fee082391723e",
4
+ "name": "Havlikmarcell@gmail.com's Account"
5
+ }
6
+ }
@@ -7,6 +7,7 @@ out only what each hop needs.
7
7
  | route | returns | why |
8
8
  |---|---|---|
9
9
  | `POST /stt/token` | `{ token, expires_in }` | short-TTL Deepgram key; the browser opens the WS itself |
10
+ | `POST /stt/soniox-token` | `{ token, expires_in }` | short-TTL Soniox key (same shape) |
10
11
  | `POST /tts` | `audio/mpeg` | ElevenLabs proxy — the `xi-api-key` stays server-side |
11
12
  | `POST /llm` | OpenAI-format SSE | Anthropic proxy — Claude has no short-TTL key to mint, so the key stays here |
12
13
 
@@ -17,6 +18,7 @@ out only what each hop needs.
17
18
  ```sh
18
19
  wrangler deploy
19
20
  wrangler secret put DEEPGRAM_API_KEY
21
+ wrangler secret put SONIOX_API_KEY
20
22
  wrangler secret put ELEVENLABS_API_KEY
21
23
  wrangler secret put ANTHROPIC_API_KEY
22
24
  ```
@@ -4,10 +4,11 @@
4
4
  // never reach the page, so this Worker holds them and hands out only what each hop needs:
5
5
  //
6
6
  // POST /stt/token → { token, expires_in } short-TTL Deepgram key (browser opens the WS itself)
7
+ // POST /stt/soniox-token → same shape short-TTL Soniox key
7
8
  // POST /tts → audio/mpeg bytes ElevenLabs proxy (the xi-api-key stays here)
8
9
  // POST /llm → OpenAI-format SSE Anthropic proxy (there is no short-TTL key to mint)
9
10
  //
10
- // Secrets (wrangler secret put): DEEPGRAM_API_KEY, ELEVENLABS_API_KEY, ANTHROPIC_API_KEY.
11
+ // Secrets (wrangler secret put): DEEPGRAM_API_KEY, SONIOX_API_KEY, ELEVENLABS_API_KEY, ANTHROPIC_API_KEY.
11
12
  // ALLOWED_ORIGINS (var) is a comma-separated allowlist — these routes spend real money, so an
12
13
  // open CORS policy is an open wallet.
13
14
  //
@@ -99,7 +100,7 @@ export default {
99
100
  // Everything below mints a credential or bills a provider. /stt/token mints at most one
100
101
  // credential per 5 min so it takes the tight limiter; /tts fires once per spoken SENTENCE and
101
102
  // /llm once per turn plus prefetch, so the conversation hot path gets its own, roomier window.
102
- const limiter = url.pathname === '/stt/token' ? env.PAID_RATE_LIMITER : env.CONVO_RATE_LIMITER;
103
+ const limiter = url.pathname.startsWith('/stt/') ? env.PAID_RATE_LIMITER : env.CONVO_RATE_LIMITER;
103
104
  if (await rateLimited(req, env, limiter)) return json({ error: 'rate limited — try again in a minute' }, 429, origin);
104
105
 
105
106
  if (url.pathname === '/stt/token') {
@@ -115,6 +116,18 @@ export default {
115
116
  return json({ token: body.access_token, expires_in: body.expires_in ?? 300 }, 200, origin);
116
117
  }
117
118
 
119
+ if (url.pathname === '/stt/soniox-token') {
120
+ if (!env.SONIOX_API_KEY) return json({ error: 'SONIOX_API_KEY not configured' }, 500, origin);
121
+ const r = await fetch('https://api.soniox.com/v1/auth/temporary-api-key', {
122
+ method: 'POST',
123
+ headers: { authorization: `Bearer ${env.SONIOX_API_KEY}`, 'content-type': 'application/json' },
124
+ body: JSON.stringify({ usage_type: 'transcribe_websocket', expires_in_seconds: 300 }),
125
+ });
126
+ const body = await r.json().catch(() => ({}));
127
+ if (!r.ok || !body.api_key) return json({ error: body.message || body.error || 'mint failed' }, 502, origin);
128
+ return json({ token: body.api_key, expires_in: 300 }, 200, origin);
129
+ }
130
+
118
131
  if (url.pathname === '/tts') {
119
132
  if (!env.ELEVENLABS_API_KEY) return json({ error: 'ELEVENLABS_API_KEY not configured' }, 500, origin);
120
133
  const { text, voice_id, model_id, output_format } = await req.json().catch(() => ({}));
@@ -1,5 +1,5 @@
1
1
  name = "voiceloop-token"
2
- main = "src/index.js"
2
+ main = "index.js"
3
3
  compatibility_date = "2026-01-01"
4
4
 
5
5
  [vars]
package/index.html CHANGED
@@ -318,13 +318,24 @@
318
318
  </main>
319
319
 
320
320
  <script type="module">
321
- import { VoiceAgent, PiperTTS, ElevenLabsTTS, makeOpenAILLM, unlockAudio, prewarmVoice, STT_PROVIDERS, sttSelfCaptures, LANG_NAMES } from './src/index.js';
321
+ import { VoiceAgent, PiperTTS, ElevenLabsTTS, makeOpenAILLM, unlockAudio, prewarmVoice, warmDeepgramToken, warmSonioxToken, STT_PROVIDERS, sttSelfCaptures, LANG_NAMES } from './src/index.js';
322
322
 
323
323
  // Load VAD/WASM + build the Silero session while the page sits idle — but ONLY for a provider that
324
324
  // will actually use it. A selfCapture provider (webspeech) builds no pipeline, so prewarming there
325
325
  // downloads an ONNX model to feed a detector that never runs.
326
326
  const prewarmIfPipelined = () => { if (!sttSelfCaptures($('sttProvider').value)) prewarmVoice(); };
327
327
 
328
+ // Pay the per-hop cold costs while idle, not on ▶: the STT token mint (0.6–2.7s when it races the
329
+ // mic/VAD start) and the LLM route's DNS+TLS. Both keyed on the current field values so a change
330
+ // re-warms the NEW target; all best-effort — open() re-mints and the first turn reconnects on miss.
331
+ const STT_TOKEN_WARMERS = { deepgram: warmDeepgramToken, soniox: warmSonioxToken };
332
+ const prewarmRoutes = () => {
333
+ const warm = STT_TOKEN_WARMERS[$('sttProvider').value], tokenUrl = $('sttTokenUrl').value.trim();
334
+ if (warm && tokenUrl) warm(tokenUrl, $('apiKey').value.trim()).catch(() => {});
335
+ const llmUrl = $('mode').value === 'llm' ? $('llmUrl').value.trim() : $('mode').value === 'hosted' ? HOSTED_LLM_URL : '';
336
+ if (llmUrl) fetch(llmUrl, { method: 'HEAD', signal: AbortSignal.timeout(3000) }).catch(() => {});
337
+ };
338
+
328
339
  const $ = id => document.getElementById(id);
329
340
  const fill = (id, entries) => $(id).append(...entries.map(([value, textContent]) =>
330
341
  Object.assign(document.createElement('option'), { value, textContent })));
@@ -461,7 +472,7 @@ function onSettingChanged() {
461
472
  for (const id of ['llmUrl', 'model']) $(id).disabled = !custom;
462
473
  $('sttTokenUrl').disabled = self;
463
474
  $('apiKey').disabled = !custom && self; // used as LLM Bearer OR token-route X-API-Key — dead only when neither hop exists
464
- showPipeline(); prewarmIfPipelined();
475
+ showPipeline(); prewarmIfPipelined(); prewarmRoutes();
465
476
  }
466
477
 
467
478
  // ── the orb's level ─────────────────────────────────────────────────────────
@@ -743,6 +754,7 @@ const applyTts = () => {
743
754
  wireModelProgress();
744
755
  dropAgent('tts');
745
756
  loadVoices();
757
+ if (tts instanceof ElevenLabsTTS) tts.warm().catch(() => {}); // DNS+TLS now, not 2.5s after ▶ (Piper's 60MB stays behind the click)
746
758
  log('tts →', $('ttsProvider').value);
747
759
  };
748
760
  let ttsUrlTimer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@todoforai/voiceloop",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
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';
@@ -407,11 +407,16 @@ export class VoiceAgent {
407
407
  try {
408
408
  stream = await navigator.mediaDevices.getUserMedia({ audio });
409
409
  } catch (e) {
410
- // The saved mic id no longer exists on this machine (unplugged / different device / stale
411
- // cross-profile localStorage) — `exact` throws OverconstrainedError instead of falling back.
412
- // Retry once on the system default so a stale preference doesn't brick the whole session.
413
- if (deviceId && e.name === 'OverconstrainedError') stream = await navigator.mediaDevices.getUserMedia({ audio: { ...audio, deviceId: undefined } });
414
- else throw e;
410
+ // OverconstrainedError ("Invalid constraint" on WebKit) has two causes:
411
+ // - the saved mic id no longer exists here (unplugged / different device / stale
412
+ // cross-profile localStorage) — `exact` rejects instead of falling back;
413
+ // - WebKitGTK (Tauri on Linux) treats the bare DSP constraints as REQUIRED, so
414
+ // channelCount/autoGainControl can be unsatisfiable even with no deviceId.
415
+ // Degrade in that order — a default mic with default DSP beats no session at all.
416
+ if (e.name !== 'OverconstrainedError') throw e;
417
+ stream = await navigator.mediaDevices.getUserMedia({ audio: { ...audio, deviceId: undefined } })
418
+ .catch(() => navigator.mediaDevices.getUserMedia({ audio: true }))
419
+ .catch(() => { throw e; });
415
420
  }
416
421
  } catch (e) {
417
422
  // Mic open failed (permission denied / no device / constraints). We already optimistically