@todoforai/voiceloop 0.1.4 → 0.1.5

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 +6 -1
  2. package/package.json +1 -1
  3. package/src/stt.js +7 -5
package/README.md CHANGED
@@ -123,7 +123,12 @@ new VoiceAgent({ sttProvider: 'speechmatics', sttTokenUrl: '/api/stt/token' })
123
123
  Cloud providers authenticate with a **short-TTL token minted by your backend** so the raw API key never reaches the page. Either:
124
124
 
125
125
  - `sttTokenUrl` — a POST route on your server that returns `{ token }` (mint it against the provider's temp-token API with your secret key), or
126
- - `getSttToken` — an async callback `() => ({ token })` when your auth doesn't fit a bare POST.
126
+ - `getSttToken` — an async callback `(provider) => ({ token })` when your auth doesn't fit a bare POST, or when each provider mints a different credential. It is handed the provider actually running (after the fallback below), so you pick the route without re-deriving that rule:
127
+
128
+ ```js
129
+ const ROUTE = { elevenlabs: '/api/stt/token', deepgram: '/api/stt/deepgram-token' };
130
+ new VoiceAgent({ sttProvider, getSttToken: p => fetch(ROUTE[p], { method: 'POST' }).then(r => r.json()) })
131
+ ```
127
132
 
128
133
  On browsers without SpeechRecognition (Firefox, WebKitGTK) `webspeech` falls back to `elevenlabs` — which needs a token route configured, so pass `sttTokenUrl`/`getSttToken` if you want the fallback to work.
129
134
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@todoforai/voiceloop",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
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
@@ -58,18 +58,20 @@ const USAGE_FLUSH_SECONDS = 30; // report streamed seconds to the backend at l
58
58
  // state to clear on failure differs per provider, so that stays with the caller).
59
59
  async function mintSttToken(url, apiKey, onFatal, getToken) {
60
60
  if (getToken) {
61
+ // HOST code on the critical path: bound it exactly like the built-in fetch below, or a minter
62
+ // that never settles stalls voice start forever with no error. We can't cancel the host's
63
+ // promise — we just stop waiting on it (it may still resolve into the void, which is fine:
64
+ // a token is idempotent to mint).
65
+ let timer;
61
66
  try {
62
- // HOST code on the critical path: bound it exactly like the built-in fetch below, or a minter
63
- // that never settles stalls voice start forever with no error. We can't cancel the host's
64
- // promise — we just stop waiting on it (it may still resolve into the void, which is fine:
65
- // a token is idempotent to mint).
66
67
  const body = await Promise.race([
67
68
  getToken(),
68
- new Promise((_, rej) => setTimeout(() => rej(new Error('timed out')), TUNING.STT.tokenFetchTimeoutMs)),
69
+ new Promise((_, rej) => { timer = setTimeout(() => rej(new Error('timed out')), TUNING.STT.tokenFetchTimeoutMs); }),
69
70
  ]);
70
71
  if (!body?.token) throw new Error('getToken returned no token');
71
72
  return body;
72
73
  } catch (e) { onFatal(`STT token: ${e.message}`); return null; }
74
+ finally { clearTimeout(timer); } // a fast mint must not hold the timer (and Node's loop) open
73
75
  }
74
76
  if (!url) { onFatal('STT token: no sttTokenUrl/getToken configured — cloud STT needs a token route (see README)'); return null; }
75
77
  let res;