alkove 0.4.2 → 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/NOTICE +1 -1
- package/README.md +6 -6
- package/dist/alkove-engine.wasm +0 -0
- package/dist/alkove-worker.js +1 -1
- package/dist/api-4YJABVLZ.js +1 -0
- package/dist/api.d.ts +32 -13
- package/dist/assets-27T24F6J.js +2 -0
- package/dist/chunk-2PTYZFLZ.js +1 -0
- package/dist/chunk-C5QG5BVR.js +1 -0
- package/dist/chunk-N4S2422Z.js +1 -0
- package/dist/cli.js +5 -3
- package/dist/copy-models.d.ts +7 -0
- package/dist/core/chain.d.ts +2 -0
- package/dist/core/engine.d.ts +19 -7
- package/dist/core/lex.d.ts +1 -1
- package/dist/core/native.d.ts +24 -5
- package/dist/core/spot/spot.d.ts +40 -1
- package/dist/engine/alk.d.ts +15 -5
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/loader.d.ts +0 -1
- package/dist/manifest.d.ts +5 -2
- package/dist/models.generated.d.ts +155 -1
- package/dist/node-3YHT2KZ5.js +1 -0
- package/dist/process.d.ts +33 -3
- package/dist/react.js +1 -1
- package/dist/realtime/worker.d.ts +6 -4
- package/dist/recipes/input.d.ts +55 -32
- package/dist/runtime/calls.d.ts +1 -0
- package/dist/runtime/node.d.ts +1 -0
- package/package.json +2 -2
- package/dist/api-63K47HT3.js +0 -1
- package/dist/assets-CPGXIA43.js +0 -2
- package/dist/chunk-FC4ZSMUX.js +0 -1
- package/dist/chunk-IMUNEOSF.js +0 -1
- package/dist/chunk-MZOMHWYI.js +0 -1
- package/dist/node-VEIFZSW6.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as B,b as u,c as N,d as J,e as U,i as $}from"./chunk-C5QG5BVR.js";import{C as T,D as I,G as C,a as k,b as m,c as L,e as F,f as P,g as p,h as W,i as R,j as A,k as y,m as v,n as O,q as w,r as S,s as E,v as V,y as M}from"./chunk-2PTYZFLZ.js";var c=class{static langs=F.langs;static inventory=W.map(e=>e.normalize("NFC"));static distance(e,t){let n=typeof e=="string"?A(e.replace(/^\/|\/$/g,""))??[]:e,o=typeof t=="string"?A(t.replace(/^\/|\/$/g,""))??[]:t;if(!n.length||!o.length)return n.length===o.length?0:1;let a=Array.from({length:o.length+1},(s,l)=>l);for(let s=1;s<=n.length;s++){let l=[s];for(let i=1;i<=o.length;i++){let g=n[s-1]===o[i-1]?0:R[n[s-1]-1].includes(o[i-1])?.5:1;l.push(Math.min(a[i]+1,l[i-1]+1,a[i-1]+g))}a=l}return a[o.length]/Math.max(n.length,o.length)}};var X=()=>typeof process<"u"&&!!process.versions?.node&&typeof window>"u",q=0,ee=null;async function d(r,e){if(X()){let n=await(ee??=import("./node-3YHT2KZ5.js").then(o=>new o.NodeBackend));return await n.ready(r),{call:async(o,a,s,l)=>n.calls[o](...a,l),hold:()=>()=>{}}}let t=N.get();return await t.models("background",r,e),{call:async(n,o,a=[],s)=>(await t.models("background",r)).call(n,o,a,s),hold:()=>t.hold()}}function re(r){let e=r.lang===void 0?[]:typeof r.lang=="string"?[r.lang]:[...r.lang],t=new Set,n=!1;for(let o of r.words)if(typeof o!="string"||o.trimStart().startsWith("{"))for(let a of O([v(o).toJSON()]))t.add(a);else/^\s*\/.+\/\s*$/.test(o)?e.slice(0,1).forEach(a=>t.add(a)):(n=!0,e.forEach(a=>t.add(a)));return{tops:[...t],lex:n?e:[]}}function j(r,e={}){if(r==="wake"){let s=P(e.langs??[]);return e.voiceprint&&s.push("timbre"),e.typedWords&&s.push(...p(e.langs??[])),s}let t=r==="agent"&&e.wake?re(e.wake):{tops:[],lex:[]},n=e.langs??[],o=new Set([...t.tops,...n]).size>1,a=["focus","cue","timbre",...t.tops.length||n.length&&o?P(t.tops):[],...o?["spot-lang"]:[]];return e.typedWords&&a.push(...p(n)),a.push(...p(t.lex)),[...new Set(a)]}async function te(r){if("pcm"in r&&"rate"in r)return u.all(r.pcm,r.rate,m);if(typeof AudioBuffer<"u"&&r instanceof AudioBuffer)return u.all(z(r),r.sampleRate,m);let e=typeof Blob<"u"&&r instanceof Blob?new Uint8Array(await r.arrayBuffer()):r instanceof Uint8Array?r:new Uint8Array(r);if(String.fromCharCode(...e.subarray(0,4))==="RIFF"){let{pcm:o,rate:a}=I(e);return u.all(o,a,m)}if(typeof OfflineAudioContext>"u")throw new y("browser.unsupported","Outside a browser only WAV is decoded: decode the file and pass { pcm, rate }.");let n=await new OfflineAudioContext(1,1,44100).decodeAudioData(e.slice().buffer);return u.all(z(n),n.sampleRate,m)}function z(r){if(r.numberOfChannels===1)return r.getChannelData(0).slice();let e=new Float32Array(r.length);for(let t=0;t<r.numberOfChannels;t++){let n=r.getChannelData(t);for(let o=0;o<e.length;o++)e[o]+=n[o]/r.numberOfChannels}return e}var Ne={configure:E,stream:ne,supported:J,micPermission:U,onDiag:V,async preload(r,e={}){let t=j(r,e);if(X()){await d(t);return}let n=N.get(),o=t.filter(i=>i!=="timbre"&&!i.startsWith("lex-")),a=t.filter(i=>i==="timbre"||i.startsWith("lex-")),s=[{loaded:0,total:0},{loaded:0,total:0}],l=i=>g=>{s[i]=g,e.onProgress?.({loaded:s[0].loaded+s[1].loaded,total:s[0].total+s[1].total})};await Promise.all([n.models("realtime",o,l(0)),a.length?n.models("background",a,l(1)):null])},async cached(r,e={}){let t=[k,...j(r,e).map(n=>L[n])];return(await Promise.all(t.map(M))).every(Boolean)},async process(r,e={}){e=await C(e);let t=await te(r);e.signal?.throwIfAborted();let o=await(await d(K(e))).call("process",[t,Q(e)],[],e.onProgress);return{...o,toWav(a="audio"){return T(a==="both"?[o.raw,o.audio]:[a==="raw"?o.raw:o.audio],m)}}}};function K(r){let e=[];return r.focus?e.push("focus","cue","timbre"):r.cue&&e.push("cue"),r.spot?.words.length&&e.push(...P(O(r.spot.words)).filter(t=>t!=="spot-lang")),[...new Set(e)]}function Q(r){let{onProgress:e,signal:t,...n}=r;return{...n,focus:typeof r.focus=="object"?{...r.focus,voiceprint:r.focus.voiceprint instanceof w?r.focus.voiceprint.toJSON():r.focus.voiceprint}:r.focus,spot:r.spot?{...r.spot,words:r.spot.words.map(o=>v(o).toJSON())}:void 0}}async function*ne(r,e={}){e=await C(e);let t=await d(K(e)),n=++q,o=t.hold();await t.call("streamOpen",[n,Q(e)]).catch(f=>{throw o(),f});let a=e.rate??m,s=new u(a,m,!0),l=0,i=0,g=Symbol.asyncIterator in r?r:oe(r);try{for await(let h of g){e.signal?.throwIfAborted();let b=[];l+=h.length,s.push(h,Z=>b.push(Z)),i+=b.length,b.length&&(yield await t.call("streamPush",[n,Float32Array.from(b)]))}let f=[],x=Math.round(l*m/a)-i;x>0&&s.push(new Float32Array(u.HALF*2+8),h=>f.length<x&&f.push(h)),f.length&&(yield await t.call("streamPush",[n,Float32Array.from(f)]))}finally{try{yield await t.call("streamEnd",[n])}finally{o()}}}async function*oe(r){let e=r.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)return;yield n}}finally{e.releaseLock()}}var D=class r{constructor(e){this.b=e}static async create(){return new r(await d(["timbre"]))}async embed(e){return Y(e,"raw",this.b)}verify(e,t,n={}){return S.verify(e,t,n)}async identify(e,t,n={}){let o=e instanceof w?e:await this.embed(e);return S.identify(o,t,n)}},H=class r{static inventory=c.inventory;static langs=c.langs;static distance=c.distance;constructor(){}static async create(e={}){return await d(p(e.langs??[])),new r}async phonemize(e,t){if(!c.langs.includes(t))throw new y("lang.unsupported",`No ${t}: ${c.langs.join(", ")} only.`);let o=(await(await d(p([t]))).call("phonemize",[Array.isArray(e)?e:[e],t])).map(a=>a.map(({ipa:s,p:l})=>({ipa:s,p:l})));return Array.isArray(e)?o:o[0]}};async function Y(r,e,t){return w.fromJSON(await(t??await d(["timbre"])).call("embed",[r,e]))}async function ae(r,e,t){for(let a of[e??[]].flat())if(!c.langs.includes(a))throw new y("lang.unsupported",`No ${a}: ${c.langs.join(", ")} only.`);let n=/^\s*\/.+\/\s*$/.test(r),o=await d(n?[]:p([e??[]].flat()));return v(await o.call("compile",[r,{lang:e,chain:t}]))}async function se(r,e){let t=[...new Set(e?.langs??[])];if(!t.length)throw new TypeError("Spot.commands: langs names the languages to compile");for(let n of t)if(!c.langs.includes(n))throw new y("lang.unsupported",`No ${n}: ${c.langs.join(", ")} only.`);return(await d(p(t))).call("compileCommands",[r,t])}var ie={compile(r,e={}){return ae(r,e.lang)},commands(r,e){return se(r,e)},enroll(r,e={}){return new B({compile:()=>ie.compile(r,e),open:async t=>{let n=await $(e,t);return{on:n.on.bind(n),stop:()=>n.dispose(),source:"raw"}},embed:(t,n)=>Y(t,n)})}},G=r=>r?new w(r.centers,r.source,r.model,r.windows):null,le=r=>({alkove:"voiceprint",model:r.model,source:r.source,centers:r.centers,windows:r.windows}),ce=typeof FinalizationRegistry>"u"?null:new FinalizationRegistry(r=>r()),_=class r{constructor(e,t,n,o){this.b=e;this.id=t;this.state={progress:n.progress,ready:n.ready,voiceprint:G(n.voiceprint)},ce?.register(this,()=>void e.call("learnerClose",[t]).catch(()=>{}).finally(o))}state;static async create(e={}){let t=await d(["timbre"]),n=++q,o=t.hold();try{let a=await t.call("learnerOpen",[n,e.voiceprint?le(e.voiceprint):null]);return new r(t,n,a,o)}catch(a){throw o(),a}}get progress(){return this.state.progress}get ready(){return this.state.ready}get voiceprint(){return this.state.voiceprint}async offer(e){let t=await this.b.call("learnerOffer",[this.id,e]);return this.state={progress:t.progress,ready:t.ready,voiceprint:G(t.voiceprint)},{accepted:t.accepted,rejected:t.rejected,progress:t.progress,ready:t.ready}}forget(){this.state={progress:0,ready:!1,voiceprint:null},this.b.call("learnerForget",[this.id])}};export{j as a,Ne as b,D as c,H as d,Y as e,ae as f,se as g,ie as h,_ as i};
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{copyFile as T,mkdir as G,writeFile as I}from"node:fs/promises";import{dirname as W,join as w}from"node:path";import{fileURLToPath as J}from"node:url";var d=class extends Error{constructor(r,t,a){super(t);this.code=r;this.cause=a}name="AlkoveError"};var p="alkove-ai",k={focus:{name:"alkove-focus-1-preview",file:"alkove-focus-1-preview.alk",bytes:1111696,sha256:"a63cda32e023b8d76089f4c3df0cc2c69ba36017b8f6cdea1da1094ef8022b6a",revision:"8e91ef608366cf503fbd8aaa44bc2000dce899ed"},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-preview",file:"alkove-timbre-1-preview.alk",bytes:739632,sha256:"d498a7dd8b20528d783052b1e1d49e54ab7ee4e47aa12712d04f3d43edc68bd8",revision:"013f7c621e8687e992508b5fb01607eb17143550"},lex:{name:"alkove-lex-1-preview",file:"alkove-lex-1-preview.alk",bytes:1818020,sha256:"1e64ca9f5c2281cadae0f9c4a944cd1b1b433f0c0c29760c36340c97f7308957",revision:"9365b7c6aa1555a561548e5198d2becf7f7ffe00"}};var u={name:"alkove-engine",file:"alkove-engine.wasm",bytes:495093,sha256:"8c8966c15deffd6aa86b34f4f3c614271b90f0de0893facaaa082e695c3ffdf9"};var i=k;var N=e=>`${i[e].name}@${i[e].sha256.slice(0,12)}`,V={model:N("timbre"),window:24e3,min:280,dim:192};var P="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),r=>r.toString(16).padStart(2,"0")).join("")}var $=()=>typeof process<"u"&&!!process.versions?.node&&typeof window>"u",B=()=>typeof caches<"u"&&(typeof isSecureContext>"u"||isSecureContext);function D(e,o){let r=globalThis.location?.href;return new URL(o,new URL(String(e).replace(/\/?$/,"/"),r)).href}function A(e){if(l.modelBaseUrl)return D(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/${p}/${e.name}/resolve/${e.revision}/${e.file}`}async function L(e,o,r=0){let t;try{t=await fetch(e)}catch(f){throw new d("models.fetch",`fetch failed: ${e}`,f)}if(!t.ok||!t.body)throw new d("models.fetch",`HTTP ${t.status}: ${e}`);let a=Number(t.headers.get("content-length"))||r,s=t.body.getReader(),n=[],c=0;for(;;){let{done:f,value:b}=await s.read();if(f)break;n.push(b),c+=b.length,o?.({loaded:c,total:Math.max(a,c)})}let y=new Uint8Array(c),v=0;for(let f of n)y.set(f,v),v+=f.length;return y}async function m(e,o){let r=await C(o);if(r!==e.sha256)throw new d("models.hash",`${e.name}: sha256 ${r}, expected ${e.sha256} (truncated download, or a CDN that rewrites files)`);return o}async function h(e,o,r){return o instanceof ArrayBuffer?m(e,new Uint8Array(o)):o instanceof Uint8Array?m(e,o):m(e,await L(String(o),r,e.bytes))}async function j(e,o){if(!B())return o();let r;try{r=await caches.open(P)}catch{return o()}let t=g+e.sha256,a=await r.match(t).catch(()=>{});if(a){let n=new Uint8Array(await a.arrayBuffer());if(await C(n)===e.sha256)return S(r,e.sha256),n;await r.delete(t).catch(()=>{})}let s=await o();return await r.put(t,new Response(s,{headers:{"content-type":"application/octet-stream"}})).catch(()=>{}),S(r,e.sha256),s}async function S(e,o){try{let r=g+"used.json",t=await(await e.match(r))?.json().catch(()=>null)??{},a=Date.now();t[o]=a;for(let[s,n]of Object.entries(t))a-n>R*864e5&&(await e.delete(g+s),delete t[s]);await e.put(r,new Response(JSON.stringify(t),{headers:{"content-type":"application/json"}}))}catch{}}var H=e=>Object.entries(i).find(([,o])=>o===e)?.[0]??"engine";async function _(e,o,r){let t=l.models?.[H(e)]??r;if(t instanceof ArrayBuffer||t instanceof Uint8Array)return h(e,t);if($()){if(t&&String(t).startsWith("file:")){let{readFile:a}=await import("node:fs/promises");return m(e,new Uint8Array(await a(new URL(String(t)))))}if(l.modelDir){let{readFile:a}=await import("node:fs/promises"),{join:s}=await import("node:path");return m(e,new Uint8Array(await a(s(l.modelDir,e.file))))}return h(e,t??A(e),o)}return j(e,()=>h(e,t??A(e),o))}function F(e,o){return _(i[e],o)}var z=`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
|
|
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>;
|
package/dist/core/chain.d.ts
CHANGED
|
@@ -16,8 +16,10 @@ export interface ChainOptions {
|
|
|
16
16
|
normalize?: boolean;
|
|
17
17
|
strength?: number;
|
|
18
18
|
print?: ArrayLike<number> | null;
|
|
19
|
+
sample?: ArrayLike<number> | null;
|
|
19
20
|
speech?: Partial<SpeechParams>;
|
|
20
21
|
sleep?: boolean;
|
|
22
|
+
lowPower?: boolean;
|
|
21
23
|
}
|
|
22
24
|
export declare class Chain {
|
|
23
25
|
private alk;
|
package/dist/core/engine.d.ts
CHANGED
|
@@ -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'
|
|
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'
|
|
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
|
-
|
|
88
|
+
commands(spec: unknown, langs: readonly Lang[]): Value[];
|
|
89
|
+
net(model: 'timbre', plan?: string): Net;
|
|
78
90
|
release(): void;
|
|
79
91
|
}
|
package/dist/core/lex.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/core/native.d.ts
CHANGED
|
@@ -17,19 +17,36 @@ 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?:
|
|
48
|
+
spot?: NativeSpot;
|
|
49
|
+
timbre?: Model;
|
|
33
50
|
}, options: Value);
|
|
34
51
|
private part;
|
|
35
52
|
push(pcm: Float32Array): Record<string, unknown>;
|
|
@@ -40,7 +57,7 @@ export type HeardFrame = [number, number | null, number[], Record<string, unknow
|
|
|
40
57
|
export declare class NativeListener {
|
|
41
58
|
private alk;
|
|
42
59
|
private ptr;
|
|
43
|
-
constructor(alk: Alk, spot:
|
|
60
|
+
constructor(alk: Alk, spot: NativeSpot, words: Value[], context: string);
|
|
44
61
|
setWords(words: Value[], context: string): void;
|
|
45
62
|
push(pcm: Float32Array): HeardFrame[];
|
|
46
63
|
release(): void;
|
|
@@ -48,7 +65,7 @@ export declare class NativeListener {
|
|
|
48
65
|
export declare class NativeEnroller {
|
|
49
66
|
private alk;
|
|
50
67
|
private ptr;
|
|
51
|
-
constructor(alk: Alk, spot:
|
|
68
|
+
constructor(alk: Alk, spot: NativeSpot, word: Value, takes: number, chain: string);
|
|
52
69
|
push(pcm: Float32Array): {
|
|
53
70
|
takes: Record<string, unknown>[];
|
|
54
71
|
done: boolean;
|
|
@@ -109,10 +126,12 @@ export declare class NativePipeline {
|
|
|
109
126
|
constructor(alk: Alk, models: {
|
|
110
127
|
focus?: Model;
|
|
111
128
|
cue?: Model;
|
|
112
|
-
spot?:
|
|
129
|
+
spot?: NativeSpot;
|
|
113
130
|
}, options: Value);
|
|
114
131
|
step(hop: Float32Array, farQuietMs: number): Float32Array;
|
|
115
|
-
|
|
132
|
+
spent(ms: number): void;
|
|
133
|
+
spot(s: NativeSpot): void;
|
|
134
|
+
timbre(model: Model): void;
|
|
116
135
|
raw(hop: Float32Array): void;
|
|
117
136
|
outs(): PipelineOut[];
|
|
118
137
|
verified(key: number, same: boolean, score: number): void;
|
package/dist/core/spot/spot.d.ts
CHANGED
|
@@ -43,9 +43,9 @@ 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
|
-
chain?: Chain;
|
|
49
49
|
}
|
|
50
50
|
export interface Take {
|
|
51
51
|
score: number;
|
|
@@ -64,3 +64,42 @@ export interface WakeEvent {
|
|
|
64
64
|
audio?: Float32Array;
|
|
65
65
|
voice?: number;
|
|
66
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
|
+
}
|
package/dist/engine/alk.d.ts
CHANGED
|
@@ -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
|
-
alk_processor(focus: number, cue: number, spot: number): number;
|
|
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(
|
|
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(
|
|
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,9 @@ 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
|
-
|
|
78
|
+
alk_pipeline_spent(p: number, ms: number): void;
|
|
79
|
+
alk_pipeline_spot(p: number, s: number): number;
|
|
80
|
+
alk_pipeline_timbre(p: number, m: number): number;
|
|
71
81
|
alk_pipeline_outs(p: number): number;
|
|
72
82
|
alk_pipeline_pending(p: number): number;
|
|
73
83
|
alk_pipeline_verified(p: number, key: number, same: number, score: number): void;
|
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
|
@@ -2,9 +2,9 @@ export { Alkove, Lex, Spot, Timbre, VoiceprintLearner } from './api';
|
|
|
2
2
|
export type { ProcessInput, StreamSource, Usage, UsageOptions } from './api';
|
|
3
3
|
export type { Enrollment } from './recipes/enroll';
|
|
4
4
|
export type { Take } from './core/spot/spot';
|
|
5
|
-
export type {
|
|
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{
|
|
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};
|
package/dist/loader.d.ts
CHANGED
package/dist/manifest.d.ts
CHANGED
|
@@ -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' |
|
|
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;
|
|
@@ -31,10 +31,11 @@ export declare const TIMBRE: {
|
|
|
31
31
|
model: string;
|
|
32
32
|
window: number;
|
|
33
33
|
min: number;
|
|
34
|
+
max: number;
|
|
34
35
|
dim: number;
|
|
35
36
|
};
|
|
36
37
|
export declare const LEX: {
|
|
37
|
-
langs: readonly ["fr", "en", "es", "pt", "it", "ca", "ro"];
|
|
38
|
+
langs: readonly ["fr", "en", "es", "pt", "it", "ca", "ro", "de", "nl", "pl", "sv"];
|
|
38
39
|
beams: number;
|
|
39
40
|
bos: number;
|
|
40
41
|
eos: number;
|
|
@@ -43,3 +44,5 @@ export declare const LEX: {
|
|
|
43
44
|
steps: number;
|
|
44
45
|
};
|
|
45
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};
|