@todoforai/voiceloop 0.1.15 → 0.1.16
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 +1 -1
- package/src/index.d.ts +2 -2
- package/src/stt.js +6 -6
- package/src/voice-agent.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@todoforai/voiceloop",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
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/index.d.ts
CHANGED
|
@@ -131,8 +131,8 @@ export interface VoiceAgentOptions {
|
|
|
131
131
|
/** LLM model id sent to the backend `/llm` route; empty → the backend's VOICE_MODEL default. */
|
|
132
132
|
model?: string;
|
|
133
133
|
llm?: LLM;
|
|
134
|
-
/** Transport seam for the built-in LLM adapter
|
|
135
|
-
* that must wrap every request (auth refresh, tracing).
|
|
134
|
+
/** Transport seam for the built-in LLM adapter AND the STT usage reports; defaults to global
|
|
135
|
+
* fetch. For tests and hosts that must wrap every request (auth refresh, tracing). */
|
|
136
136
|
fetchFn?: typeof fetch;
|
|
137
137
|
apiKey?: string;
|
|
138
138
|
/** Full endpoint URLs, not a base: voiceloop composes no routes, so a host can point the LLM and
|
package/src/stt.js
CHANGED
|
@@ -48,7 +48,7 @@ const newSocket = (url, protocols) => {
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
// Common opts shape (provided by the VoiceAgent):
|
|
51
|
-
// { apiKey, sttUrl, sttModel, sttLang, keyterms, sttTokenUrl, getToken, sttUsageUrl,
|
|
51
|
+
// { apiKey, sttUrl, sttModel, sttLang, keyterms, sttTokenUrl, getToken, sttUsageUrl, fetchFn (usage POSTs),
|
|
52
52
|
// onPartial, onFinal, onError, onClose, isClosed }
|
|
53
53
|
//
|
|
54
54
|
// AUTH (cloud providers): the raw provider key must stay server-side. Either
|
|
@@ -107,12 +107,12 @@ async function mintSttToken(url, apiKey, onFatal, getToken) {
|
|
|
107
107
|
// Accumulate streamed samples and flush them to /stt/usage — inline once USAGE_FLUSH_SECONDS is
|
|
108
108
|
// crossed, and again whenever the caller flushes on close (billing is trust-but-verify: the client
|
|
109
109
|
// reports what it streamed since the backend can't meter a direct browser↔provider socket).
|
|
110
|
-
function makeUsageReporter(sttUsageUrl, apiKey, provider, extra = {}) {
|
|
110
|
+
function makeUsageReporter(sttUsageUrl, apiKey, provider, extra = {}, fetchFn = fetch) {
|
|
111
111
|
let samples = 0;
|
|
112
112
|
const flush = () => {
|
|
113
113
|
const seconds = samples / 16000; samples = 0;
|
|
114
114
|
if (seconds <= 0 || !sttUsageUrl) return;
|
|
115
|
-
|
|
115
|
+
fetchFn(sttUsageUrl, {
|
|
116
116
|
method: 'POST', keepalive: true,
|
|
117
117
|
headers: { 'Content-Type': 'application/json', 'X-API-Key': apiKey },
|
|
118
118
|
body: JSON.stringify({ seconds, provider, ...extra }),
|
|
@@ -133,7 +133,7 @@ export function makeElevenLabsSTT(opts) {
|
|
|
133
133
|
const sttUrl = opts.sttUrl || 'wss://api.elevenlabs.io/v1/speech-to-text/realtime';
|
|
134
134
|
const sttModel = opts.sttModel || 'scribe_v2_realtime';
|
|
135
135
|
let ws = null, opening = false, outbox = [], sentSinceCommit = false, sttStart = 0;
|
|
136
|
-
const usage = makeUsageReporter(sttUsageUrl, apiKey, 'elevenlabs');
|
|
136
|
+
const usage = makeUsageReporter(sttUsageUrl, apiKey, 'elevenlabs', {}, opts.fetchFn);
|
|
137
137
|
|
|
138
138
|
const sendAudio = (i16) => {
|
|
139
139
|
if (!ws || ws.readyState !== 1) { outbox.push(i16); return; }
|
|
@@ -277,7 +277,7 @@ export function makeSpeechmaticsSTT(opts) {
|
|
|
277
277
|
flushFinal(true);
|
|
278
278
|
}, ms); };
|
|
279
279
|
|
|
280
|
-
const usage = makeUsageReporter(sttUsageUrl, apiKey, 'speechmatics', { model: sttModel || 'standard' });
|
|
280
|
+
const usage = makeUsageReporter(sttUsageUrl, apiKey, 'speechmatics', { model: sttModel || 'standard' }, opts.fetchFn);
|
|
281
281
|
|
|
282
282
|
const sendAudio = (i16) => {
|
|
283
283
|
if (!ws || ws.readyState !== 1 || !started) { outbox.push(i16); return; }
|
|
@@ -485,7 +485,7 @@ export function makeDeepgramSTT(opts) {
|
|
|
485
485
|
// TurnInfo.transcript is cumulative for the CURRENT turn (Flux restarts it on each new turn_index),
|
|
486
486
|
// so `turnText` is simply the latest transcript — no committed/tail split needed.
|
|
487
487
|
let turnText = '', audioSinceFinal = false, awaitingFinal = false, safetyTimer = null;
|
|
488
|
-
const usage = makeUsageReporter(sttUsageUrl, apiKey, 'deepgram', { model });
|
|
488
|
+
const usage = makeUsageReporter(sttUsageUrl, apiKey, 'deepgram', { model }, opts.fetchFn);
|
|
489
489
|
|
|
490
490
|
// Pre-open buffer is a bounded PREROLL (~1s), not a backlog: Flux is a real-time model — burst-
|
|
491
491
|
// sending seconds of buffered audio after a slow token fetch/handshake makes its whole timeline lag
|
package/src/voice-agent.js
CHANGED
|
@@ -202,7 +202,7 @@ export class VoiceAgent {
|
|
|
202
202
|
// `getSttToken` is called with the provider actually running — the RESOLVED one, so a host
|
|
203
203
|
// whose credential differs per provider never has to re-derive the webspeech downgrade
|
|
204
204
|
// (that rule lives here, in resolveSttProvider, and must not be mirrored host-side).
|
|
205
|
-
sttTokenUrl, getToken: getSttToken && (() => getSttToken(this.sttProvider)), sttUsageUrl, eotThreshold: sttEotThreshold,
|
|
205
|
+
sttTokenUrl, getToken: getSttToken && (() => getSttToken(this.sttProvider)), sttUsageUrl, fetchFn, eotThreshold: sttEotThreshold,
|
|
206
206
|
onPartial: (text, ms, committed = '') => {
|
|
207
207
|
const interim = `${committed} ${text}`.trim();
|
|
208
208
|
this._turnText = interim; // latest interim (committed prefix + live tail) for the turn detector
|