alkove 0.5.0 → 0.6.0

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/dist/cli.js CHANGED
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import{copyFile as G,mkdir as I,writeFile as W}from"node:fs/promises";import{dirname as z,join as w}from"node:path";import{fileURLToPath as J}from"node:url";var d=class extends Error{constructor(t,r,a){super(r);this.code=t;this.cause=a}name="AlkoveError"};var m="alkove-ai",k={focus:{name:"alkove-focus-1",file:"alkove-focus-1.alk",bytes:2320032,sha256:"25028c1f9faf765ccab4076716b5e8a8e756cd7662babd2bc078951982df5ce4",revision:"69075e56ca39f9bc09bcf41c3f79288a2d753989"},cue:{name:"alkove-cue-1-preview",file:"alkove-cue-1-preview.alk",bytes:1199892,sha256:"19e8b6c66ee9ce23bba3b8011f03827c5ba4bb2fe8bec25fe07558a78950190a",revision:"0e1f30380bdfb3201b5d4fd7d9e4197f71f11a60"},spot:{name:"alkove-spot-1-preview",file:"alkove-spot-1-preview.alk",bytes:2774380,sha256:"fef6b59f0c31c5c742db17d758621f778b23cff5a04834e0c6ec47b313d2ce3d",revision:"38a12d1fc87e7ec58f262d5ef729dda64f7ab0e3"},timbre:{name:"alkove-timbre-1",file:"alkove-timbre-1.alk",bytes:970064,sha256:"fc94dfff533f1a4fb2abea172c1f5ff7a92cc00c6331275ea1a26e38f877b0e8",revision:"cb87ad720218e582f114d89b5a6936b9fd3f811a"},lex:{name:"alkove-lex-1-preview",file:"alkove-lex-1-preview.alk",bytes:1818020,sha256:"1e64ca9f5c2281cadae0f9c4a944cd1b1b433f0c0c29760c36340c97f7308957",revision:"9365b7c6aa1555a561548e5198d2becf7f7ffe00"}};var p={name:"alkove-engine",file:"alkove-engine.wasm",bytes:635017,sha256:"03f52bfcfa1bc0b0491a4eb982e08a765e69e3e4ab3801f66349c9b0048d624a"};var i=k;var P=e=>`${i[e].name}@${i[e].sha256.slice(0,12)}`,Z={model:P("timbre"),window:24e3,min:1400,max:32e3,dim:192};var N="alkove",g="https://cache.alkove.invalid/",R=30,l={},O=!1,x=new Set;function M(e){O&&E({code:"config.late",level:"warn",message:"Alkove.configure() after the first input: models already loaded keep their source."}),l={...l,...e}}var U=new Set;function E(e){for(let o of x)o(e);x.size||e.level!=="warn"||U.has(e.code)||(U.add(e.code),console.warn(`alkove: ${e.message??e.code}`,e))}async function C(e){let o=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(o),t=>t.toString(16).padStart(2,"0")).join("")}var B=()=>typeof process<"u"&&!!process.versions?.node&&typeof window>"u",L=()=>typeof caches<"u"&&(typeof isSecureContext>"u"||isSecureContext);function $(e,o){let t=globalThis.location?.href;return new URL(o,new URL(String(e).replace(/\/?$/,"/"),t)).href}function A(e){if(l.modelBaseUrl)return $(l.modelBaseUrl,e.file);if(!e.revision)throw new d("models.fetch",`${e.name}: not on Hugging Face in this version, set modelBaseUrl`);return E({code:"models.default-host",level:"warn",message:`${e.name} comes from Hugging Face: each user sends it their IP. Self-host the models in production (modelBaseUrl).`}),`https://huggingface.co/${m}/${e.name}/resolve/${e.revision}/${e.file}`}async function D(e,o,t=0){let r;try{r=await fetch(e)}catch(f){throw new d("models.fetch",`fetch failed: ${e}`,f)}if(!r.ok||!r.body)throw new d("models.fetch",`HTTP ${r.status}: ${e}`);let a=Number(r.headers.get("content-length"))||t,s=r.body.getReader(),n=[],c=0;for(;;){let{done:f,value:v}=await s.read();if(f)break;n.push(v),c+=v.length,o?.({loaded:c,total:Math.max(a,c)})}let y=new Uint8Array(c),b=0;for(let f of n)y.set(f,b),b+=f.length;return y}async function u(e,o){let t=await C(o);if(t!==e.sha256)throw new d("models.hash",`${e.name}: sha256 ${t}, expected ${e.sha256} (truncated download, or a CDN that rewrites files)`);return o}async function h(e,o,t){return o instanceof ArrayBuffer?u(e,new Uint8Array(o)):o instanceof Uint8Array?u(e,o):u(e,await D(String(o),t,e.bytes))}async function j(e,o){if(!L())return o();let t;try{t=await caches.open(N)}catch{return o()}let r=g+e.sha256,a=await t.match(r).catch(()=>{});if(a){let n=new Uint8Array(await a.arrayBuffer());if(await C(n)===e.sha256)return S(t,e.sha256),n;await t.delete(r).catch(()=>{})}let s=await o();return await t.put(r,new Response(s,{headers:{"content-type":"application/octet-stream"}})).catch(()=>{}),S(t,e.sha256),s}async function S(e,o){try{let t=g+"used.json",r=await(await e.match(t))?.json().catch(()=>null)??{},a=Date.now();r[o]=a;for(let[s,n]of Object.entries(r))a-n>R*864e5&&(await e.delete(g+s),delete r[s]);await e.put(t,new Response(JSON.stringify(r),{headers:{"content-type":"application/json"}}))}catch{}}var H=e=>Object.entries(i).find(([,o])=>o===e)?.[0]??"engine";async function T(e,o,t){let r=l.models?.[H(e)]??t;if(r instanceof ArrayBuffer||r instanceof Uint8Array)return h(e,r);if(B()){if(r&&String(r).startsWith("file:")){let{readFile:s}=await import("node:fs/promises");return u(e,new Uint8Array(await s(new URL(String(r)))))}let a=_(l.modelBaseUrl);if(a){let{readFile:s}=await import("node:fs/promises"),{join:n}=await import("node:path");return u(e,new Uint8Array(await s(n(await a,e.file))))}return h(e,r??A(e),o)}return j(e,()=>h(e,r??A(e),o))}function _(e){if(!e)return null;let o=String(e);return o.startsWith("file:")?import("node:url").then(t=>t.fileURLToPath(o)):/^[a-z][a-z0-9+.-]+:/i.test(o)?null:Promise.resolve(o)}function F(e,o){return T(i[e],o)}var X=`alkove models <dir> [focus cue spot timbre lex]
2
+ import{copyFile as K}from"node:fs/promises";import{dirname as Q,join as R}from"node:path";import{fileURLToPath as V}from"node:url";import{mkdir as B,writeFile as D}from"node:fs/promises";import{join as j}from"node:path";var p="alkove-ai",x={focus:{name:"alkove-focus-1",file:"alkove-focus-1.alk",bytes:2320032,sha256:"25028c1f9faf765ccab4076716b5e8a8e756cd7662babd2bc078951982df5ce4",revision:"bb6db3ecd63f322565c1b625635c762b1a5797cd"},cue:{name:"alkove-cue-1",file:"alkove-cue-1.alk",bytes:1334468,sha256:"b5b7b3e239203eac95bb4510ae7a9c057e79959926dfb64665f46eccc1e4d3de",revision:"0b404bbf29f3480ad7539de8bcbf36ea4b89a5b5"},spot:{name:"alkove-spot-1",file:"alkove-spot-1.alk",bytes:553664,sha256:"946110dd1bd3ff9092d551c1f8d828dbe3e1f0cc9c1e00f63cfe7400ef6e66cd",revision:"18c30629f26ffcfba5987663c144471b23a08945"},"spot-fr":{name:"alkove-spot-1",file:"alkove-spot-1-fr.alk",bytes:339107,sha256:"4a203e4cc5499ff0f1dfa8741058a6313067faa919ea61b9455ee7b2d8be91b4",revision:"18c30629f26ffcfba5987663c144471b23a08945"},"spot-en":{name:"alkove-spot-1",file:"alkove-spot-1-en.alk",bytes:339107,sha256:"52bf84fbed6728cb2a604ad04fa00bc901c720774e6a9c7278bcf48e7e3225c7",revision:"18c30629f26ffcfba5987663c144471b23a08945"},"spot-es":{name:"alkove-spot-1",file:"alkove-spot-1-es.alk",bytes:339107,sha256:"2098eb29c1ada3f2da6254ce083133a3e1e2893fec663479cad0b7ab6081d168",revision:"18c30629f26ffcfba5987663c144471b23a08945"},"spot-pt":{name:"alkove-spot-1",file:"alkove-spot-1-pt.alk",bytes:339107,sha256:"84803c861590c8698214edf4a55a47f58a1c7a518eebf6b4a75511d600866ce9",revision:"18c30629f26ffcfba5987663c144471b23a08945"},"spot-it":{name:"alkove-spot-1",file:"alkove-spot-1-it.alk",bytes:339107,sha256:"573a65d7f96c4bf4a78192530f68cb8776d434e6699e7c3d97e6edf60278803d",revision:"18c30629f26ffcfba5987663c144471b23a08945"},"spot-ca":{name:"alkove-spot-1",file:"alkove-spot-1-ca.alk",bytes:339107,sha256:"1d2adb0ec5855f627cdab8e974cbb67088a1a46189572acdee3d39f0953df1ba",revision:"18c30629f26ffcfba5987663c144471b23a08945"},"spot-ro":{name:"alkove-spot-1",file:"alkove-spot-1-ro.alk",bytes:339107,sha256:"73991a8e2c9e32c9438e64d7715b35af08cee033ae434ed9fe4d6e6b518581e3",revision:"18c30629f26ffcfba5987663c144471b23a08945"},"spot-de":{name:"alkove-spot-1",file:"alkove-spot-1-de.alk",bytes:339107,sha256:"4a3bba1d1a5da91998510c5dd7fdf7800390825f24ea33edadd433ede81722bf",revision:"18c30629f26ffcfba5987663c144471b23a08945"},"spot-nl":{name:"alkove-spot-1",file:"alkove-spot-1-nl.alk",bytes:339107,sha256:"717ecc565d224254ce43a6fddfc259c7b3099011f10ef20af29c4b925cf67285",revision:"18c30629f26ffcfba5987663c144471b23a08945"},"spot-pl":{name:"alkove-spot-1",file:"alkove-spot-1-pl.alk",bytes:339107,sha256:"891cb9c5596876975c2ea7b7023ac94c4c4972b6441cca902925eb31dcf6038a",revision:"18c30629f26ffcfba5987663c144471b23a08945"},"spot-sv":{name:"alkove-spot-1",file:"alkove-spot-1-sv.alk",bytes:339107,sha256:"fdbe462b8fca971c90f727c3494286ad849a914d9271903be818a35040b72f5e",revision:"18c30629f26ffcfba5987663c144471b23a08945"},"spot-lang":{name:"alkove-spot-1",file:"alkove-spot-1-lang.alk",bytes:264161,sha256:"69b8bbb2d788c54056eefbf534d8fc2dab1e1215684a1a8dc3a5fdbaae6f147b",revision:"18c30629f26ffcfba5987663c144471b23a08945"},timbre:{name:"alkove-timbre-1",file:"alkove-timbre-1.alk",bytes:970064,sha256:"fc94dfff533f1a4fb2abea172c1f5ff7a92cc00c6331275ea1a26e38f877b0e8",revision:"c4770d4575c7e37306708351b18b39fb211b2c14"},"lex-fr":{name:"alkove-lex-1",file:"alkove-lex-1-fr.alk",bytes:1252088,sha256:"280f64fa48509f44893ec13a7000ebf321c54fd4d732f0bffd173777bc8847b5",revision:"df4cac7735c505b5506e245a97d50cf204af1eb1"},"lex-en":{name:"alkove-lex-1",file:"alkove-lex-1-en.alk",bytes:1465760,sha256:"37029e330b7afc3984784a39e4577f6a0e0cb33037adb8070cbd283d06cbabe0",revision:"df4cac7735c505b5506e245a97d50cf204af1eb1"},"lex-es":{name:"alkove-lex-1",file:"alkove-lex-1-es.alk",bytes:386680,sha256:"01ba0aeb04b7d4cfe216e620d65f009849ef4ab841f8ce98b9a20e35df07dcf1",revision:"df4cac7735c505b5506e245a97d50cf204af1eb1"},"lex-pt":{name:"alkove-lex-1",file:"alkove-lex-1-pt.alk",bytes:1470971,sha256:"1af83d0d607c16972e05c990ea7c803ce614a6df4ea93a001cbc55748c4a4c85",revision:"df4cac7735c505b5506e245a97d50cf204af1eb1"},"lex-it":{name:"alkove-lex-1",file:"alkove-lex-1-it.alk",bytes:1190010,sha256:"0a88b0616927675f588ae7a81a3b25813a642d10534ff5dc475d796c57e7387b",revision:"df4cac7735c505b5506e245a97d50cf204af1eb1"},"lex-ca":{name:"alkove-lex-1",file:"alkove-lex-1-ca.alk",bytes:1157080,sha256:"4b6f0bb9dcbadfd0efaf4065acde4b974b59e5502f1ecd8818332d0189253b8a",revision:"df4cac7735c505b5506e245a97d50cf204af1eb1"},"lex-ro":{name:"alkove-lex-1",file:"alkove-lex-1-ro.alk",bytes:369425,sha256:"6c49c0bfb3b9ac55f6483b0ec0e05cd62ba975a32923dff794a4a76a0dfa7d45",revision:"df4cac7735c505b5506e245a97d50cf204af1eb1"},"lex-de":{name:"alkove-lex-1",file:"alkove-lex-1-de.alk",bytes:1356248,sha256:"64ed6add4fb369f1b1a9a43c1028d570d1ae740e37a2163417bbe6d9fa997d88",revision:"df4cac7735c505b5506e245a97d50cf204af1eb1"},"lex-nl":{name:"alkove-lex-1",file:"alkove-lex-1-nl.alk",bytes:1147472,sha256:"5e05ffd8ac66047cd1049dc1aa98c1b9ef086eb94fc575eb8440a5beef1db683",revision:"df4cac7735c505b5506e245a97d50cf204af1eb1"},"lex-pl":{name:"alkove-lex-1",file:"alkove-lex-1-pl.alk",bytes:395038,sha256:"f4250c033c1555d8076bd7b15884741accde3f88a751ae44f08972de88e89de4",revision:"df4cac7735c505b5506e245a97d50cf204af1eb1"},"lex-sv":{name:"alkove-lex-1",file:"alkove-lex-1-sv.alk",bytes:1171030,sha256:"58fd5c019711e2604f204618d79bd0c744bb31acda6af45cd758699a7b945f56",revision:"df4cac7735c505b5506e245a97d50cf204af1eb1"}};var m={name:"alkove-engine",file:"alkove-engine.wasm",bytes:799946,sha256:"a570ec034cdb4f0cccb7e7a0ca9d0f47e3094adee056b73cee02b1d71d341ed9"};var c=x;var O=e=>`${c[e].name}@${c[e].sha256.slice(0,12)}`,se={model:O("timbre"),window:24e3,min:1400,max:32e3,dim:192},u={langs:["fr","en","es","pt","it","ca","ro","de","nl","pl","sv"],beams:3,bos:66,eos:67,vocab:68,word:33,steps:39},w=e=>["cue","spot",...e.map(a=>`spot-${a}`),...new Set(e).size>1?["spot-lang"]:[]],U=e=>e.map(a=>`lex-${a}`);function M(e){let a=new Set;for(let o of e.length?e:Object.keys(c))if(o==="spot")for(let t of w(u.langs))a.add(t);else if(o==="lex")for(let t of U(u.langs))a.add(t);else if(o in c)o.startsWith("spot-")&&a.add("cue").add("spot"),a.add(o),o==="focus"&&a.add("timbre");else throw new Error(`unknown model ${o}`);return[...a].filter(o=>o.startsWith("spot-")&&o!=="spot-lang").length>1&&a.add("spot-lang"),[...a]}async function A(e,a,o,t=console.log){await B(e,{recursive:!0});for(let s of a){let n=await o(s);await D(j(e,c[s].file),n),t(`${c[s].file} ${(n.length/1e6).toFixed(2)} MB sha256 ok`)}}var i=class extends Error{constructor(o,t,s){super(t);this.code=o;this.cause=s}name="AlkoveError"};var H="alkove",h="https://cache.alkove.invalid/",T=30,l={},_=!1,S=new Set;function C(e){_&&P({code:"config.late",level:"warn",message:"Alkove.configure() after the first input: models already loaded keep their source."}),l={...l,...e}}var N=new Set;function P(e){for(let a of S)a(e);S.size||e.level!=="warn"||N.has(e.code)||(N.add(e.code),console.warn(`alkove: ${e.message??e.code}`,e))}async function L(e){let a=await crypto.subtle.digest("SHA-256",e);return Array.from(new Uint8Array(a),o=>o.toString(16).padStart(2,"0")).join("")}var G=()=>typeof process<"u"&&!!process.versions?.node&&typeof window>"u",W=()=>typeof caches<"u"&&(typeof isSecureContext>"u"||isSecureContext);function I(e,a){let o=globalThis.location?.href;return new URL(a,new URL(String(e).replace(/\/?$/,"/"),o)).href}function E(e){if(l.modelBaseUrl)return I(l.modelBaseUrl,e.file);if(!e.revision)throw new i("models.fetch",`${e.name}: not on Hugging Face in this version, set modelBaseUrl`);return P({code:"models.default-host",level:"warn",message:`${e.name} comes from Hugging Face: each user sends it their IP. Self-host the models in production (modelBaseUrl).`}),`https://huggingface.co/${p}/${e.name}/resolve/${e.revision}/${e.file}`}async function z(e,a,o=0){let t;try{t=await fetch(e)}catch(f){throw new i("models.fetch",`fetch failed: ${e}`,f)}if(!t.ok||!t.body)throw new i("models.fetch",`HTTP ${t.status}: ${e}`);let s=Number(t.headers.get("content-length"))||o,n=t.body.getReader(),r=[],b=0;for(;;){let{done:f,value:y}=await n.read();if(f)break;r.push(y),b+=y.length,a?.({loaded:b,total:Math.max(s,b)})}let g=new Uint8Array(b),k=0;for(let f of r)g.set(f,k),k+=f.length;return g}async function d(e,a){let o=await L(a);if(o!==e.sha256)throw new i("models.hash",`${e.name}: sha256 ${o}, expected ${e.sha256} (truncated download, or a CDN that rewrites files)`);return a}async function v(e,a,o){return a instanceof ArrayBuffer?d(e,new Uint8Array(a)):a instanceof Uint8Array?d(e,a):d(e,await z(String(a),o,e.bytes))}async function J(e,a){if(!W())return a();let o;try{o=await caches.open(H)}catch{return a()}let t=h+e.sha256,s=await o.match(t).catch(()=>{});if(s){let r=new Uint8Array(await s.arrayBuffer());if(await L(r)===e.sha256)return F(o,e.sha256),r;await o.delete(t).catch(()=>{})}let n=await a();return await o.put(t,new Response(n,{headers:{"content-type":"application/octet-stream"}})).catch(()=>{}),F(o,e.sha256),n}async function F(e,a){try{let o=h+"used.json",t=await(await e.match(o))?.json().catch(()=>null)??{},s=Date.now();t[a]=s;for(let[n,r]of Object.entries(t))s-r>T*864e5&&(await e.delete(h+n),delete t[n]);await e.put(o,new Response(JSON.stringify(t),{headers:{"content-type":"application/json"}}))}catch{}}var X=e=>Object.entries(c).find(([,a])=>a===e)?.[0]??"engine";async function Y(e,a,o){let t=l.models?.[X(e)]??o;if(t instanceof ArrayBuffer||t instanceof Uint8Array)return v(e,t);if(G()){if(t&&String(t).startsWith("file:")){let{readFile:n}=await import("node:fs/promises");return d(e,new Uint8Array(await n(new URL(String(t)))))}let s=q(l.modelBaseUrl);if(s){let{readFile:n}=await import("node:fs/promises"),{join:r}=await import("node:path");return d(e,new Uint8Array(await n(r(await s,e.file))))}return v(e,t??E(e),a)}return J(e,()=>v(e,t??E(e),a))}function q(e){if(!e)return null;let a=String(e);return a.startsWith("file:")?import("node:url").then(o=>o.fileURLToPath(a)):/^[a-z][a-z0-9+.-]+:/i.test(a)?null:Promise.resolve(a)}function $(e,a){return Y(c[e],a)}var Z=`alkove models <dir> [focus cue spot timbre lex | spot-<lang> lex-<lang>]
3
3
 
4
4
  Copies what the installed version of alkove loads into <dir>, for self-hosting:
5
5
  the models (downloaded from Hugging Face at the pinned revision, sha256 checked),
6
- alkove-engine.wasm, alkove-worker.js and alkove-worklet.js.
6
+ alkove-engine.wasm, alkove-worker.js and alkove-worklet.js. spot brings Cue and
7
+ every language's top, lex every language; spot-fr brings Cue, Spot's bottom and
8
+ French only, a second spot-<lang> the language head, focus brings Timbre.
7
9
 
8
- Then: Alkove.configure({ modelBaseUrl: '/<dir>/', assetBaseUrl: '/<dir>/' })`;async function Y(e){let[o,t,...r]=e;if(o!=="models"||!t){console.log(X),process.exitCode=o?1:0;return}let a=r.length?r:Object.keys(i);a.includes("focus")&&!a.includes("timbre")&&a.push("timbre");for(let n of a)if(!(n in i))throw new Error(`unknown model ${n}`);await I(t,{recursive:!0}),M({});for(let n of a){let c=await F(n);await W(w(t,i[n].file),c),console.log(`${i[n].file} ${(c.length/1e6).toFixed(2)} MB sha256 ok`)}let s=z(J(import.meta.url));for(let n of[p.file,"alkove-worker.js","alkove-worklet.js"])await G(w(s,n),w(t,n)),console.log(n)}Y(process.argv.slice(2)).catch(e=>{console.error(String(e?.message??e)),process.exitCode=1});
10
+ Then: Alkove.configure({ modelBaseUrl: '/<dir>/', assetBaseUrl: '/<dir>/' })`;async function ee(e){let[a,o,...t]=e;if(a!=="models"||!o){console.log(Z),process.exitCode=a?1:0;return}let s=M(t);C({}),await A(o,s,$);let n=Q(V(import.meta.url));for(let r of[m.file,"alkove-worker.js","alkove-worklet.js"])await K(R(n,r),R(o,r)),console.log(r)}ee(process.argv.slice(2)).catch(e=>{console.error(String(e?.message??e)),process.exitCode=1});
@@ -0,0 +1,7 @@
1
+ import { type ModelName } from './manifest';
2
+ export declare function modelsFor(names: readonly string[]): ModelName[];
3
+ export declare function copyModels(dir: string, names: readonly ModelName[], load: (n: ModelName) => Promise<Uint8Array>, log?: {
4
+ (...data: any[]): void;
5
+ (...data: any[]): void;
6
+ (message?: any, ...optionalParams: any[]): void;
7
+ }): Promise<void>;
@@ -19,6 +19,7 @@ export interface ChainOptions {
19
19
  sample?: ArrayLike<number> | null;
20
20
  speech?: Partial<SpeechParams>;
21
21
  sleep?: boolean;
22
+ lowPower?: boolean;
22
23
  }
23
24
  export declare class Chain {
24
25
  private alk;
@@ -1,8 +1,8 @@
1
1
  import type { Alk, Model, Tensor } from '../engine/alk';
2
- import type { ModelName } from '../manifest';
2
+ import type { Lang, ModelName } from '../manifest';
3
3
  import { Chain, type ChainOptions } from './chain';
4
- import { NativeCoach, NativeEnroller, NativeLearner, NativeLex, NativeListener, NativePipeline, NativeProcessor, NativeTimbre, type Value } from './native';
5
- export type StreamModel = 'focus' | 'cue' | 'spot';
4
+ import { NativeCoach, NativeEnroller, NativeLearner, NativeLex, NativeListener, NativePipeline, NativeProcessor, NativeSpot, NativeTimbre, type Value } from './native';
5
+ export type StreamModel = 'focus' | 'cue';
6
6
  export interface StreamNet {
7
7
  f32(name: string): Float32Array;
8
8
  run(): void;
@@ -15,20 +15,23 @@ export interface Net {
15
15
  }
16
16
  export interface Engine {
17
17
  stream(model: StreamModel): StreamNet;
18
- net(model: 'timbre' | 'lex', plan?: string): Net;
18
+ net(model: 'timbre', plan?: string): Net;
19
19
  chain(opts?: ChainOptions): Chain;
20
20
  processor(options: {
21
21
  focus: unknown;
22
22
  cue: boolean | null;
23
23
  spot: unknown;
24
24
  }): NativeProcessor;
25
+ recordingPrint(pcm: Float32Array, options: Value): number[] | null;
25
26
  listener(words: Value[], context: string): NativeListener;
26
27
  enroller(word: Value, takes: number, chain: string): NativeEnroller;
27
- lex(): NativeLex;
28
+ lex(langs: readonly Lang[]): NativeLex;
29
+ spot(langs: readonly Lang[], heard?: readonly Lang[]): NativeSpot;
28
30
  compile(text: string, lang: string[], chain?: string): {
29
31
  word: Value;
30
32
  warnings: Value[];
31
33
  };
34
+ commands(spec: unknown, langs: readonly Lang[]): Value[];
32
35
  timbre(): NativeTimbre;
33
36
  learner(source: string, start: Value): NativeLearner;
34
37
  pipeline(options: {
@@ -46,10 +49,13 @@ export declare class WasmEngine implements Engine {
46
49
  private models;
47
50
  private calls;
48
51
  private lexer;
52
+ private spotter;
53
+ private bare;
49
54
  private voices;
50
55
  constructor(alk: Alk, bytes: (model: ModelName) => Uint8Array);
51
56
  has(model: ModelName): boolean;
52
57
  model(name: ModelName): Model;
58
+ private langModel;
53
59
  stream(model: StreamModel): StreamNet;
54
60
  chain(opts?: ChainOptions): Chain;
55
61
  processor(options: {
@@ -57,9 +63,14 @@ export declare class WasmEngine implements Engine {
57
63
  cue: boolean | null;
58
64
  spot: unknown;
59
65
  }): NativeProcessor;
66
+ recordingPrint(pcm: Float32Array, options: Value): number[] | null;
60
67
  listener(words: Value[], context: string): NativeListener;
61
68
  enroller(word: Value, takes: number, chain: string): NativeEnroller;
62
- lex(): NativeLex;
69
+ lex(langs: readonly Lang[]): NativeLex;
70
+ spot(langs: readonly Lang[], heard?: readonly Lang[]): NativeSpot;
71
+ private bareSpot;
72
+ private tops;
73
+ private sent;
63
74
  timbre(): NativeTimbre;
64
75
  learner(source: string, start: Value): NativeLearner;
65
76
  pipeline(options: {
@@ -74,6 +85,7 @@ export declare class WasmEngine implements Engine {
74
85
  word: Value;
75
86
  warnings: Value[];
76
87
  };
77
- net(model: 'timbre' | 'lex', plan?: string): Net;
88
+ commands(spec: unknown, langs: readonly Lang[]): Value[];
89
+ net(model: 'timbre', plan?: string): Net;
78
90
  release(): void;
79
91
  }
@@ -9,7 +9,7 @@ export interface Warning {
9
9
  [key: string]: unknown;
10
10
  }
11
11
  export declare class Lex {
12
- static readonly langs: readonly ["fr", "en", "es", "pt", "it", "ca", "ro"];
12
+ static readonly langs: readonly ["fr", "en", "es", "pt", "it", "ca", "ro", "de", "nl", "pl", "sv"];
13
13
  static readonly inventory: string[];
14
14
  static distance(a: string | number[], b: string | number[]): number;
15
15
  }
@@ -17,19 +17,35 @@ export declare class NativeLex {
17
17
  constructor(alk: Alk, model: Model);
18
18
  get handle(): number;
19
19
  phonemize(texts: string[], lang: string): NativePronunciation[][];
20
+ add(model: Model): void;
21
+ release(): void;
22
+ }
23
+ export declare class NativeSpot {
24
+ private alk;
25
+ private ptr;
26
+ readonly langs: string[];
27
+ readonly all: string[];
28
+ head: boolean;
29
+ constructor(alk: Alk, cue: Model, bottom: Model);
30
+ get handle(): number;
31
+ add(top: Model): string;
32
+ addLangs(langs: readonly string[]): void;
33
+ setLang(head: Model): void;
20
34
  release(): void;
21
35
  }
22
36
  export declare function compileNative(alk: Alk, lex: NativeLex | null, text: string, lang: string[], chain?: string): {
23
37
  word: Value;
24
38
  warnings: Value[];
25
39
  };
40
+ export declare function compileCommandsNative(alk: Alk, lex: NativeLex, spec: unknown, langs: string[]): Value[];
41
+ export declare function recordingPrint(alk: Alk, focus: Model, cue: Model, timbre: Model, pcm: Float32Array, options: Value): number[] | null;
26
42
  export declare class NativeProcessor {
27
43
  private alk;
28
44
  private ptr;
29
45
  constructor(alk: Alk, models: {
30
46
  focus?: Model;
31
47
  cue?: Model;
32
- spot?: Model;
48
+ spot?: NativeSpot;
33
49
  timbre?: Model;
34
50
  }, options: Value);
35
51
  private part;
@@ -41,7 +57,7 @@ export type HeardFrame = [number, number | null, number[], Record<string, unknow
41
57
  export declare class NativeListener {
42
58
  private alk;
43
59
  private ptr;
44
- constructor(alk: Alk, spot: Model, words: Value[], context: string);
60
+ constructor(alk: Alk, spot: NativeSpot, words: Value[], context: string);
45
61
  setWords(words: Value[], context: string): void;
46
62
  push(pcm: Float32Array): HeardFrame[];
47
63
  release(): void;
@@ -49,7 +65,7 @@ export declare class NativeListener {
49
65
  export declare class NativeEnroller {
50
66
  private alk;
51
67
  private ptr;
52
- constructor(alk: Alk, spot: Model, word: Value, takes: number, chain: string);
68
+ constructor(alk: Alk, spot: NativeSpot, word: Value, takes: number, chain: string);
53
69
  push(pcm: Float32Array): {
54
70
  takes: Record<string, unknown>[];
55
71
  done: boolean;
@@ -110,10 +126,11 @@ export declare class NativePipeline {
110
126
  constructor(alk: Alk, models: {
111
127
  focus?: Model;
112
128
  cue?: Model;
113
- spot?: Model;
129
+ spot?: NativeSpot;
114
130
  }, options: Value);
115
131
  step(hop: Float32Array, farQuietMs: number): Float32Array;
116
- spot(model: Model): void;
132
+ spent(ms: number): void;
133
+ spot(s: NativeSpot): void;
117
134
  timbre(model: Model): void;
118
135
  raw(hop: Float32Array): void;
119
136
  outs(): PipelineOut[];
@@ -43,6 +43,7 @@ export declare class Word {
43
43
  static fromJSON(json: WordJSON | string): Word | null;
44
44
  }
45
45
  export declare const wordOf: (w: Word | WordJSON | string) => Word;
46
+ export declare function searchLangs(words: readonly unknown[]): Lang[];
46
47
  export interface CompileOptions {
47
48
  lang?: Lang | Lang[];
48
49
  }
@@ -63,3 +64,42 @@ export interface WakeEvent {
63
64
  audio?: Float32Array;
64
65
  voice?: number;
65
66
  }
67
+ export interface CommandSpec {
68
+ commands: {
69
+ id: string;
70
+ phrases: string[] | Partial<Record<Lang, string[]>>;
71
+ }[];
72
+ lists?: Record<string, string[] | Partial<Record<Lang, string[]>>>;
73
+ }
74
+ export interface CommandsJSON {
75
+ alkove: 'commands';
76
+ lang: Lang;
77
+ commands: {
78
+ id: string;
79
+ phrases: {
80
+ text: string;
81
+ slots: {
82
+ name: string;
83
+ value: string;
84
+ number?: number;
85
+ }[];
86
+ readings: string[];
87
+ }[];
88
+ }[];
89
+ }
90
+ export interface CommandEvent {
91
+ id: string;
92
+ phrase: string;
93
+ slots: Record<string, string | number>;
94
+ score: number;
95
+ gap: number;
96
+ lang: Lang;
97
+ start: number;
98
+ end: number;
99
+ }
100
+ export interface LanguageEvent {
101
+ lang: Lang;
102
+ p: number;
103
+ start: number;
104
+ end: number;
105
+ }
@@ -18,7 +18,7 @@ export interface AlkExports {
18
18
  alk_io_count(m: number, plan: number, kind: number): number;
19
19
  alk_io_name(m: number, plan: number, kind: number, i: number, out: number, cap: number): number;
20
20
  alk_io_shape(m: number, plan: number, kind: number, i: number, dims: number, cap: number): number;
21
- alk_chain(focus: number, cue: number, gate: number, normalize: number, sleep: number, strength: number, confidence: number, exitConfidence: number, startSecs: number, stopSecs: number, print: number, printLen: number): number;
21
+ alk_chain(focus: number, cue: number, gate: number, normalize: number, sleep: number, strength: number, confidence: number, exitConfidence: number, startSecs: number, stopSecs: number, print: number, printLen: number, lowPower: number): number;
22
22
  alk_chain_free(c: number): void;
23
23
  alk_chain_hop(c: number): number;
24
24
  alk_chain_step(c: number): number;
@@ -35,18 +35,26 @@ export interface AlkExports {
35
35
  alk_lex(m: number): number;
36
36
  alk_lex_free(l: number): void;
37
37
  alk_lex_phonemize(l: number): number;
38
+ alk_lex_add(l: number, m: number): number;
39
+ alk_spot(cue: number, bottom: number): number;
40
+ alk_spot_free(s: number): void;
41
+ alk_spot_add(s: number, m: number): number;
42
+ alk_spot_lang(s: number, m: number): number;
43
+ alk_spot_langs(s: number): number;
44
+ alk_commands(l: number): number;
38
45
  alk_compile(l: number): number;
39
46
  alk_processor(focus: number, cue: number, spot: number, timbre: number): number;
47
+ alk_recording_print(focus: number, cue: number, timbre: number, x: number, len: number): number;
40
48
  alk_processor_free(p: number): void;
41
49
  alk_processor_push(p: number, pcm: number, len: number): number;
42
50
  alk_processor_end(p: number): number;
43
51
  alk_processor_audio(p: number): number;
44
52
  alk_processor_audio_len(p: number): number;
45
- alk_listener(m: number): number;
53
+ alk_listener(s: number): number;
46
54
  alk_listener_free(l: number): void;
47
55
  alk_listener_words(l: number): number;
48
56
  alk_listener_push(l: number, pcm: number, len: number): number;
49
- alk_enroller(m: number): number;
57
+ alk_enroller(s: number): number;
50
58
  alk_enroller_free(e: number): void;
51
59
  alk_enroller_push(e: number, pcm: number, len: number): number;
52
60
  alk_enroller_result(e: number): number;
@@ -67,7 +75,8 @@ export interface AlkExports {
67
75
  alk_pipeline_hop(p: number): number;
68
76
  alk_pipeline_step(p: number, farQuietMs: number): number;
69
77
  alk_pipeline_raw(p: number): void;
70
- alk_pipeline_spot(p: number, m: number): void;
78
+ alk_pipeline_spent(p: number, ms: number): void;
79
+ alk_pipeline_spot(p: number, s: number): number;
71
80
  alk_pipeline_timbre(p: number, m: number): number;
72
81
  alk_pipeline_outs(p: number): number;
73
82
  alk_pipeline_pending(p: number): number;
package/dist/errors.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type ErrorCode = 'mic.denied' | 'mic.not-found' | 'mic.busy' | 'page.insecure' | 'browser.unsupported' | 'models.fetch' | 'models.hash' | 'engine.failed' | 'lang.unsupported' | 'word.outdated';
1
+ export type ErrorCode = 'mic.denied' | 'mic.not-found' | 'mic.busy' | 'page.insecure' | 'browser.unsupported' | 'models.fetch' | 'models.hash' | 'models.missing' | 'engine.failed' | 'lang.unsupported' | 'word.outdated';
2
2
  export declare class AlkoveError extends Error {
3
3
  readonly code: ErrorCode;
4
4
  readonly cause?: unknown | undefined;
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export type { Enrollment } from './recipes/enroll';
4
4
  export type { Take } from './core/spot/spot';
5
5
  export type { SpeechParams, TurnOptions } from './core/cue';
6
6
  export type { Pronunciation, Warning } from './core/lex';
7
- export type { Context, Thresholds, WakeEvent, Word, WordJSON } from './core/spot/spot';
7
+ export type { CommandEvent, CommandSpec, CommandsJSON, Context, LanguageEvent, Thresholds, WakeEvent, Word, WordJSON } from './core/spot/spot';
8
8
  export { Voiceprint } from './core/timbre';
9
9
  export type { Level, VoiceprintJSON } from './core/timbre';
10
10
  export { AlkoveError } from './errors';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as n,b as s,c as a,f as i,g as c}from"./chunk-LB4OLDBE.js";import{f as o,g as t,h as p}from"./chunk-BWNLE4ZO.js";import{i as e,n as r}from"./chunk-SSJ7CLCP.js";export{n as Alkove,e as AlkoveError,a as Lex,i as Spot,s as Timbre,r as Voiceprint,c as VoiceprintLearner,t as createAgentInput,o as createCallInput,p as createWakeListener};
1
+ import{b as n,c as s,d as a,h as m,i}from"./chunk-N4S2422Z.js";import{f as o,g as t,h as p}from"./chunk-C5QG5BVR.js";import{k as e,q as r}from"./chunk-2PTYZFLZ.js";export{n as Alkove,e as AlkoveError,a as Lex,m as Spot,s as Timbre,r as Voiceprint,i as VoiceprintLearner,t as createAgentInput,o as createCallInput,p as createWakeListener};
@@ -1,6 +1,6 @@
1
1
  export { ENGINE_WASM } from './engine.generated';
2
2
  export { HF_ORG } from './models.generated';
3
- export type ModelName = 'focus' | 'cue' | 'spot' | 'timbre' | 'lex';
3
+ export type ModelName = 'focus' | 'cue' | 'spot' | 'spot-lang' | 'timbre' | `spot-${Lang}` | `lex-${Lang}`;
4
4
  export interface ModelFile {
5
5
  name: string;
6
6
  file: string;
@@ -35,7 +35,7 @@ export declare const TIMBRE: {
35
35
  dim: number;
36
36
  };
37
37
  export declare const LEX: {
38
- langs: readonly ["fr", "en", "es", "pt", "it", "ca", "ro"];
38
+ langs: readonly ["fr", "en", "es", "pt", "it", "ca", "ro", "de", "nl", "pl", "sv"];
39
39
  beams: number;
40
40
  bos: number;
41
41
  eos: number;
@@ -44,3 +44,5 @@ export declare const LEX: {
44
44
  steps: number;
45
45
  };
46
46
  export type Lang = (typeof LEX.langs)[number];
47
+ export declare const spotModels: (langs: readonly Lang[]) => ModelName[];
48
+ export declare const lexModels: (langs: readonly Lang[]) => ModelName[];
@@ -21,6 +21,90 @@ export declare const MODELS_JSON: {
21
21
  sha256: string;
22
22
  revision: string;
23
23
  };
24
+ 'spot-fr': {
25
+ name: string;
26
+ file: string;
27
+ bytes: number;
28
+ sha256: string;
29
+ revision: string;
30
+ };
31
+ 'spot-en': {
32
+ name: string;
33
+ file: string;
34
+ bytes: number;
35
+ sha256: string;
36
+ revision: string;
37
+ };
38
+ 'spot-es': {
39
+ name: string;
40
+ file: string;
41
+ bytes: number;
42
+ sha256: string;
43
+ revision: string;
44
+ };
45
+ 'spot-pt': {
46
+ name: string;
47
+ file: string;
48
+ bytes: number;
49
+ sha256: string;
50
+ revision: string;
51
+ };
52
+ 'spot-it': {
53
+ name: string;
54
+ file: string;
55
+ bytes: number;
56
+ sha256: string;
57
+ revision: string;
58
+ };
59
+ 'spot-ca': {
60
+ name: string;
61
+ file: string;
62
+ bytes: number;
63
+ sha256: string;
64
+ revision: string;
65
+ };
66
+ 'spot-ro': {
67
+ name: string;
68
+ file: string;
69
+ bytes: number;
70
+ sha256: string;
71
+ revision: string;
72
+ };
73
+ 'spot-de': {
74
+ name: string;
75
+ file: string;
76
+ bytes: number;
77
+ sha256: string;
78
+ revision: string;
79
+ };
80
+ 'spot-nl': {
81
+ name: string;
82
+ file: string;
83
+ bytes: number;
84
+ sha256: string;
85
+ revision: string;
86
+ };
87
+ 'spot-pl': {
88
+ name: string;
89
+ file: string;
90
+ bytes: number;
91
+ sha256: string;
92
+ revision: string;
93
+ };
94
+ 'spot-sv': {
95
+ name: string;
96
+ file: string;
97
+ bytes: number;
98
+ sha256: string;
99
+ revision: string;
100
+ };
101
+ 'spot-lang': {
102
+ name: string;
103
+ file: string;
104
+ bytes: number;
105
+ sha256: string;
106
+ revision: string;
107
+ };
24
108
  timbre: {
25
109
  name: string;
26
110
  file: string;
@@ -28,7 +112,77 @@ export declare const MODELS_JSON: {
28
112
  sha256: string;
29
113
  revision: string;
30
114
  };
31
- lex: {
115
+ 'lex-fr': {
116
+ name: string;
117
+ file: string;
118
+ bytes: number;
119
+ sha256: string;
120
+ revision: string;
121
+ };
122
+ 'lex-en': {
123
+ name: string;
124
+ file: string;
125
+ bytes: number;
126
+ sha256: string;
127
+ revision: string;
128
+ };
129
+ 'lex-es': {
130
+ name: string;
131
+ file: string;
132
+ bytes: number;
133
+ sha256: string;
134
+ revision: string;
135
+ };
136
+ 'lex-pt': {
137
+ name: string;
138
+ file: string;
139
+ bytes: number;
140
+ sha256: string;
141
+ revision: string;
142
+ };
143
+ 'lex-it': {
144
+ name: string;
145
+ file: string;
146
+ bytes: number;
147
+ sha256: string;
148
+ revision: string;
149
+ };
150
+ 'lex-ca': {
151
+ name: string;
152
+ file: string;
153
+ bytes: number;
154
+ sha256: string;
155
+ revision: string;
156
+ };
157
+ 'lex-ro': {
158
+ name: string;
159
+ file: string;
160
+ bytes: number;
161
+ sha256: string;
162
+ revision: string;
163
+ };
164
+ 'lex-de': {
165
+ name: string;
166
+ file: string;
167
+ bytes: number;
168
+ sha256: string;
169
+ revision: string;
170
+ };
171
+ 'lex-nl': {
172
+ name: string;
173
+ file: string;
174
+ bytes: number;
175
+ sha256: string;
176
+ revision: string;
177
+ };
178
+ 'lex-pl': {
179
+ name: string;
180
+ file: string;
181
+ bytes: number;
182
+ sha256: string;
183
+ revision: string;
184
+ };
185
+ 'lex-sv': {
32
186
  name: string;
33
187
  file: string;
34
188
  bytes: number;
@@ -0,0 +1 @@
1
+ import{A as W,B as H,H as j,I as B,a as $,d as D,k as v,n as y,z as I}from"./chunk-2PTYZFLZ.js";var x=class{constructor(e){this.size=e;this.buf=new Float32Array(e)}buf;fill=0;push(e,r){let t=0;for(;t<e.length;){let n=Math.min(this.size-this.fill,e.length-t);this.buf.set(e.subarray(t,t+n),this.fill),this.fill+=n,t+=n,this.fill===this.size&&(this.fill=0,r(this.buf))}}get pending(){return this.fill}reset(){this.fill=0}};var k=D.chunk,re=["silence","forced","wake"],J=i=>new Uint8Array(i.buffer,i.byteOffset,i.byteLength),A=class{constructor(e,r,t,n={}){this.alk=e;let a={gate:!1,normalize:!0,strength:1,sleep:!0,...n},s={...H,...n.speech},o=n.lowPower===void 0?-1:+n.lowPower,m=(c,u)=>e.x.alk_chain(r.ptr,t.ptr,+a.gate,+a.normalize,+a.sleep,a.strength,s.confidence,s.exitConfidence,s.startSecs,s.stopSecs,c,u,o),h=n.print?Float32Array.from(n.print):null;this.ptr=h?e.with(J(h),c=>m(c,h.length)):m(0,0),this.ptr||e.fail("chain"),this.delay=e.x.alk_chain_get(this.ptr,4)}delay;ptr;hops=new x(k);mix=new Float32Array(k);focusOut=new Float32Array(k);onFocus=null;onCue=null;get speaking(){return this.alk.x.alk_chain_get(this.ptr,0)===1}get sleeping(){return this.alk.x.alk_chain_get(this.ptr,1)===1}get time(){return this.alk.x.alk_chain_get(this.ptr,2)}get gainDb(){return this.alk.x.alk_chain_get(this.ptr,3)}release(){this.ptr&&this.alk.x.alk_chain_free(this.ptr),this.ptr=0}setPrint(e){let r=this.alk.x;if(!e)r.alk_chain_print(this.ptr,0,0);else{let t=Float32Array.from(e);this.alk.with(J(t),n=>r.alk_chain_print(this.ptr,n,t.length))<0&&this.alk.fail("print")}}setStrength(e){this.alk.x.alk_chain_strength(this.ptr,e)}setEnabled(e){this.alk.x.alk_chain_enabled(this.ptr,+e)}step(e,r){if(this.hops.pending||e.length!==k)throw new RangeError("step() takes whole hops only");return this.hop(e,r)}push(e,r){let t=new Float32Array(Math.floor((this.hops.pending+e.length)/k)*k),n=0;return this.hops.push(e,a=>{t.set(this.hop(a,r),n),n+=k}),t}hop(e,r){let{alk:t,ptr:n}=this,a=t.x;new Float32Array(t.heap,a.alk_chain_hop(n),k).set(e);let s=a.alk_chain_step(n);this.mix.set(new Float32Array(t.heap,s,k));let o=new Float64Array(t.heap,a.alk_chain_events(n),4*a.alk_chain_event_count(n)).slice();for(let m=0;m<o.length;m+=4){let[h,c,u]=[o[m+1],o[m+2],o[m+3]];switch(o[m]){case 0:r({type:"speechstart",start:h});break;case 1:r({type:"speechend",start:h,end:c});break;case 2:r({type:"idle",asleep:h===1,at:c});break;case 3:r({type:"diag",code:"focus.print",level:"info",data:{print:h===1,after:c,why:re[u]}});break;case 5:this.onFocus&&(this.focusOut.set(new Float32Array(t.heap,a.alk_chain_focus(n),k)),this.onFocus(this.focusOut,h));break;case 6:this.onCue?.(h,c);break;case 10:r({type:"diag",code:"focus.mode",level:h===1&&c===1?"info":"warn",data:{focus:h===1,separator:c===1,threads:u}})}}return this.mix}};var te=new TextEncoder,ne=new TextDecoder;function ae(i){let e=[],r=[],t=0,n=()=>{e.length&&(r.push(Uint8Array.from(e)),t+=e.length,e.length=0)},a=u=>{n(),r.push(u),t+=u.length},s=u=>e.push(u&255,u>>>8&255,u>>>16&255,u>>>24),o=u=>{let d=te.encode(u);s(d.length),a(d)},m=u=>{if(u==null)e.push(0);else if(typeof u=="boolean")e.push(u?2:1);else if(typeof u=="number")e.push(3),a(new Uint8Array(Float64Array.of(u).buffer));else if(typeof u=="string")e.push(4),o(u);else if(u instanceof Uint8Array)e.push(7),s(u.length),a(u.slice());else if(u instanceof Float32Array)e.push(8),s(u.length),a(new Uint8Array(u.slice().buffer));else if(Array.isArray(u)||ArrayBuffer.isView(u)){let d=Array.from(u);e.push(5),s(d.length);for(let f of d)m(f)}else{let d=Object.entries(u).filter(([,f])=>f!==void 0);e.push(6),s(d.length);for(let[f,O]of d)o(f),m(O)}};m(i),n();let h=new Uint8Array(t),c=0;for(let u of r)h.set(u,c),c+=u.length;return h}function ie(i){let e=new DataView(i.buffer,i.byteOffset,i.byteLength),r=0,t=()=>(r+=4,e.getUint32(r-4,!0)),n=()=>{let s=t();return r+=s,ne.decode(i.subarray(r-s,r))},a=()=>{switch(i[r++]){case 0:return null;case 1:return!1;case 2:return!0;case 3:return r+=8,e.getFloat64(r-8,!0);case 4:return n();case 5:return Array.from({length:t()},a);case 6:return Object.fromEntries(Array.from({length:t()},()=>[n(),a()]));case 7:{let s=t();return r+=s,i.slice(r-s,r)}case 8:{let s=t();return r+=4*s,new Float32Array(i.slice(r-4*s,r).buffer)}default:throw new Error("bad value from the core")}};return a()}function b(i,e){let r=ae(e),t=i.x.alk_value_in(r.length);new Uint8Array(i.heap,t,r.length).set(r)}function p(i,e){let r=ie(new Uint8Array(i.heap,i.x.alk_value_out(),i.x.alk_value_len()).slice());if(e>=0)return r;let t=r;throw t.kind==="TypeError"?new TypeError(t.message):t.kind==="RangeError"?new RangeError(t.message):t.kind==="AlkoveError"?new v(t.code,t.message):new Error(t.message)}var l=i=>{if(!i)throw new Error("used after release");return i},_=(i,e,r)=>i.with(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),t=>r(t,e.length)),F=class{constructor(e,r){this.alk=e;this.ptr=e.x.alk_lex(r.ptr),this.ptr||e.fail("lex")}ptr;get handle(){return this.ptr}phonemize(e,r){return b(this.alk,{texts:e,lang:r}),p(this.alk,this.alk.x.alk_lex_phonemize(l(this.ptr)))}add(e){p(this.alk,this.alk.x.alk_lex_add(l(this.ptr),e.ptr))}release(){this.ptr&&this.alk.x.alk_lex_free(this.ptr),this.ptr=0}},w=class{constructor(e,r,t){this.alk=e;this.ptr=e.x.alk_spot(r.ptr,t.ptr),this.ptr||e.fail("spot")}ptr;langs=[];all=[];head=!1;get handle(){return l(this.ptr)}add(e){let r=p(this.alk,this.alk.x.alk_spot_add(l(this.ptr),e.ptr));return this.langs.includes(r)||this.langs.push(r),this.all.includes(r)||this.all.push(r),r}addLangs(e){let r=e.filter(t=>!this.all.includes(t));r.length&&(b(this.alk,r),p(this.alk,this.alk.x.alk_spot_langs(l(this.ptr))),this.all.push(...r))}setLang(e){p(this.alk,this.alk.x.alk_spot_lang(l(this.ptr),e.ptr)),this.head=!0}release(){this.ptr&&this.alk.x.alk_spot_free(this.ptr),this.ptr=0}};function Q(i,e,r,t,n){return b(i,{text:r,lang:t,chain:n}),p(i,i.x.alk_compile(e?.handle??0))}function G(i,e,r,t){return b(i,{spec:r,langs:t}),p(i,i.x.alk_commands(e.handle))}function Y(i,e,r,t,n,a){b(i,a);let s=p(i,_(i,n,(o,m)=>i.x.alk_recording_print(e.ptr,r.ptr,t.ptr,o,m)));return s?Array.from(s):null}var N=class{constructor(e,r,t){this.alk=e;b(e,t),this.ptr=e.x.alk_processor(r.focus?.ptr??0,r.cue?.ptr??0,r.spot?.handle??0,r.timbre?.ptr??0),this.ptr||e.fail("processor")}ptr;part(e){let{x:r}=this.alk,t=p(this.alk,e),n=new Float32Array(this.alk.heap,r.alk_processor_audio(l(this.ptr)),r.alk_processor_audio_len(l(this.ptr))).slice(),{start:a,...s}=t;return{start:a,audio:n,...s}}push(e){return this.part(_(this.alk,e,(r,t)=>this.alk.x.alk_processor_push(l(this.ptr),r,t)))}end(){return this.part(this.alk.x.alk_processor_end(l(this.ptr)))}release(){this.ptr&&this.alk.x.alk_processor_free(this.ptr),this.ptr=0}},M=class{constructor(e,r,t,n){this.alk=e;b(e,{words:t,context:n}),this.ptr=e.x.alk_listener(r.handle),this.ptr||e.fail("listener")}ptr;setWords(e,r){b(this.alk,{words:e,context:r}),p(this.alk,this.alk.x.alk_listener_words(l(this.ptr)))}push(e){return p(this.alk,_(this.alk,e,(r,t)=>this.alk.x.alk_listener_push(l(this.ptr),r,t)))}release(){this.ptr&&this.alk.x.alk_listener_free(this.ptr),this.ptr=0}},V=class{constructor(e,r,t,n,a){this.alk=e;b(e,{word:t,takes:n,chain:a}),this.ptr=e.x.alk_enroller(r.handle),this.ptr||e.fail("enroller")}ptr;push(e){return p(this.alk,_(this.alk,e,(r,t)=>this.alk.x.alk_enroller_push(l(this.ptr),r,t)))}result(){return p(this.alk,this.alk.x.alk_enroller_result(l(this.ptr)))}release(){this.ptr&&this.alk.x.alk_enroller_free(this.ptr),this.ptr=0}},L=class{constructor(e,r){this.alk=e;this.ptr=e.x.alk_timbre(r.ptr),this.ptr||e.fail("timbre")}ptr;get handle(){return this.ptr}windows(e){return p(this.alk,_(this.alk,e,(r,t)=>this.alk.x.alk_timbre_windows(l(this.ptr),r,t)))}embed(e,r){return b(this.alk,{source:r}),p(this.alk,_(this.alk,e,(t,n)=>this.alk.x.alk_timbre_embed(l(this.ptr),t,n)))}release(){this.ptr&&this.alk.x.alk_timbre_free(this.ptr),this.ptr=0}};function q(i,e){return b(i,e),p(i,i.x.alk_voiceprint())}var S=class{constructor(e,r,t){this.alk=e;b(e,{source:r,start:t}),this.ptr=e.x.alk_learner(),this.ptr||e.fail("learner")}ptr;learn(e,r){return p(this.alk,_(this.alk,r,(t,n)=>this.alk.x.alk_learner_learn(l(this.ptr),e.handle,t,n)))}offer(e,r){return p(this.alk,_(this.alk,r,(t,n)=>this.alk.x.alk_learner_offer(l(this.ptr),e.handle,t,n)))}progress(){return p(this.alk,this.state()).progress}ready(){return p(this.alk,this.state()).ready}state(){return this.alk.x.alk_learner_state(l(this.ptr))}voiceprint(e=!1){return p(this.alk,this.alk.x.alk_learner_voiceprint(l(this.ptr),+e))}forget(){this.alk.x.alk_learner_forget(l(this.ptr))}release(){this.ptr&&this.alk.x.alk_learner_free(this.ptr),this.ptr=0}},E=class{constructor(e,r,t){this.alk=e;b(e,t),this.ptr=e.x.alk_pipeline(r.focus?.ptr??0,r.cue?.ptr??0,r.spot?.handle??0),this.ptr||e.fail("pipeline")}ptr;out=new Float32Array(256);step(e,r){let{alk:t}=this,n=l(this.ptr);new Float32Array(t.heap,t.x.alk_pipeline_hop(n),256).set(e);let a=t.x.alk_pipeline_step(n,r);return this.out.set(new Float32Array(t.heap,a,256)),this.out}spent(e){this.alk.x.alk_pipeline_spent(l(this.ptr),e)}spot(e){p(this.alk,this.alk.x.alk_pipeline_spot(l(this.ptr),e.handle))}timbre(e){this.alk.x.alk_pipeline_timbre(l(this.ptr),e.ptr)<0&&this.alk.fail("pipeline.timbre")}raw(e){new Float32Array(this.alk.heap,this.alk.x.alk_pipeline_hop(l(this.ptr)),256).set(e),this.alk.x.alk_pipeline_raw(l(this.ptr))}outs(){return this.alk.x.alk_pipeline_pending(l(this.ptr))?p(this.alk,this.alk.x.alk_pipeline_outs(l(this.ptr))):[]}verified(e,r,t){this.alk.x.alk_pipeline_verified(l(this.ptr),e,+r,t)}set(e){b(this.alk,e),p(this.alk,this.alk.x.alk_pipeline_set(l(this.ptr)))}record(e){p(this.alk,this.alk.x.alk_pipeline_record(l(this.ptr),e))}recent(){return p(this.alk,this.alk.x.alk_pipeline_recent(l(this.ptr)))}stats(){return p(this.alk,this.alk.x.alk_pipeline_stats(l(this.ptr)))}get time(){return this.alk.x.alk_pipeline_get(l(this.ptr),0)}get sleeping(){return this.alk.x.alk_pipeline_get(l(this.ptr),1)===1}get gainDb(){return this.alk.x.alk_pipeline_get(l(this.ptr),2)}get hops(){return this.alk.x.alk_pipeline_get(l(this.ptr),3)}get chained(){return this.alk.x.alk_pipeline_get(l(this.ptr),4)===1}release(){this.ptr&&this.alk.x.alk_pipeline_free(this.ptr),this.ptr=0}},P=class{constructor(e,r){this.alk=e;b(e,{reference:r}),this.ptr=e.x.alk_coach(),this.ptr||e.fail("coach")}ptr;learner(e){return b(this.alk,{start:e}),p(this.alk,this.alk.x.alk_coach_learner(l(this.ptr)))}forget(){this.alk.x.alk_coach_forget(l(this.ptr))}window(e,r,t,n){return p(this.alk,_(this.alk,r,(a,s)=>this.alk.x.alk_coach_window(l(this.ptr),e.handle,a,s,t,n)))}verify(e,r){return p(this.alk,_(this.alk,r,(t,n)=>this.alk.x.alk_coach_verify(l(this.ptr),e.handle,t,n)))}release(){this.ptr&&this.alk.x.alk_coach_free(this.ptr),this.ptr=0}};var C=class{constructor(e,r){this.alk=e;this.bytes=r}models=new Map;calls=new Map;lexer=null;spotter=null;bare=null;voices=null;has(e){return this.models.has(e)}model(e){let r=this.models.get(e);return r||this.models.set(e,r=this.alk.model(this.bytes(e))),r}langModel(e){try{return this.model(e)}catch(r){throw new v("models.missing",`${e} was not loaded: load the languages the words use.`,r)}}stream(e){return this.model(e).session()}chain(e){return new A(this.alk,this.model("focus"),this.model("cue"),e)}processor(e){let r=!!e.focus,t=e.spot?this.bareSpot(y(e.spot.words??[])):void 0,n={focus:r?this.model("focus"):void 0,cue:r||e.cue?this.model("cue"):void 0,spot:t,timbre:r?this.model("timbre"):void 0};return new N(this.alk,n,e)}recordingPrint(e,r){return Y(this.alk,this.model("focus"),this.model("cue"),this.model("timbre"),e,r)}listener(e,r){return new M(this.alk,this.bareSpot(y(e)),e,r)}enroller(e,r,t){return new V(this.alk,this.bareSpot(y([e])),e,r,t)}lex(e){for(let r of e)this.lexer?this.lexer.add(this.langModel(`lex-${r}`)):this.lexer=new F(this.alk,this.langModel(`lex-${r}`));if(!this.lexer)throw new v("models.missing","Lex needs a language.");return this.lexer}spot(e,r=[]){let t=this.tops(this.spotter??=new w(this.alk,this.model("cue"),this.model("spot")),e);if(t.addLangs(r),!t.head&&t.all.length>1){let n=this.sent("spot-lang");n&&t.setLang(n)}return t}bareSpot(e){return this.tops(this.bare??=new w(this.alk,this.model("cue"),this.model("spot")),e)}tops(e,r){for(let t of r)e.langs.includes(t)||e.add(this.langModel(`spot-${t}`));return e}sent(e){try{return this.model(e)}catch{return null}}timbre(){return this.voices??=new L(this.alk,this.model("timbre"))}learner(e,r){return new S(this.alk,e,r)}pipeline(e){let r=!!e.chain,t=[...e.words??[],...e.enroll?[e.enroll.word]:[]],n=e.langs??[],a=t.length||n.length?this.spot(y(t),n):void 0,s=new E(this.alk,{focus:r?this.model("focus"):void 0,cue:r?this.model("cue"):void 0,spot:a},e);return r&&s.timbre(this.model("timbre")),s}coach(e){return new P(this.alk,e)}voiceprint(e){return q(this.alk,e)}compile(e,r,t){return Q(this.alk,/^\s*\/.+\/\s*$/.test(e)?null:this.lex(r),e,r,t)}commands(e,r){return G(this.alk,this.lex(r),e,[...r])}net(e,r){let t=`${e} ${r??""}`,n=this.calls.get(t);n||this.calls.set(t,n=this.model(e).session(r));let a=n;return{run:(s,o)=>a.call(s,o),reset:()=>a.reset()}}release(){this.lexer?.release(),this.spotter?.release(),this.bare?.release(),this.voices?.release(),this.lexer=null,this.spotter=null,this.bare=null,this.voices=null;for(let e of this.calls.values())e.release();for(let e of this.models.values())e.release();this.calls.clear(),this.models.clear()}};var g=class extends Error{},T=class i{constructor(e){this.x=e}static async create(e){let r=await WebAssembly.instantiate(e,{});return new i(r.exports)}get heap(){return this.x.memory.buffer}with(e,r){let t=this.x.alk_alloc(e.length);new Uint8Array(this.heap,t,e.length).set(e);try{return r(t,e.length)}finally{this.x.alk_free(t,e.length)}}fail(e){let t=this.x.alk_alloc(512);try{let n=this.x.alk_error(t,512);throw new g(`${e}: ${new TextDecoder().decode(new Uint8Array(this.heap,t,n))}`)}finally{this.x.alk_free(t,512)}}model(e){return new U(this,e)}},U=class{constructor(e,r){this.alk=e;let t=e.x;this.ptr=e.with(r,(s,o)=>t.alk_model(s,o)),this.ptr||e.fail("model");let n=t.alk_alloc(256),a=s=>new TextDecoder().decode(new Uint8Array(e.heap,n,s));try{this.plans=Array.from({length:t.alk_plans(this.ptr)},(s,o)=>{let m=c=>Array.from({length:t.alk_io_count(this.ptr,o,c)},(u,d)=>{let f=a(t.alk_io_name(this.ptr,o,c,d,n,256)),O=t.alk_io_shape(this.ptr,o,c,d,n,64),z=Array.from(new Uint32Array(e.heap,n,O));return{name:f,dims:z,size:z.reduce((Z,ee)=>Z*ee,1)}}),h=m(0);return{index:o,name:a(t.alk_plan_name(this.ptr,o,n,256)),inputs:h,outputs:m(1),variable:h[t.alk_variable(this.ptr,o)]?.name??null}})}finally{t.alk_free(n,256)}}ptr;plans;session(e){let r=e===void 0?this.plans[0]:this.plans.find(t=>t.name===e);if(!r)throw new g(`no plan named ${e}`);return new R(this,r)}release(){this.alk.x.alk_model_free(this.ptr)}},R=class{constructor(e,r){this.model=e;this.plan=r;let{alk:t}=e,n=t.x;this.ptr=n.alk_session(e.ptr,r.index),this.ptr||t.fail("session");let a=new TextEncoder;for(let[s,o]of[[r.inputs,n.alk_input],[r.outputs,n.alk_output]])for(let m of s)this.at.set(m.name,{...m,p:t.with(a.encode(m.name),(h,c)=>o(this.ptr,h,c))})}ptr;at=new Map;io(e){let r=this.at.get(e);if(!r)throw new g(`no tensor named ${e}`);return r}f32(e){let r=this.io(e);return new Float32Array(this.model.alk.heap,r.p,r.size)}run(){this.model.alk.x.alk_run(this.ptr)}reset(){this.model.alk.x.alk_state_clear(this.ptr)}call(e,r=this.plan.outputs.map(t=>t.name)){let{alk:t}=this.model,{variable:n}=this.plan;for(let s of this.plan.inputs){let o=e[s.name];if(!o)throw new g(`missing input ${s.name}`);if(s.name===n)t.x.alk_set_len(this.ptr,o.data.length)!==0&&t.fail(s.name);else if(o.data.length!==s.size)throw new g(`${s.name}: ${o.data.length} values for ${s.size}`);this.f32(s.name).set(o.data)}this.run();let a={};for(let s of r)a[s]={data:this.f32(s).slice(),dims:[...this.io(s).dims]};return a}release(){this.model.alk.x.alk_session_free(this.ptr),this.at.clear()}};function K(i){let e=new Map,r=new Map,t=(n,a,s)=>{let o=n.get(a);if(!o)throw new Error(`${s} ${a} is closed, or its worker was started again`);return o};return{embed:(n,a)=>i().timbre().embed(n,a??"raw"),learnerOpen:(n,a)=>{let s=i().learner("raw",a);return e.set(n,s),{progress:s.progress(),ready:s.ready(),voiceprint:s.voiceprint(!0)}},learnerOffer:(n,a)=>{let s=t(e,n,"learner");return{...s.offer(i().timbre(),a),voiceprint:s.voiceprint(!0)}},learnerForget:n=>(e.get(n)?.forget(),null),learnerClose:n=>(e.get(n)?.release(),e.delete(n),null),phonemize:(n,a)=>i().lex([a]).phonemize(n,a),compile:(n,a)=>i().compile(n,a.lang===void 0?[]:[a.lang].flat(),a.chain).word,compileCommands:(n,a)=>i().commands(n,a),process:(n,a,s)=>{let o=B(i(),n,{...a,onProgress:s});return{audio:o.audio,raw:o.raw,speech:o.speech,wakes:o.wakes,diag:o.diag,trace:o.trace}},streamOpen:(n,a)=>(r.set(n,new j(i(),a)),null),streamPush:(n,a)=>t(r,n,"stream").push(a),streamEnd:n=>{let a=t(r,n,"stream");return r.delete(n),a.end()}}}var X=class{engine=null;boot=null;bytes=new Map;calls=K(()=>this.engine);async ready(e){await(this.boot??=(async()=>{let r=await I($,void 0,new URL("./alkove-engine.wasm",import.meta.url).href),t=await T.create(await WebAssembly.compile(r));this.engine=new C(t,n=>this.bytes.get(n))})().catch(r=>{throw this.boot=null,r}));for(let r of e)this.bytes.has(r)||this.bytes.set(r,await W(r));return this}};export{X as NodeBackend};
package/dist/process.d.ts CHANGED
@@ -7,6 +7,7 @@ export interface ProcessOptions {
7
7
  focus?: boolean | {
8
8
  voiceprint?: VoiceprintInput;
9
9
  strength?: number;
10
+ lowPower?: boolean;
10
11
  };
11
12
  cue?: boolean | Partial<SpeechParams>;
12
13
  spot?: {
@@ -58,6 +59,7 @@ export declare function coreOptions(opts: Omit<ProcessOptions, 'onProgress' | 's
58
59
  sample?: number[] | undefined;
59
60
  print: number[] | null;
60
61
  strength: number;
62
+ lowPower: boolean;
61
63
  } | null;
62
64
  cue: boolean | null;
63
65
  speech: {
@@ -85,7 +87,28 @@ export declare class Processor {
85
87
  readonly opts: Omit<ProcessOptions, 'onProgress' | 'signal'>;
86
88
  private core;
87
89
  private closed;
88
- constructor(engine: Engine, opts?: Omit<ProcessOptions, 'onProgress' | 'signal'>);
90
+ constructor(engine: Engine, opts?: Omit<ProcessOptions, 'onProgress' | 'signal'>, wire?: {
91
+ focus: {
92
+ sample?: number[] | undefined;
93
+ print: number[] | null;
94
+ strength: number;
95
+ lowPower: boolean;
96
+ } | null;
97
+ cue: boolean | null;
98
+ speech: {
99
+ confidence: number;
100
+ exitConfidence: number;
101
+ startSecs: number;
102
+ stopSecs: number;
103
+ };
104
+ normalize: boolean;
105
+ trace: boolean;
106
+ rate: number;
107
+ spot: {
108
+ words: WordJSON[];
109
+ context: Context;
110
+ } | null;
111
+ });
89
112
  push(pcm: Float32Array): ProcessPart;
90
113
  end(): ProcessPart;
91
114
  release(): void;
package/dist/react.js CHANGED
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{f as W,g as V,h as F}from"./chunk-BWNLE4ZO.js";import"./chunk-SSJ7CLCP.js";import{useCallback as M,useEffect as h,useLayoutEffect as B,useRef as p,useState as v}from"react";var J=t=>Array.isArray(t)||Object.getPrototypeOf(t)===Object.prototype;function k(t,r){if(Object.is(t,r))return!0;if(typeof t!="object"||typeof r!="object"||!t||!r)return!1;let u=t.toJSON,a=r.toJSON;if(typeof u=="function"||typeof a=="function")return k(typeof u=="function"?u.call(t):t,typeof a=="function"?a.call(r):r);if(!J(t)||!J(r)||Array.isArray(t)!==Array.isArray(r))return!1;let l=Object.keys(t).filter(o=>t[o]!==void 0),S=Object.keys(r).filter(o=>r[o]!==void 0);return l.length===S.length&&l.every(o=>k(t[o],r[o]))}var Q={speechstart:!0,speechend:!0,speechcancel:!0,turn:!0,turnend:!0,interruptstart:!0,interrupt:!0,interruptcancel:!0,mode:!0,status:!0,voiceprint:!0,learn:!0,mic:!0,trackchange:!0,wake:!0,heard:!0,trace:!0,audio:!0,utterance:!0,take:!0,enrolled:!0},X=Object.keys(Q),C=1,D=Promise.resolve(),Y=typeof window>"u"?h:B;function N(t,r,u){let{enabled:a=!0,on:l,...S}=r,o=S,m=p(l),x=p(o),w=Object.fromEntries(Object.entries(o).filter(([n])=>!u.includes(n))),f=p({value:w,version:0}),b=k(f.current.value,w)?f.current.version:f.current.version+1;Y(()=>{m.current=l,x.current=o,b!==f.current.version&&(f.current={value:w,version:b})});let[O,R]=v(null),[P,d]=v("off"),[G,E]=v(null),[K,A]=v(null),[q,H]=v(null),s=p(null),c=p({}),i=p(null),y=M(()=>{let n=!!s.current&&!!m.current?.diag;n&&!i.current?i.current=s.current.on("diag",g=>m.current?.diag?.(g)):!n&&i.current&&(i.current(),i.current=null)},[]);h(()=>{if(!a)return;let n=new AbortController,g=[];d("starting"),A(null);let T=D.then(()=>{if(n.signal.aborted)return;let e={...x.current,signal:n.signal};return c.current={strength:e.strength??C,voiceprint:e.voiceprint??null},t(e)});return D=T.catch(()=>{}),T.then(e=>{if(e){if(n.signal.aborted)return e.dispose();s.current=e,y();for(let I of X)g.push(e.on(I,(z=>m.current?.[I]?.(z))));g.push(e.on("status",d),e.on("mode",I=>E(I.mode)),e.on("trackchange",H)),R(e),d(e.status),E(e.mode)}},e=>{n.signal.aborted||(A(e instanceof Error?e:new Error(String(e))),d("off"))}),()=>{n.abort();for(let e of g)e();i.current?.(),i.current=null,s.current?.dispose(),s.current=null,R(null),d("off"),E(null),H(null),A(null)}},[a,b,t,y]);let U=!!l?.diag;h(y,[O,U,y]);let j=u.includes("strength")?o.strength:void 0,L=u.includes("voiceprint")?o.voiceprint:void 0;h(()=>{let n=s.current;n&&(u.includes("strength")&&(j??C)!==c.current.strength&&(c.current.strength=j??C,n.setStrength(c.current.strength)),u.includes("voiceprint")&&!k(L??null,c.current.voiceprint??null)&&(c.current.voiceprint=L??null,n.setVoiceprint(c.current.voiceprint)))},[O,j,L,u]);let _=M(async()=>{await s.current?.resume()},[]);return{input:O,status:P,mode:G,error:K,get track(){return q??O?.track??null},resume:_}}var Z=["strength","voiceprint"],$=["voiceprint"],tt=[];function ut(t={}){return N(V,t,$)}function st(t={}){return N(W,t,Z)}function ct(t){return N(F,t,tt)}export{ut as useAgentInput,st as useCallInput,ct as useWakeListener};
2
+ import{f as W,g as V,h as F}from"./chunk-C5QG5BVR.js";import"./chunk-2PTYZFLZ.js";import{useCallback as M,useEffect as h,useLayoutEffect as B,useRef as p,useState as v}from"react";var J=t=>Array.isArray(t)||Object.getPrototypeOf(t)===Object.prototype;function k(t,r){if(Object.is(t,r))return!0;if(typeof t!="object"||typeof r!="object"||!t||!r)return!1;let u=t.toJSON,a=r.toJSON;if(typeof u=="function"||typeof a=="function")return k(typeof u=="function"?u.call(t):t,typeof a=="function"?a.call(r):r);if(!J(t)||!J(r)||Array.isArray(t)!==Array.isArray(r))return!1;let l=Object.keys(t).filter(o=>t[o]!==void 0),S=Object.keys(r).filter(o=>r[o]!==void 0);return l.length===S.length&&l.every(o=>k(t[o],r[o]))}var Q={speechstart:!0,speechend:!0,speechcancel:!0,turn:!0,turnend:!0,interruptstart:!0,interrupt:!0,interruptcancel:!0,mode:!0,status:!0,voiceprint:!0,learn:!0,mic:!0,trackchange:!0,wake:!0,command:!0,language:!0,heard:!0,trace:!0,audio:!0,utterance:!0,take:!0,enrolled:!0},X=Object.keys(Q),C=1,D=Promise.resolve(),Y=typeof window>"u"?h:B;function N(t,r,u){let{enabled:a=!0,on:l,...S}=r,o=S,m=p(l),x=p(o),w=Object.fromEntries(Object.entries(o).filter(([n])=>!u.includes(n))),f=p({value:w,version:0}),b=k(f.current.value,w)?f.current.version:f.current.version+1;Y(()=>{m.current=l,x.current=o,b!==f.current.version&&(f.current={value:w,version:b})});let[O,R]=v(null),[P,d]=v("off"),[G,E]=v(null),[K,A]=v(null),[q,H]=v(null),s=p(null),c=p({}),i=p(null),y=M(()=>{let n=!!s.current&&!!m.current?.diag;n&&!i.current?i.current=s.current.on("diag",g=>m.current?.diag?.(g)):!n&&i.current&&(i.current(),i.current=null)},[]);h(()=>{if(!a)return;let n=new AbortController,g=[];d("starting"),A(null);let T=D.then(()=>{if(n.signal.aborted)return;let e={...x.current,signal:n.signal};return c.current={strength:e.strength??C,voiceprint:e.voiceprint??null},t(e)});return D=T.catch(()=>{}),T.then(e=>{if(e){if(n.signal.aborted)return e.dispose();s.current=e,y();for(let I of X)g.push(e.on(I,(z=>m.current?.[I]?.(z))));g.push(e.on("status",d),e.on("mode",I=>E(I.mode)),e.on("trackchange",H)),R(e),d(e.status),E(e.mode)}},e=>{n.signal.aborted||(A(e instanceof Error?e:new Error(String(e))),d("off"))}),()=>{n.abort();for(let e of g)e();i.current?.(),i.current=null,s.current?.dispose(),s.current=null,R(null),d("off"),E(null),H(null),A(null)}},[a,b,t,y]);let U=!!l?.diag;h(y,[O,U,y]);let j=u.includes("strength")?o.strength:void 0,L=u.includes("voiceprint")?o.voiceprint:void 0;h(()=>{let n=s.current;n&&(u.includes("strength")&&(j??C)!==c.current.strength&&(c.current.strength=j??C,n.setStrength(c.current.strength)),u.includes("voiceprint")&&!k(L??null,c.current.voiceprint??null)&&(c.current.voiceprint=L??null,n.setVoiceprint(c.current.voiceprint)))},[O,j,L,u]);let _=M(async()=>{await s.current?.resume()},[]);return{input:O,status:P,mode:G,error:K,get track(){return q??O?.track??null},resume:_}}var Z=["strength","voiceprint"],$=["voiceprint"],tt=[];function ut(t={}){return N(V,t,$)}function st(t={}){return N(W,t,Z)}function ct(t){return N(F,t,tt)}export{ut as useAgentInput,st as useCallInput,ct as useWakeListener};