@todoforai/voiceloop 0.1.16 → 0.1.18
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/voice-agent.js +11 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@todoforai/voiceloop",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
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/voice-agent.js
CHANGED
|
@@ -47,9 +47,10 @@ registerProcessor('capture-processor', class extends AudioWorkletProcessor {
|
|
|
47
47
|
return true;
|
|
48
48
|
}
|
|
49
49
|
});`;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
// Built lazily: React Native ships a URL.createObjectURL that throws ("not implemented"), and a
|
|
51
|
+
// native host (audioIO) never loads the worklet at all — so nothing may run at import time.
|
|
52
|
+
let captureWorkletUrl = null;
|
|
53
|
+
const CAPTURE_WORKLET_URL_GET = () => captureWorkletUrl ??= URL.createObjectURL(new Blob([CAPTURE_WORKLET_SRC], { type: 'text/javascript' }));
|
|
53
54
|
|
|
54
55
|
// Compose the full system prompt: a persona (base voice persona by default, or a host-supplied one)
|
|
55
56
|
// + the host's conversation context (if any).
|
|
@@ -438,7 +439,7 @@ export class VoiceAgent {
|
|
|
438
439
|
try {
|
|
439
440
|
ctx = new AudioContext({ sampleRate: 16000 });
|
|
440
441
|
const src = ctx.createMediaStreamSource(stream);
|
|
441
|
-
await ctx.audioWorklet.addModule(
|
|
442
|
+
await ctx.audioWorklet.addModule(CAPTURE_WORKLET_URL_GET());
|
|
442
443
|
if (gen !== this._pipelineGen || this._closed) { stream.getTracks().forEach(t => t.stop()); ctx.close(); return; } // superseded/stopped while loading
|
|
443
444
|
const node = new AudioWorkletNode(ctx, 'capture-processor');
|
|
444
445
|
node.port.onmessage = e => this._onCapture(e.data); // Float32Array chunk from the audio thread
|
|
@@ -1960,6 +1961,9 @@ const CDN_PIPER_WASM = `${CDN}@diffusionstudio/piper-wasm@1.0.0/build/piper_phon
|
|
|
1960
1961
|
// literal specifier is resolved by Vite's import analysis BEFORE it checks /* @vite-ignore */ —
|
|
1961
1962
|
// which fails since onnxruntime-web isn't installed as a dependency.
|
|
1962
1963
|
const ORT_SPECIFIER = 'onnxruntime-web';
|
|
1964
|
+
// Dynamic import by URL, hidden from bundlers: Hermes (React Native) rejects `import(expr)` at
|
|
1965
|
+
// bytecode compile time, so the syntax can't appear in this file even on paths RN never takes.
|
|
1966
|
+
const importUrl = new Function('u', 'return import(u)');
|
|
1963
1967
|
|
|
1964
1968
|
// OPFS blob cache — same 'piper' directory and url-basename filenames as the lib's own cache, so
|
|
1965
1969
|
// models already downloaded through the lib are reused (and vice versa).
|
|
@@ -2012,7 +2016,7 @@ export class PiperTTS extends StreamingTTS {
|
|
|
2012
2016
|
if (typeof document !== 'undefined' && !document.getElementById('vl-importmap')) {
|
|
2013
2017
|
const { loadVoiceDeps } = await import('./deps.js'); await loadVoiceDeps();
|
|
2014
2018
|
}
|
|
2015
|
-
return
|
|
2019
|
+
return importUrl(CDN_PIPER);
|
|
2016
2020
|
})();
|
|
2017
2021
|
}
|
|
2018
2022
|
|
|
@@ -2042,8 +2046,8 @@ export class PiperTTS extends StreamingTTS {
|
|
|
2042
2046
|
const path = lib.PATH_MAP[voiceId];
|
|
2043
2047
|
if (!path) throw new Error(`unknown Piper voice: ${voiceId}`);
|
|
2044
2048
|
const [ort, phonMod, cfgBlob, modelBlob] = await Promise.all([
|
|
2045
|
-
|
|
2046
|
-
|
|
2049
|
+
importUrl(ORT_SPECIFIER),
|
|
2050
|
+
importUrl(CDN_PIPER_PHONEMIZE),
|
|
2047
2051
|
opfsCachedFetch(`${lib.HF_BASE}/${path}.json`),
|
|
2048
2052
|
opfsCachedFetch(`${lib.HF_BASE}/${path}`, this._onModelProgress),
|
|
2049
2053
|
]);
|