PageSourceSearch

https://crushchat.app/_next/static/chunks/6345.bbc6e420173b722a.js

js crushchat.app collected 2026-10-04 06:55:51 UTC 69,188 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6345],{20629:(t,r,o)=>{t.exports=(()=>{var t,r,a,i,s,n,l,u,d,p,c,f,h,m,g,y,w,b,v,E,S,A,T,_,O,P,M,C,R,F,D,U,x,L=Object.defineProperty,I=Object.getOwnPropertyDescriptor,B=Object.getOwnPropertyNames,N=Object.prototype.hasOwnProperty,k=o(96299),$=(t,r)=>()=>(t&&(r=t(t=0)),r),j=(t,r)=>{for(var o in r)L(t,o,{get:r[o],enumerable:!0})},V=t=>((t,r,o,a)=>{if(r&&"object"==typeof r||"function"==typeof r)for(let o of B(r))N.call(t,o)||void 0===o||L(t,o,{get:()=>r[o],enumerable:!(a=I(r,o))||a.enumerable});return t})(L({},"__esModule",{value:!0}),t),G=$(()=>{t=new Map,r=[],a=(o,a,i)=>{if(a&&"function"==typeof a.init&&"function"==typeof a.createInferenceSessionHandler){let s=t.get(o);if(void 0===s)t.set(o,{backend:a,priority:i});else{if(s.priority>i)return;if(s.priority===i&&s.backend!==a)throw Error(`cannot register backend "${o}" using priority ${i}`)}if(i>=0){let a=r.indexOf(o);-1!==a&&r.splice(a,1);for(let a=0;a<r.length;a++)if(t.get(r[a]).priority<=i)return void r.splice(a,0,o);
1r.push(o)}return}throw TypeError("not a valid backend")},i=async r=>{let o=t.get(r);if(!o)return"backend not found.";if(o.initialized)return o.backend;if(o.aborted)return o.error;{let t=!!o.initPromise;try{return t||(o.initPromise=o.backend.init(r)),await o.initPromise,o.initialized=!0,o.backend}catch(r){return t||(o.error=`${r}`,o.aborted=!0),o.error}finally{delete o.initPromise}}},s=async t=>{let o=t.executionProviders||[],a=o.map(t=>"string"==typeof t?t:t.name),s=0===a.length?r:a,n,l=[],u=new Set;for(let t of s){let r=await i(t);"string"==typeof r?l.push({name:t,err:r}):(n||(n=r),n===r&&u.add(t))}if(!n)throw Error(`no available backend found. ERR: ${l.map(t=>`[${t.name}] ${t.err}`).join(", ")}`);for(let{name:t,err:r}of l)a.includes(t)&&console.warn(`removing requested execution provider "${t}" from session options because it is not available: ${r}`);let d=o.filter(t=>u.has("string"==typeof t?t:t.name));return[n,new Proxy(t,{get:(t,r)=>"executionProviders"===r?d:Reflect.get(t,r)})]}}),W=$(()=>{G()}),z=$(()=>{n="1.27.0"}),H=$(()=>{z(),l="warning",Object.defineProperty(u={wasm:{},webgl:{},webgpu:{},versions:{common:n},set logLevel(e){if(void 0!==e){if("string"!=typeof e||-1===["verbose","info","warning","error","fatal"].indexOf(e))throw Error(`Unsupported logging level: ${e}`);l=e}},get logLevel(){return l}},"logLevel",{enumerable:!0})}),q=$(()=>{H(),d=u}),Z=$(()=>{p=(t,r)=>{let o="u">typeof document?document.createElement("canvas"):new OffscreenCanvas(1,1);o.width=t.dims[3],o.height=t.dims[2];let a=o.getContext("2d");if(null!=a){let i,s;r?.tensorLayout!==void 0&&"NHWC"===r.tensorLayout?(i=t.dims[2],s=t.dims[3]):(i=t.dims[3],s=t.dims[2]);let n=r?.format!==void 0?r.format:"RGB",l=r?.norm,u,d;void 0===l||void 0===l.mean?u=[255,255,255,255]:"number"==typeof l.mean?u=[l.mean,l.mean,l.mean,l.mean]:(u=[l.mean[0],l.mean[1],l.mean[2],0],void 0!==l.mean[3]&&(u[3]=l.mean[3])),void 0===l||void 0===l.bias?d=[0,0,0,0]:"number"==typeof l.bias?d=[l.bias,l.bias,l.bias,l.bias]:(d=[l.bias[0],l.bias[1],l.bias[2],0],void 0!==l.bias[3]&&(d[3]=l.bias[3]));let p=s*i,c=0,f=p,h=2*p,m=-1;"RGBA"===n?(c=0,f=p,h=2*p,m=3*p):"RGB"===n?(c=0,f=p,h=2*p):"RBG"===n&&(c=0,h=p,f=2*p);for(let r=0;r<s;r++)for(let o=0;o<i;o++)a.fillStyle="rgba("+(t.data[c++]-d[0])*u[0]+","+(t.data[f++]-d[1])*u[1]+","+(t.data[h++]-d[2])*u[2]+","+(-1===m?255:(t.data[m++]-d[3])*u[3])+")",a.fillRect(o,r,1,1);if("toDataURL"in o)return o.toDataURL();throw Error("toDataURL is not supported")}throw Error("Can not access image data")},c=(t,r)=>{let o="u">typeof document?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),a;if(null!=o){let i,s,n;r?.tensorLayout!==void 0&&"NHWC"===r.tensorLayout?(i=t.dims[2],s=t.dims[1],n=t.dims[3]):(i=t.dims[3],s=t.dims[2],n=t.dims[1]);let l=void 0!==r&&void 0!==r.format?r.format:"RGB",u=r?.norm,d,p;void 0===u||void 0===u.mean?d=[255,255,255,255]:"number"==typeof u.mean?d=[u.mean,u.mean,u.mean,u.mean]:(d=[u.mean[0],u.mean[1],u.mean[2],255],void 0!==u.mean[3]&&(d[3]=u.mean[3])),void 0===u||void 0===u.bias?p=[0,0,0,0]:"number"==typeof u.bias?p=[u.bias,u.bias,u.bias,u.bias]:(p=[u.bias[0],u.bias[1],u.bias[2],0],void 0!==u.bias[3]&&(p[3]=u.bias[3]));let c=s*i;if(void 0!==r&&(void 0!==r.format&&4===n&&"RGBA"!==r.format||3===n&&"RGB"!==r.format&&"BGR"!==r.format))throw Error("Tensor format doesn't match input tensor dims");let f=0,h=1,m=2,g=3,y=0,w=c,b=2*c,v=-1;"RGBA"===l?(y=0,w=c,b=2*c,v=3*c):"RGB"===l?(y=0,w=c,b=2*c):"RBG"===l&&(y=0,b=c,w=2*c),a=o.createImageData(i,s);for(let r=0;r<s*i;f+=4,h+=4,m+=4,g+=4,r++)a.data[f]=(t.data[y++]-p[0])*d[0],a.data[h]=(t.data[w++]-p[1])*d[1],a.data[m]=(t.data[b++]-p[2])*d[2],a.data[g]=-1===v?255:(t.data[v++]-p[3])*d[3]}else throw Error("Can not access image data");return a}}),J=$(()=>{Q(),f=(t,r)=>{if(void 0===t)throw Error("Image buffer must be defined");if(void 0===r.height||void 0===r.width)throw Error("Image height and width must be defined");if("NHWC"===r.tensorLayout)throw Error("NHWC Tensor layout is not supported yet");let{height:o,width:a}=r,i=r.norm??{mean:255,bias:0},s,n;s="number"==typeof i.mean?[i.mean,i.mean,i.mean,i.mean]:[i.mean[0],i.mean[1],i.mean[2],i.mean[3]??255],n="number"==typeof i.bias?[i.bias,i.bias,i.bias,i.bias]:[i.bias[0],i.bias[1],i.bias[2],i.bias[3]??0];let l=void 0!==r.format?r.format:"RGBA",u=void 0!==r.tensorFormat&&void 0!==r.tensorFormat?r.tensorFormat:"RGB",d=o*a,p=new Float32Array("RGBA"===u?4*d:3*d),c=4,f=0,h=1,m=2,g=3,y=0,w=d,b=2*d,v=-1;"RGB"===l&&(c=3,f=0,h=1,m=2,g=-1),"RGBA"===u?v=3*d:"RBG"===u?(y=0,b=d,w=2*d):"BGR"===u&&(b=0,w=d,y=2*d);for(let r=0;r<d;r++,f+=c,m+=c,h+=c,g+=c)p[y++]=(t[f]+n[0])/s[0],p[w++]=(t[h]+n[1])/s[1],p[b++]=(t[m]+n[2])/s[2],-1!==v&&-1!==g&&(p[v++]=(t[g]+n[3])/s[3]);return"RGBA"===u?new _("float32",p,[1,4,o,a]):new _("float32",p,[1,3,o,a])},h=async(t,r)=>{let o="u">typeof HTMLImageElement&&t instanceof HTMLImageElement,a="u">typeof ImageData&&t instanceof ImageData,i="u">typeof ImageBitmap&&t instanceof ImageBitmap,s="string"==typeof t,n,l=r??{},u=()=>{if("u">typeof document)return document.createElement("canvas");if("u">typeof OffscreenCanvas)return new OffscreenCanvas(1,1);throw Error("Canvas is not supported")},d=t=>"u">typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||t instanceof OffscreenCanvas?t.getContext("2d"):null;if(o){let o=u();o.width=t.width,o.height=t.height;let a=d(o);if(null!=a){let o=t.height,i=t.width;if(void 0!==r&&void 0!==r.resizedHeight&&void 0!==r.resizedWidth&&(o=r.resizedHeight,i=r.resizedWidth),void 0!==r){if(l=r,void 0!==r.tensorFormat)throw Error("Image input config format must be RGBA for HTMLImageElement");l.tensorFormat="RGBA",l.height=o,l.width=i}else l.tensorFormat="RGBA",l.height=o,l.width=i;a.drawImage(t,0,0),n=a.getImageData(0,0,i,o).data}else throw Error("Can not access image data")}else if(a){let o,a;if(void 0!==r&&void 0!==r.resizedWidth&&void 0!==r.resizedHeight?(o=r.resizedHeight,a=r.resizedWidth):(o=t.height,a=t.width),void 0!==r&&(l=r),l.format="RGBA",l.height=o,l.width=a,void 0!==r){let r=u();r.width=a,r.height=o;let i=d(r);if(null!=i)i.putImageData(t,0,0),n=i.getImageData(0,0,a,o).data;else throw Error("Can not access image data")}else n=t.data}else if(i){if(void 0===r)throw Error("Please provide image config with format for Imagebitmap");let o=u();o.width=t.width,o.height=t.height;let a=d(o);if(null!=a){let r=t.height,o=t.width;return a.drawImage(t,0,0,o,r),n=a.getImageData(0,0,o,r).data,l.height=r,l.width=o,f(n,l)}throw Error("Can not access image data")}else{if(s)return new Promise((r,o)=>{let a=u(),i=d(a);if(!t||!i)return o();let s=new Image;s.crossOrigin="Anonymous",s.src=t,s.onload=()=>{a.width=s.width,a.height=s.height,i.drawImage(s,0,0,a.width,a.height);let t=i.getImageData(0,0,a.width,a.height);l.height=a.height,l.width=a.width,r(f(t.data,l))}});throw Error("Input data provided is not supported - aborted tensor creation")}if(void 0!==n)return f(n,l);throw Error("Input data provided is not supported - aborted tensor creation")},m=(t,r)=>{let{width:o,height:a,download:i,dispose:s}=r;return new _({location:"texture",type:"float32",texture:t,dims:[1,a,o,4],download:i,dispose:s})},g=(t,r)=>{let{dataType:o,dims:a,download:i,dispose:s}=r;return new _({location:"gpu-buffer",type:o??"float32",gpuBuffer:t,dims:a,download:i,dispose:s})},y=(t,r)=>{let{dataType:o,dims:a,download:i,dispose:s}=r;return new _({location:"ml-tensor",type:o??"float32",mlTensor:t,dims:a,download:i,dispose:s})},w=(t,r,o)=>new _({location:"cpu-pinned",type:t,data:r,dims:o??[r.length]})}),Y=$(()=>{b=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array
1],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),v=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),E=!1,S=()=>{if(!E){E=!0;let t="u">typeof BigInt64Array&&BigInt64Array.from,r="u">typeof BigUint64Array&&BigUint64Array.from,o=globalThis.Float16Array,a="u">typeof o&&o.from;t&&(b.set("int64",BigInt64Array),v.set(BigInt64Array,"int64")),r&&(b.set("uint64",BigUint64Array),v.set(BigUint64Array,"uint64")),a?(b.set("float16",o),v.set(o,"float16")):b.set("float16",Uint16Array)}}}),K=$(()=>{Q(),A=t=>{let r=1;for(let o=0;o<t.length;o++){let a=t[o];if("number"!=typeof a||!Number.isSafeInteger(a))throw TypeError(`dims[${o}] must be an integer, got: ${a}`);if(a<0)throw RangeError(`dims[${o}] must be a non-negative integer, got: ${a}`);r*=a}return r},T=(t,r)=>{switch(t.location){case"cpu":return new _(t.type,t.data,r);case"cpu-pinned":return new _({location:"cpu-pinned",data:t.data,type:t.type,dims:r});case"texture":return new _({location:"texture",texture:t.texture,type:t.type,dims:r});case"gpu-buffer":return new _({location:"gpu-buffer",gpuBuffer:t.gpuBuffer,type:t.type,dims:r});case"ml-tensor":return new _({location:"ml-tensor",mlTensor:t.mlTensor,type:t.type,dims:r});default:throw Error(`tensorReshape: tensor location ${t.location} is not supported`)}}}),Q=$(()=>{Z(),J(),Y(),K(),_=class{constructor(t,r,o){let a,i;if(S(),"object"==typeof t&&"location"in t)switch(this.dataLocation=t.location,a=t.type,i=t.dims,t.location){case"cpu-pinned":{let r=b.get(a);if(!r)throw TypeError(`unsupported type "${a}" to create tensor from pinned buffer`);if(!(t.data instanceof r))throw TypeError(`buffer should be of type ${r.name}`);this.cpuData=t.data;break}case"texture":if("float32"!==a)throw TypeError(`unsupported type "${a}" to create tensor from texture`);this.gpuTextureData=t.texture,this.downloader=t.download,this.disposer=t.dispose;break;case"gpu-buffer":if("float32"!==a&&"float16"!==a&&"int32"!==a&&"int64"!==a&&"uint32"!==a&&"uint8"!==a&&"bool"!==a&&"uint4"!==a&&"int4"!==a)throw TypeError(`unsupported type "${a}" to create tensor from gpu buffer`);this.gpuBufferData=t.gpuBuffer,this.downloader=t.download,this.disposer=t.dispose;break;case"ml-tensor":if("float32"!==a&&"float16"!==a&&"int32"!==a&&"int64"!==a&&"uint32"!==a&&"uint64"!==a&&"int8"!==a&&"uint8"!==a&&"bool"!==a&&"uint4"!==a&&"int4"!==a)throw TypeError(`unsupported type "${a}" to create tensor from MLTensor`);this.mlTensorData=t.mlTensor,this.downloader=t.download,this.disposer=t.dispose;break;default:throw Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let s,n;if("string"==typeof t)if(a=t,n=o,"string"===t){if(!Array.isArray(r))throw TypeError("A string tensor's data must be a string array.");s=r}else{let o=b.get(t);if(void 0===o)throw TypeError(`Unsupported tensor type: ${t}.`);if(Array.isArray(r)){if("float16"===t&&o===Uint16Array||"uint4"===t||"int4"===t)throw TypeError(`Creating a ${t} tensor from number array is not supported. Please use ${o.name} as data.`);s="uint64"===t||"int64"===t?o.from(r,BigInt):o.from(r)}else if(r instanceof o)s=r;else if(r instanceof Uint8ClampedArray)if("uint8"===t)s=Uint8Array.from(r);else throw TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else if("float16"===t&&r instanceof Uint16Array&&o!==Uint16Array)s=new globalThis.Float16Array(r.buffer,r.byteOffset,r.length);else throw TypeError(`A ${a} tensor's data must be type of ${o}`)}else if(n=r,Array.isArray(t)){if(0===t.length)throw TypeError("Tensor type cannot be inferred from an empty array.");let r=typeof t[0];if("string"===r)a="string",s=t;else if("boolean"===r)a="bool",s=Uint8Array.from(t);else throw TypeError(`Invalid element type of data array: ${r}.`)}else if(t instanceof Uint8ClampedArray)a="uint8",s=Uint8Array.from(t);else{let r=v.get(t.constructor);if(void 0===r)throw TypeError(`Unsupported type for tensor data: ${t.constructor}.`);a=r,s=t}if(void 0===n)n=[s.length];else if(!Array.isArray(n))throw TypeError("A tensor's dims must be a number array");i=n,this.cpuData=s,this.dataLocation="cpu"}let s=A(i);if(this.cpuData&&s!==this.cpuData.length&&("uint4"!==a&&"int4"!==a||Math.ceil(s/2)!==this.cpuData.length))throw Error(`Tensor's size(${s}) does not match data length(${this.cpuData.length}).`);this.type=a,this.dims=i,this.size=s}static async fromImage(t,r){return h(t,r)}static fromTexture(t,r){return m(t,r)}static fromGpuBuffer(t,r){return g(t,r)}static fromMLTensor(t,r){return y(t,r)}static fromPinnedBuffer(t,r,o){return w(t,r,o)}toDataURL(t){return p(this,t)}toImageData(t){return c(this,t)}get data(){if(this.ensureValid(),!this.cpuData)throw Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw Error("The data is not stored as a WebGL texture.");return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw Error("The data is not stored as a WebGPU buffer.");return this.gpuBufferData}get mlTensor(){if(this.ensureValid(),!this.mlTensorData)throw Error("The data is not stored as a WebNN MLTensor.");return this.mlTensorData}async getData(t){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":case"ml-tensor":if(!this.downloader)throw Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw Error("The current tensor is being downloaded.");try{this.isDownloading=!0;let r=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=r,t&&this.disposer&&(this.disposer(),this.disposer=void 0),r}finally{this.isDownloading=!1}default:throw Error(`cannot get data from location: ${this.dataLocation}`)}}dispose(){if(this.isDownloading)throw Error("The current tensor is being downloaded.");this.disposer&&(this.disposer(),this.disposer=void 0),this.cpuData=void 0,this.gpuTextureData=void 0,this.gpuBufferData=void 0,this.mlTensorData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if("none"===this.dataLocation)throw Error("The tensor is disposed.")}reshape(t){if(this.ensureValid(),this.downloader||this.disposer)throw Error("Cannot reshape a tensor that owns GPU resource.");return T(this,t)}}}),X=$(()=>
1{Q(),O=_}),ee=$(()=>{H(),P=(t,r)=>{(typeof u.trace>"u"?u.wasm.trace:u.trace)&&console.timeStamp(`${t}::ORT::${r}`)},M=(t,r)=>{let o=Error().stack?.split(/\r\n|\r|\n/g)||[],a=!1;for(let i=0;i<o.length;i++){if(a&&!o[i].includes("TRACE_FUNC")){let a=`FUNC_${t}::${o[i].trim().split(" ")[1]}`;r&&(a+=`::${r}`),P("CPU",a);return}o[i].includes("TRACE_FUNC")&&(a=!0)}},C=t=>{(typeof u.trace>"u"?u.wasm.trace:u.trace)&&M("BEGIN",t)},R=t=>{(typeof u.trace>"u"?u.wasm.trace:u.trace)&&M("END",t)},F=t=>{(typeof u.trace>"u"?u.wasm.trace:u.trace)&&console.time(`ORT::${t}`)},D=t=>{(typeof u.trace>"u"?u.wasm.trace:u.trace)&&console.timeEnd(`ORT::${t}`)}}),et=$(()=>{G(),X(),ee(),U=class t{constructor(t){this.handler=t}async run(t,r,o){C(),F("InferenceSession.run");let a={},i={};if("object"!=typeof t||null===t||t instanceof O||Array.isArray(t))throw TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let s=!0;if("object"==typeof r){if(null===r)throw TypeError("Unexpected argument[1]: cannot be null.");if(r instanceof O)throw TypeError("'fetches' cannot be a Tensor");if(Array.isArray(r)){if(0===r.length)throw TypeError("'fetches' cannot be an empty array.");for(let t of(s=!1,r)){if("string"!=typeof t)throw TypeError("'fetches' must be a string array or an object.");if(-1===this.outputNames.indexOf(t))throw RangeError(`'fetches' contains invalid output name: ${t}.`);a[t]=null}if("object"==typeof o&&null!==o)i=o;else if("u">typeof o)throw TypeError("'options' must be an object.")}else{let t=!1,n=Object.getOwnPropertyNames(r);for(let o of this.outputNames)if(-1!==n.indexOf(o)){let i=r[o];(null===i||i instanceof O)&&(t=!0,s=!1,a[o]=i)}if(t){if("object"==typeof o&&null!==o)i=o;else if("u">typeof o)throw TypeError("'options' must be an object.")}else i=r}}else if("u">typeof r)throw TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let r of this.inputNames)if(typeof t[r]>"u")throw Error(`input '${r}' is missing in 'feeds'.`);if(s)for(let t of this.outputNames)a[t]=null;let n=await this.handler.run(t,a,i),l={};for(let t in n)if(Object.hasOwnProperty.call(n,t)){let r=n[t];r instanceof O?l[t]=r:l[t]=new O(r.type,r.data,r.dims)}return D("InferenceSession.run"),R(),l}async release(){return this.handler.dispose()}static async create(r,o,a,i){C(),F("InferenceSession.create");let n,l={};if("string"==typeof r){if(n=r,"object"==typeof o&&null!==o)l=o;else if("u">typeof o)throw TypeError("'options' must be an object.")}else if(r instanceof Uint8Array){if(n=r,"object"==typeof o&&null!==o)l=o;else if("u">typeof o)throw TypeError("'options' must be an object.")}else if(r instanceof ArrayBuffer||"u">typeof SharedArrayBuffer&&r instanceof SharedArrayBuffer){let t=0,s=r.byteLength;if("object"==typeof o&&null!==o)l=o;else if("number"==typeof o){if(!Number.isSafeInteger(t=o))throw RangeError("'byteOffset' must be an integer.");if(t<0||t>=r.byteLength)throw RangeError(`'byteOffset' is out of range [0, ${r.byteLength}).`);if(s=r.byteLength-t,"number"==typeof a){if(!Number.isSafeInteger(s=a))throw RangeError("'byteLength' must be an integer.");if(s<=0||t+s>r.byteLength)throw RangeError(`'byteLength' is out of range (0, ${r.byteLength-t}].`);if("object"==typeof i&&null!==i)l=i;else if("u">typeof i)throw TypeError("'options' must be an object.")}else if("u">typeof a)throw TypeError("'byteLength' must be a number.")}else if("u">typeof o)throw TypeError("'options' must be an object.");n=new Uint8Array(r,t,s)}else throw TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[u,d]=await s(l),p=await u.createInferenceSessionHandler(n,d);return D("InferenceSession.create"),R(),new t(p)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}get inputMetadata(){return this.handler.inputMetadata}get outputMetadata(){return this.handler.outputMetadata}}}),er=$(()=>{et(),x=U}),eo=$(()=>{}),ea=$(()=>{}),ei=$(()=>{}),es=$(()=>{}),en={};j(en,{InferenceSession:()=>x,TRACE:()=>P,TRACE_EVENT_BEGIN:()=>F,TRACE_EVENT_END:()=>D,TRACE_FUNC_BEGIN:()=>C,TRACE_FUNC_END:()=>R,Tensor:()=>O,env:()=>d,registerBackend:()=>a});var el=$(()=>{W(),q(),er(),X(),eo(),ea(),ee(),ei(),es()}),eu=$(()=>{}),ed={};j(ed,{default:()=>ec});var ep,ec,ef,eh,em,eg,ey,ew,eb,ev,eE,eS,eA,eT,e_,eO,eP,eM,eC,eR,eF,eD,eU,ex,eL,eI,eB,eN,ek,e$,ej,eV,eG,eW,ez,eH,eq,eZ,eJ,eY,eK,eQ,eX,e0,e1,e2,e3,e6,e4,e8,e5,e9,e7,te,tt,tr,to,ta,ti,ts,tn,tl,tu,td,tp,tc,tf=$(()=>{tE(),tm(),th(),(ep=globalThis.self?.name==="ort-wasm-proxy-worker")&&(self.onmessage=t=>{let{type:r,in:o}=t.data;
1try{switch(r){case"init-wasm":eP(o.wasm).then(()=>{ez(o).then(()=>{postMessage({type:r})},t=>{postMessage({type:r,err:t})})},t=>{postMessage({type:r,err:t})});break;case"init-ep":{let{epName:t,env:a}=o;eH(a,t).then(()=>{postMessage({type:r})},t=>{postMessage({type:r,err:t})});break}case"copy-from":{let{buffer:t}=o,a=eJ(t);postMessage({type:r,out:a});break}case"create":{let{model:t,options:a}=o;eY(t,a).then(t=>{postMessage({type:r,out:t})},t=>{postMessage({type:r,err:t})});break}case"release":eK(o),postMessage({type:r});break;case"run":{let{sessionId:t,inputIndices:a,inputs:i,outputIndices:s,options:n}=o;eX(t,a,i,s,Array(s.length).fill(null),n).then(t=>{t.some(t=>"cpu"!==t[3])?postMessage({type:r,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:r,out:t},e1([...i,...t]))},t=>{postMessage({type:r,err:t})});break}case"end-profiling":e0(o),postMessage({type:r})}}catch(t){postMessage({type:r,err:t})}}),ec=ep?null:t=>new Worker(t??eh,{type:"classic",name:"ort-wasm-proxy-worker"})}),th=$(()=>{eu(),ef=typeof location>"u"?void 0:location.origin,eh="u">typeof document?document.currentScript?.src:"u">typeof self?self.location?.href:void 0,em=()=>{if(eh&&!eh.startsWith("blob:"))return eh.substring(0,eh.lastIndexOf("/")+1)},eg=(t,r)=>{try{let o=r??eh;return(o?new URL(t,o):new URL(t)).origin===ef}catch{return!1}},ey=async t=>{let r=await (await fetch(t,{credentials:"same-origin"})).blob();return URL.createObjectURL(r)},ew=async t=>(await import(t)).default,eb=(tf(),V(ed)).default,ev=async()=>{if(!eh)throw Error("Failed to load proxy worker: cannot determine the script source URL.");if(eg(eh))return[void 0,eb()];let t=await ey(eh);return[t,eb(t)]},eE=void 0,eS=async(t,r,o,a)=>{let i=eE&&!(t||r);if(i)if(eh)i=eg(eh)||a&&!o;else if(a&&!o)i=!0;else throw Error("cannot determine the script source URL.");if(i)return[void 0,eE];{let a,i,s="ort-wasm-simd-threaded.mjs",n=t??((t,r)=>{let o=r??eh;try{return(o?new URL(t,o):new URL(t)).href}catch{return}})(s,r),l=o&&n&&!eg(n,r),u=l?await ey(n):n??(a=s,i=r,`${i??"./"}${a}`);return[l?u:void 0,await ew(u)]}}}),tm=$(()=>{th(),eT=!1,e_=!1,eO=!1,eP=async t=>{if(eT)return Promise.resolve();if(e_)throw Error("multiple calls to 'initializeWebAssembly()' detected.");if(eO)throw Error("previous call to 'initializeWebAssembly()' failed.");e_=!0;let r=t.initTimeout,o=t.numThreads;if(!1!==t.simd){if("relaxed"===t.simd){if(!(()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,19,1,17,0,65,1,253,15,65,2,253,15,65,3,253,15,253,147,2,11]))}catch{return!1}})())throw Error("Relaxed WebAssembly SIMD is not supported in the current environment.")}else if(!(()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,30,1,28,0,65,0,253,15,253,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,253,186,1,26,11]))}catch{return!1}})())throw Error("WebAssembly SIMD is not supported in the current environment.")}let a=(()=>{if(typeof SharedArrayBuffer>"u")return!1;try{return"u">typeof MessageChannel&&new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]))}catch{return!1}})();o>1&&!a&&("u">typeof self&&!self.crossOriginIsolated&&console.warn("env.wasm.numThreads is set to "+o+", but this will not work unless you enable crossOriginIsolated mode. See https://web.dev/cross-origin-isolation-guide/ for more info."),console.warn("WebAssembly multi-threading is not supported in the current environment. Falling back to single-threading."),t.numThreads=o=1);let i=t.wasmPaths,s="string"==typeof i?i:void 0,n=i?.mjs,l=n?.href??n,u=i?.wasm,d=u?.href??u,p=t.wasmBinary,[c,f]=await eS(l,s,o>1,!!p||!!d),h=!1,m=[];if(r>0&&m.push(new Promise(t=>{setTimeout(()=>{h=!0,t()},r)})),m.push(new Promise((t,r)=>{let a={numThreads:o};if(p)a.wasmBinary=p,a.locateFile=t=>t;else if(d||s)a.locateFile=t=>d??s+t;else if(l&&0!==l.indexOf("blob:"))a.locateFile=t=>new URL(t,l).href;else if(c){let t=em();t&&(a.locateFile=r=>t+r)}f(a).then(r=>{e_=!1,eT=!0,eA=r,t(),c&&URL.revokeObjectURL(c)},t=>{e_=!1,eO=!0,r(t)})})),await Promise.race(m),h)throw Error(`WebAssembly backend initializing failed due to timeout: ${r}ms`)},eM=()=>
1{if(eT&&eA)return eA;throw Error("WebAssembly is not initialized yet.")}}),tg=$(()=>{tm(),eC=(t,r)=>{let o=eM(),a=o.lengthBytesUTF8(t)+1,i=o._malloc(a);return o.stringToUTF8(t,i,a),r.push(i),i},eR=(t,r,o,a)=>{if("object"==typeof t&&null!==t){if(o.has(t))throw Error("Circular reference in options");o.add(t)}Object.entries(t).forEach(([t,i])=>{let s=r?r+t:t;if("object"==typeof i)eR(i,s+".",o,a);else if("string"==typeof i||"number"==typeof i)a(s,i.toString());else if("boolean"==typeof i)a(s,i?"1":"0");else throw Error(`Can't handle extra config type: ${typeof i}`)})},eF=t=>{let r=eM(),o=r.stackSave();try{let o=r.PTR_SIZE,a=r.stackAlloc(2*o);r._OrtGetLastError(a,a+o);let i=Number(r.getValue(a,4===o?"i32":"i64")),s=r.getValue(a+o,"*"),n=s?r.UTF8ToString(s):"";throw Error(`${t} ERROR_CODE: ${i}, ERROR_MESSAGE: ${n}`)}finally{r.stackRestore(o)}}}),ty=$(()=>{tm(),tg(),eD=t=>{let r=eM(),o=0,a=[],i=t||{};try{if(t?.logSeverityLevel===void 0)i.logSeverityLevel=2;else if("number"!=typeof t.logSeverityLevel||!Number.isInteger(t.logSeverityLevel)||t.logSeverityLevel<0||t.logSeverityLevel>4)throw Error(`log severity level is not valid: ${t.logSeverityLevel}`);if(t?.logVerbosityLevel===void 0)i.logVerbosityLevel=0;else if("number"!=typeof t.logVerbosityLevel||!Number.isInteger(t.logVerbosityLevel))throw Error(`log verbosity level is not valid: ${t.logVerbosityLevel}`);t?.terminate===void 0&&(i.terminate=!1);let s=0;return t?.tag!==void 0&&(s=eC(t.tag,a)),o=r._OrtCreateRunOptions(i.logSeverityLevel,i.logVerbosityLevel,!!i.terminate,s),0===o&&eF("Can't create run options."),t?.extra!==void 0&&eR(t.extra,"",new WeakSet,(t,i)=>{let s=eC(t,a),n=eC(i,a);0!==r._OrtAddRunConfigEntry(o,s,n)&&eF(`Can't set a run config entry: ${t} - ${i}.`)}),[o,a]}catch(t){throw 0!==o&&r._OrtReleaseRunOptions(o),a.forEach(t=>r._free(t)),t}}}),tw=$(()=>{tm(),tg(),eU=(t,r,o,a)=>{let i=eC(r,a),s=eC(o,a);0!==eM()._OrtAddSessionConfigEntry(t,i,s)&&eF(`Can't set a session config entry: ${r} - ${o}.`)},ex=async(t,r,o)=>{for(let a of r.executionProviders){let r="string"==typeof a?a:a.name,i=[];switch(r){case"webnn":if(r="WEBNN",eU(t,"session.disable_quant_qdq","1",o),eU(t,"session.disable_qdq_constant_folding","1",o),"string"!=typeof a){let r=a?.deviceType;r&&eU(t,"deviceType",r,o)}break;case"webgpu":if(r="JS","string"!=typeof a&&a?.preferredLayout){if("NCHW"!==a.preferredLayout&&"NHWC"!==a.preferredLayout)throw Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${a.preferredLayout}`);eU(t,"preferredLayout",a.preferredLayout,o)}break;case"wasm":case"cpu":continue;default:throw Error(`not supported execution provider: ${r}`)}let s=eC(r,o),n=i.length,l=0,u=0;if(n>0){l=eM()._malloc(n*eM().PTR_SIZE),o.push(l),u=eM()._malloc(n*eM().PTR_SIZE),o.push(u);for(let t=0;t<n;t++)eM().setValue(l+t*eM().PTR_SIZE,i[t][0],"*"),eM().setValue(u+t*eM().PTR_SIZE,i[t][1],"*")}await eM()._OrtAppendExecutionProvider(t,s,l,u,n)!==0&&eF(`Can't append execution provider: ${r}.`)}},eL=async t=>{let r=eM(),o=0,a=[],i=t||{};(t=>{t.extra||(t.extra={}),t.extra.session||(t.extra.session={});let r=t.extra.session;r.use_ort_model_bytes_directly||(r.use_ort_model_bytes_directly="1"),t.executionProviders&&t.executionProviders.some(t=>("string"==typeof t?t:t.name)==="webgpu")&&(t.enableMemPattern=!1)})(i);try{let t=(t=>{switch(t){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"layout":return 3;case"all":return 99;default:throw Error(`unsupported graph optimization level: ${t}`)}})(i.graphOptimizationLevel??"all"),s=(t=>{switch(t){case"sequential":return 0;case"parallel":return 1;default:throw Error(`unsupported execution mode: ${t}`)}})(i.executionMode??"sequential"),n="string"==typeof i.logId?eC(i.logId,a):0,l=i.logSeverityLevel??2;if(!Number.isInteger(l)||l<0||l>4)throw Error(`log severity level is not valid: ${l}`);let u=i.logVerbosityLevel??0;if(!Number.isInteger(u)||u<0||u>4)throw Error(`log verbosity level is not valid: ${u}`);let d="string"==typeof i.optimizedModelFilePath?eC(i.optimizedModelFilePath,a):0;if(o=r._OrtCreateSessionOptions(t,!!i.enableCpuMemArena,!!i.enableMemPattern,s,!!i.enableProfiling,0,n,l,u,d),0===o&&eF("Can't create session options."),i.executionProviders&&await ex(o,i,a),void 0!==i.enableGraphCapture){if("boolean"!=typeof i.enableGraphCapture)throw Error(`enableGraphCapture must be a boolean value: ${i.enableGraphCapture}`);eU(o,"enableGraphCapture",i.enableGraphCapture.toString(),a)}if(i.freeDimensionOverrides)for(let[t,s]of Object.entries(i.freeDimensionOverrides)){if("string"!=typeof t)throw Error(`free dimension override name must be a string: ${t}`);if("number"!=typeof s||!Number.isInteger(s)||s<0)throw Error(`free dimension override value must be a non-negative integer: ${s}`);let i=eC(t,a);0!==r._OrtAddFreeDimensionOverride(o,i,s)&&eF(`Can't set a free dimension override: ${t} - ${s}.`)}return void 0!==i.extra&&eR(i.extra,"",new WeakSet,(t,r)=>{eU(o,t,r,a)}),[o,a]}catch(t){throw 0!==o&&0!==r._OrtReleaseSessionOptions(o)&&eF("Can't release session options."),a.forEach(t=>r._free(t)),t}}}),tb=$(()=>{eI=t=>{switch(t){case"int8":return 3;case"uint8":return 2;case"bool":return 9;
1case"int16":return 5;case"uint16":return 4;case"int32":return 6;case"uint32":return 12;case"float16":return 10;case"float32":return 1;case"float64":return 11;case"string":return 8;case"int64":return 7;case"uint64":return 13;case"int4":return 22;case"uint4":return 21;default:throw Error(`unsupported data type: ${t}`)}},eB=t=>{switch(t){case 3:return"int8";case 2:return"uint8";case 9:return"bool";case 5:return"int16";case 4:return"uint16";case 6:return"int32";case 12:return"uint32";case 10:return"float16";case 1:return"float32";case 11:return"float64";case 8:return"string";case 7:return"int64";case 13:return"uint64";case 22:return"int4";case 21:return"uint4";default:throw Error(`unsupported data type: ${t}`)}},eN=(t,r)=>{let o=[-1,4,1,1,2,2,4,8,-1,1,2,8,4,8,-1,-1,-1,-1,-1,-1,-1,.5,.5][t],a="number"==typeof r?r:r.reduce((t,r)=>t*r,1);return o>0?Math.ceil(a*o):void 0},ek=t=>{switch(t){case"float16":return"u">typeof Float16Array?Float16Array:Uint16Array;case"float32":return Float32Array;case"uint8":case"bool":return Uint8Array;case"int8":return Int8Array;case"uint16":return Uint16Array;case"int16":return Int16Array;case"int32":return Int32Array;case"float64":return Float64Array;case"uint32":return Uint32Array;case"int64":return BigInt64Array;case"uint64":return BigUint64Array;default:throw Error(`unsupported type: ${t}`)}},e$=t=>{switch(t){case"verbose":return 0;case"info":return 1;case"warning":return 2;case"error":return 3;case"fatal":return 4;default:throw Error(`unsupported logging level: ${t}`)}},ej=t=>"float32"===t||"float16"===t||"int32"===t||"int64"===t||"uint32"===t||"uint8"===t||"bool"===t||"uint4"===t||"int4"===t,eV=t=>"float32"===t||"float16"===t||"int32"===t||"int64"===t||"uint32"===t||"uint64"===t||"int8"===t||"uint8"===t||"bool"===t||"uint4"===t||"int4"===t,eG=t=>{switch(t){case"none":return 0;case"cpu":return 1;case"cpu-pinned":return 2;case"texture":return 3;case"gpu-buffer":return 4;case"ml-tensor":return 5;default:throw Error(`unsupported data location: ${t}`)}}}),tv=$(()=>{eu(),eW=async t=>{if("string"!=typeof t)return t instanceof Blob?new Uint8Array(await t.arrayBuffer()):t instanceof Uint8Array?t:new Uint8Array(t);{let r=await fetch(t);if(!r.ok)throw Error(`failed to load external data file: ${t}`);let o=r.headers.get("Content-Length"),a=o?parseInt(o,10):0;if(a<0x40000000)return new Uint8Array(await r.arrayBuffer());{if(!r.body)throw Error(`failed to load external data file: ${t}, no response body.`);let o=r.body.getReader(),i;try{i=new ArrayBuffer(a)}catch(t){if(t instanceof RangeError){let t=Math.ceil(a/65536);i=new WebAssembly.Memory({initial:t,maximum:t}).buffer}else throw t}let s=0;for(;;){let{done:t,value:r}=await o.read();if(t)break;let a=r.byteLength;new Uint8Array(i,s,a).set(r),s+=a}return new Uint8Array(i,0,a)}}}}),tE=$(()=>{el(),ty(),tw(),tb(),tm(),tg(),tv(),ez=async t=>{var r,o;r=t.wasm.numThreads,o=e$(t.logLevel),0!==eM()._OrtInit(r,o)&&eF("Can't initialize onnxruntime.")},eH=async(t,r)=>{eM().asyncInit?.();let o=t.webgpu.adapter;if("webgpu"===r){if(typeof navigator>"u"||!navigator.gpu)throw Error("WebGPU is not supported in current environment");if(o){if("object"!=typeof o.limits||"object"!=typeof o.features||"function"!=typeof o.requestDevice)throw Error("Invalid GPU adapter set in `env.webgpu.adapter`. It must be a GPUAdapter object.")}else{let r=t.webgpu.powerPreference;if(void 0!==r&&"low-power"!==r&&"high-performance"!==r)throw Error(`Invalid powerPreference setting: "${r}"`);let a=t.webgpu.forceFallbackAdapter;if(void 0!==a&&"boolean"!=typeof a)throw Error(`Invalid forceFallbackAdapter setting: "${a}"`);if(!(o=await navigator.gpu.requestAdapter({powerPreference:r,forceFallbackAdapter:a})))throw Error('Failed to get GPU adapter. You may need to enable flag "--enable-unsafe-webgpu" if you are using Chrome.')}}if("webnn"===r&&(typeof navigator>"u"||!navigator.ml))throw Error("WebNN is not supported in current environment")},eq=new Map,eZ=(t,r)=>{let o=eM(),a=o.stackSave(),i=0;try{let a=o.PTR_SIZE,s=o.stackAlloc(2*a);0!==o._OrtGetInputOutputMetadata(t,r,s,s+a)&&eF("Can't get session input/output metadata.");let n=Number(o.getValue(s,"*"));i=Number(o.getValue(s+a,"*"));let l=o.HEAP32[i/4];if(0===l)return[n,0];
1let u=o.HEAPU32[i/4+1],d=[];for(let t=0;t<u;t++){let r=Number(o.getValue(i+8+t*a,"*"));d.push(0!==r?o.UTF8ToString(r):Number(o.getValue(i+8+(t+u)*a,"*")))}return[n,l,d]}finally{o.stackRestore(a),0!==i&&o._OrtFree(i)}},eJ=t=>{let r=eM(),o=r._malloc(t.byteLength);if(0===o)throw Error(`Can't create a session. failed to allocate a buffer of size ${t.byteLength}.`);return r.HEAPU8.set(t,o),[o,t.byteLength]},eY=async(t,r)=>{let o,a,i=eM();Array.isArray(t)?[o,a]=t:t.buffer===i.HEAPU8.buffer?[o,a]=[t.byteOffset,t.byteLength]:[o,a]=eJ(t);let s=0,n=0,l=[],u=[],d=[];try{if([n,l]=await eL(r),r?.externalData&&i.mountExternalData){let t=[];for(let o of r.externalData){let r="string"==typeof o?o:o.path;t.push(eW("string"==typeof o?o:o.data).then(t=>{i.mountExternalData(r,t)}))}await Promise.all(t)}for(let t of r?.executionProviders??[])if(("string"==typeof t?t:t.name)==="webnn"){if(i.shouldTransferToMLTensor=!1,"string"!=typeof t){let r=t?.context,o=t?.gpuDevice,a=t?.deviceType,s=t?.powerPreference;r?i.currentContext=r:o?i.currentContext=await i.webnnCreateMLContext(o):i.currentContext=await i.webnnCreateMLContext({deviceType:a,powerPreference:s})}else i.currentContext=await i.webnnCreateMLContext();break}s=await i._OrtCreateSession(o,a,n),i.webgpuOnCreateSession?.(s),0===s&&eF("Can't create a session."),i.jsepOnCreateSession?.(),i.currentContext&&(i.webnnRegisterMLContext(s,i.currentContext),i.currentContext=void 0,i.shouldTransferToMLTensor=!0);let[t,p]=(t=>{let r=eM(),o=r.stackSave();try{let o=r.PTR_SIZE,a=r.stackAlloc(2*o);0!==r._OrtGetInputOutputCount(t,a,a+o)&&eF("Can't get session input/output count.");let i=4===o?"i32":"i64";return[Number(r.getValue(a,i)),Number(r.getValue(a+o,i))]}finally{r.stackRestore(o)}})(s),c=!!r?.enableGraphCapture,f=[],h=[],m=[],g=[];for(let r=0;r<t;r++){let[t,o,a]=eZ(s,r);0===t&&eF("Can't get an input name."),u.push(t);let n=i.UTF8ToString(t);f.push(n),m.push(0===o?{name:n,isTensor:!1}:{name:n,isTensor:!0,type:eB(o),shape:a})}for(let r=0;r<p;r++){let[o,a,n]=eZ(s,r+t);0===o&&eF("Can't get an output name."),d.push(o);let l=i.UTF8ToString(o);h.push(l),g.push(0===a?{name:l,isTensor:!1}:{name:l,isTensor:!0,type:eB(a),shape:n})}return eq.set(s,[s,u,d,null,c,!1]),[s,f,h,m,g]}catch(t){throw u.forEach(t=>i._OrtFree(t)),d.forEach(t=>i._OrtFree(t)),0!==s&&0!==i._OrtReleaseSession(s)&&eF("Can't release session."),t}finally{i._free(o),0!==n&&0!==i._OrtReleaseSessionOptions(n)&&eF("Can't release session options."),l.forEach(t=>i._free(t)),i.unmountExternalData?.()}},eK=t=>{let r=eM(),o=eq.get(t);if(!o)throw Error(`cannot release session. invalid session id: ${t}`);let[a,i,s,n,l]=o;n&&(l&&0!==r._OrtClearBoundOutputs(n.handle)&&eF("Can't clear bound outputs."),0!==r._OrtReleaseBinding(n.handle)&&eF("Can't release IO binding.")),r.jsepOnReleaseSession?.(t),r.webnnOnReleaseSession?.(t),r.webgpuOnReleaseSession?.(t),i.forEach(t=>r._OrtFree(t)),s.forEach(t=>r._OrtFree(t)),0!==r._OrtReleaseSession(a)&&eF("Can't release session."),eq.delete(t)},eQ=async(t,r,o,a,i,s,n=!1)=>{if(!t)return void r.push(0);let l=eM(),u=l.PTR_SIZE,d=t[0],p=t[1],c=t[3],f=c,h,m;if("string"===d&&("gpu-buffer"===c||"ml-tensor"===c))throw Error("String tensor is not supported on GPU.");if(n&&"gpu-buffer"!==c)throw Error(`External buffer must be provided for input/output index ${s} when enableGraphCapture is true.`);if("gpu-buffer"===c){let r=t[2].gpuBuffer;m=eN(eI(d),p);{let t=l.jsepRegisterBuffer;if(!t)throw Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');h=t(a,s,r,m)}}else if("ml-tensor"===c){let r=t[2].mlTensor;m=eN(eI(d),p);let o=l.webnnRegisterMLTensor;if(!o)throw Error('Tensor location "ml-tensor" is not supported without using WebNN.');h=o(a,r,eI(d),p)}else{let r=t[2];if(Array.isArray(r)){m=u*r.length,h=l._malloc(m),o.push(h);for(let t=0;t<r.length;t++){if("string"!=typeof r[t])throw TypeError(`tensor data at index ${t} is not a string`);l.setValue(h+t*u,eC(r[t],o),"*")}}else{let t=l.webnnIsGraphInput,s=l.webnnIsGraphOutput;if("string"!==d&&t&&s){let n=l.UTF8ToString(i);if(t(a,n)||s(a,n)){let t=eI(d);m=eN(t,p),f="ml-tensor";let o=l.webnnCreateTemporaryTensor,i=l.webnnUploadTensor;if(!o||!i)throw Error('Tensor location "ml-tensor" is not supported without using WebNN.');let s=await o(a,t,p);i(s,new Uint8Array(r.buffer,r.byteOffset,r.byteLength)),h=s}else m=r.byteLength,h=l._malloc(m),o.push(h),l.HEAPU8.set(new Uint8Array(r.buffer,r.byteOffset,m),h)}else m=r.byteLength,h=l._malloc(m),o.push(h),l.HEAPU8.set(new Uint8Array(r.buffer,r.byteOffset,m),h)}}let g=l.stackSave(),y=l.stackAlloc(4*p.length);try{p.forEach((t,r)=>l.setValue(y+r*u,t,4===u?"i32":"i64"));let t=l._OrtCreateTensor(eI(d),h,m,y,p.length,eG(f));0===t&&eF(`Can't create tensor for input/output. session=${a}, index=${s}.`),r.push(t)}finally{l.stackRestore(g)}},eX=async(t,r,o,a,i,s)=>{let n=eM(),l=n.PTR_SIZE,u=eq.get(t);if(!u)throw Error(`cannot run inference. invalid session id: ${t}`);let d=u[0],p=u[1],c=u[2],f=u[3],h=u[4],m=(u[5],r.length),g=a.length,y=0,w=[],b=[],v=[],E=[],S=[],A=n.stackSave(),T=n.stackAlloc(m*l),_=n.stackAlloc(m*l),O=n.stackAlloc(g*l),P=n.stackAlloc(g*l);try{let u;[y,w]=eD(s),F("wasm prepareInputOutputTensor");for(let a=0;a<m;a++)await eQ(o[a],b,E,t,p[r[a]],r[a],h);for(let r=0;r<g;r++)await eQ(i[r],v,E,t,c[a[r]],m+a[r],h);D("wasm prepareInputOutputTensor");for(let t=0;t<m;t++)n.setValue(T+t*l,b[t],"*"),n.setValue(_+t*l,p[r[t]],"*");for(let t=0;t<g;t++)n.setValue(O+t*l,v[t],"*"),n.setValue(P+t*l,c[a[t]],"*");n.jsepOnRunStart?.(d),n.webnnOnRunStart?.(d),u=await n._OrtRun(d,_,T,m,P,g,O,y),0!==u&&eF("failed to call OrtRun().");let A=[],M=[];F("wasm ProcessOutputTensor");for(let r=0;r<g;r++){let o=Number(n.getValue(O+r*l,"*"));if(o===v[r]||S.includes(v[r])){A.push(i[r]),o!==v[r]&&0!==n._OrtReleaseTensor(o)&&eF("Can't release tensor.");continue}let s=n.stackSave(),u=n.stackAlloc(4*l),d=!1,p,c=0;try{0!==n._OrtGetTensorData(o,u,u+l,u+2*l,u+3*l)&&eF(`Can't access output tensor data on index ${r}.`);let i=4===l?"i32":"i64",s=Number(n.getValue(u,i));c=n.getValue(u+l,"*");let h=n.getValue(u+2*l,"*"),m=Number(n.getValue(u+3*l,i)),g=[];for(let t=0;t<m;t++)g.push(Number(n.getValue(h+t*l,i)));0!==n._OrtFree(h)&&eF("Can't free memory for tensor dims.");let y=g.reduce((t,r)=>t*r,1);p=eB(s);let w=f?.outputPreferredLocations[a[r]];if("string"===p){if("gpu-buffer"===w||"ml-tensor"===w)throw Error("String tensor is not supported on GPU.");let t=[];for(let r=0;r<y;r++){let o=n.getValue(c+r*l,"*"),a=n.getValue(c+(r+1)*l,"*"),i=r===y-1?void 0:a-o;t.push(n.UTF8ToString(o,i))}A.push([p,g,t,"cpu"])}else if("gpu-buffer"===w&&y>0){let t=n.jsepGetBuffer;if(!t)throw Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let r=t(c),a=eN(s,y);if(void 0===a||!ej(p))throw Error(`Unsupported data type: ${p}`);d=!0,A.push([p,g,{gpuBuffer:r,download:n.jsepCreateDownloader(r,a,p),dispose:()=>{0!==n._OrtReleaseTensor(o)&&eF("Can't release tensor.")}},"gpu-buffer"])}else if("ml-tensor"===w&&y>0){let r=n.webnnEnsureTensor,a=n.webnnIsGraphInputOutputTypeSupported;if(!r||!a)throw Error('preferredLocation "ml-tensor" is not supported without using WebNN.');if(void 0===eN(s,y)||!eV(p))throw Error(`Unsupported data type: ${p}`);
1if(!a(t,p,!1))throw Error(`preferredLocation "ml-tensor" for ${p} output is not supported by current WebNN Context.`);let i=await r(t,c,s,g,!1);d=!0,A.push([p,g,{mlTensor:i,download:n.webnnCreateMLTensorDownloader(c,p),dispose:()=>{n.webnnReleaseTensorId(c),n._OrtReleaseTensor(o)}},"ml-tensor"])}else if("ml-tensor-cpu-output"===w&&y>0){let t=n.webnnCreateMLTensorDownloader(c,p)(),r=A.length;d=!0,M.push((async()=>{let a=[r,await t];return n.webnnReleaseTensorId(c),n._OrtReleaseTensor(o),a})()),A.push([p,g,[],"cpu"])}else{let t=new(ek(p))(y);new Uint8Array(t.buffer,t.byteOffset,t.byteLength).set(n.HEAPU8.subarray(c,c+t.byteLength)),A.push([p,g,t,"cpu"])}}finally{n.stackRestore(s),"string"===p&&c&&n._free(c),d||n._OrtReleaseTensor(o)}}for(let[r,o]of(f&&!h&&(0!==n._OrtClearBoundOutputs(f.handle)&&eF("Can't clear bound outputs."),eq.set(t,[d,p,c,f,h,!1])),await Promise.all(M)))A[r][2]=o;return D("wasm ProcessOutputTensor"),A}finally{n.webnnOnRunEnd?.(d),n.stackRestore(A),b.forEach(t=>n._OrtReleaseTensor(t)),v.forEach(t=>n._OrtReleaseTensor(t)),E.forEach(t=>n._free(t)),0!==y&&n._OrtReleaseRunOptions(y),w.forEach(t=>n._free(t))}},e0=t=>{let r=eM(),o=eq.get(t);if(!o)throw Error("invalid session id");let a=o[0],i=r._OrtEndProfiling(a);0===i&&eF("Can't get an profile file name."),r._OrtFree(i)},e1=t=>{let r=[];for(let o of t){let t=o[2];!Array.isArray(t)&&"buffer"in t&&r.push(t.buffer)}return r}}),tS=$(()=>{el(),tE(),tm(),th(),e2=()=>!!d.wasm.proxy&&"u">typeof document,e6=!1,e4=!1,e8=!1,e7=new Map,te=(t,r)=>{let o=e7.get(t);o?o.push(r):e7.set(t,[r])},tt=()=>{if(e6||!e4||e8||!e3)throw Error("worker not ready")},tr=t=>{switch(t.data.type){case"init-wasm":e6=!1,t.data.err?(e8=!0,e9[1](t.data.err)):(e4=!0,e9[0]()),e5&&(URL.revokeObjectURL(e5),e5=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let r=e7.get(t.data.type);t.data.err?r.shift()[1](t.data.err):r.shift()[0](t.data.out)}}},to=async()=>{if(!e4){if(e6)throw Error("multiple calls to 'initWasm()' detected.");if(e8)throw Error("previous call to 'initWasm()' failed.");if(e6=!0,e2())return new Promise((t,r)=>{e3?.terminate(),ev().then(([o,a])=>{try{(e3=a).onerror=t=>r(t),e3.onmessage=tr,e9=[t,r];let i={type:"init-wasm",in:d};if(!i.in.wasm.wasmPaths&&o){let t=em();t&&(i.in.wasm.wasmPaths=t)}e3.postMessage(i),e5=o}catch(t){r(t)}},r)});try{await eP(d.wasm),await ez(d),e4=!0}catch(t){throw e8=!0,t}finally{e6=!1}}},ta=async t=>{if(e2())return tt(),new Promise((r,o)=>{te("init-ep",[r,o]);let a={type:"init-ep",in:{epName:t,env:d}};e3.postMessage(a)});await eH(d,t)},ti=async t=>e2()?(tt(),new Promise((r,o)=>{te("copy-from",[r,o]),e3.postMessage({type:"copy-from",in:{buffer:t}},[t.buffer])})):eJ(t),ts=async(t,r)=>{if(!e2())return eY(t,r);
1if(r?.preferredOutputLocation)throw Error('session option "preferredOutputLocation" is not supported for proxy.');return tt(),new Promise((o,a)=>{te("create",[o,a]);let i={type:"create",in:{model:t,options:{...r}}},s=[];t instanceof Uint8Array&&s.push(t.buffer),e3.postMessage(i,s)})},tn=async t=>{if(e2())return tt(),new Promise((r,o)=>{te("release",[r,o]),e3.postMessage({type:"release",in:t})});eK(t)},tl=async(t,r,o,a,i,s)=>{if(!e2())return eX(t,r,o,a,i,s);if(o.some(t=>"cpu"!==t[3]))throw Error("input tensor on GPU is not supported for proxy.");if(i.some(t=>t))throw Error("pre-allocated output tensor is not supported for proxy.");return tt(),new Promise((i,n)=>{te("run",[i,n]),e3.postMessage({type:"run",in:{sessionId:t,inputIndices:r,inputs:o,outputIndices:a,options:s}},e1(o))})},tu=async t=>{if(e2())return tt(),new Promise((r,o)=>{te("end-profiling",[r,o]),e3.postMessage({type:"end-profiling",in:t})});e0(t)}}),tA=$(()=>{el(),tS(),tb(),eu(),tv(),td=(t,r)=>{switch(t.location){case"cpu":return[t.type,t.dims,t.data,"cpu"];case"gpu-buffer":return[t.type,t.dims,{gpuBuffer:t.gpuBuffer},"gpu-buffer"];case"ml-tensor":return[t.type,t.dims,{mlTensor:t.mlTensor},"ml-tensor"];default:throw Error(`invalid data location: ${t.location} for ${r()}`)}},tp=t=>{switch(t[3]){case"cpu":return new O(t[0],t[2],t[1]);case"gpu-buffer":{let r=t[0];if(!ej(r))throw Error(`not supported data type: ${r} for deserializing GPU tensor`);let{gpuBuffer:o,download:a,dispose:i}=t[2];return O.fromGpuBuffer(o,{dataType:r,dims:t[1],download:a,dispose:i})}case"ml-tensor":{let r=t[0];if(!eV(r))throw Error(`not supported data type: ${r} for deserializing MLTensor tensor`);let{mlTensor:o,download:a,dispose:i}=t[2];return O.fromMLTensor(o,{dataType:r,dims:t[1],download:a,dispose:i})}default:throw Error(`invalid data location: ${t[3]}`)}},tc=class{async fetchModelAndCopyToWasmMemory(t){return ti(await eW(t))}async loadModel(t,r){let o;C(),o="string"==typeof t?await this.fetchModelAndCopyToWasmMemory(t):t,[this.sessionId,this.inputNames,this.outputNames,this.inputMetadata,this.outputMetadata]=await ts(o,r),R()}async dispose(){return tn(this.sessionId)}async run(t,r,o){C();let a=[],i=[];Object.entries(t).forEach(t=>{let r=t[0],o=t[1],s=this.inputNames.indexOf(r);if(-1===s)throw Error(`invalid input '${r}'`);a.push(o),i.push(s)});let s=[],n=[];Object.entries(r).forEach(t=>{let r=t[0],o=t[1],a=this.outputNames.indexOf(r);if(-1===a)throw Error(`invalid output '${r}'`);s.push(o),n.push(a)});let l=a.map((t,r)=>td(t,()=>`input "${this.inputNames[i[r]]}"`)),u=s.map((t,r)=>t?td(t,()=>`output "${this.outputNames[n[r]]}"`):null),d=await tl(this.sessionId,i,l,n,u,o),p={};for(let t=0;t<d.length;t++)p[this.outputNames[n[t]]]=s[t]??tp(d[t]);return R(),p}startProfiling(){}endProfiling(){tu(this.sessionId)}}}),tT={};j(tT,{OnnxruntimeWebAssemblyBackend:()=>tO,initializeFlags:()=>t_,wasmBackend:()=>tP});var t_,tO,tP,tM=$(()=>{el(),tS(),tA(),t_=()=>{("number"!=typeof d.wasm.initTimeout||d.wasm.initTimeout<0)&&(d.wasm.initTimeout=0);let t=d.wasm.simd;if("boolean"!=typeof t&&void 0!==t&&"fixed"!==t&&"relaxed"!==t&&(console.warn(`Property "env.wasm.simd" is set to unknown value "${t}". Reset it to \`false\` and ignore SIMD feature checking.`),d.wasm.simd=!1),"boolean"!=typeof d.wasm.proxy&&(d.wasm.proxy=!1),"boolean"!=typeof d.wasm.trace&&(d.wasm.trace=!1),"number"!=typeof d.wasm.numThreads||!Number.isInteger(d.wasm.numThreads)||d.wasm.numThreads<=0)if("u">typeof self&&!self.crossOriginIsolated)d.wasm.numThreads=1;else{let t=typeof navigator>"u"?k("node:os").cpus().length:navigator.hardwareConcurrency;d.wasm.numThreads=Math.min(4,Math.ceil((t||1)/2))}},tP=new(tO=class{async init(t){t_(),await to(),await ta(t)}async createInferenceSessionHandler(t,r){let o=new tc;return await o.loadModel(t,r),o}})}),tC={};j(tC,{InferenceSession:()=>x,TRACE:()=>P,TRACE_EVENT_BEGIN:()=>F,TRACE_EVENT_END:()=>D,TRACE_FUNC_BEGIN:()=>C,TRACE_FUNC_END:()=>R,Tensor:()=>O,default:()=>tR,env:()=>d,registerBackend:()=>a}),el(),el(),el();var tR=en;{let t=(tM(),V(tT)).wasmBackend;a("cpu",t,10),a("wasm",t,10)}return Object.defineProperty(d.versions,"web",{value:"1.27.0",enumerable:!0}),V(tC)})()},37887:(t,r)=>
1{Object.defineProperty(r,"__esModule",{value:!0}),r.baseAssetPath=void 0;let o="undefined"!=typeof window&&void 0!==window.document?window.document.currentScript:null,a="/";o&&(a=o.src.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^/]+$/,"/")),r.baseAssetPath=a},46417:(t,r,o)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.SileroLegacy=void 0;let a=o(96252);class i{constructor(t,r,o,a,i){this.ortInstance=t,this._session=r,this._h=o,this._c=a,this._sr=i,this.reset_state=()=>{let t=Array(128).fill(0);this._h=new this.ortInstance.Tensor("float32",t,[2,1,64]),this._c=new this.ortInstance.Tensor("float32",t,[2,1,64])},this.process=async t=>{let r={input:new this.ortInstance.Tensor("float32",t,[1,t.length]),h:this._h,c:this._c,sr:this._sr},o=await this._session.run(r);this._h=o.hn,this._c=o.cn;let[a]=o.output?.data;return{notSpeech:1-a,isSpeech:a}},this.release=async()=>{await this._session.release(),this._h.dispose(),this._c.dispose(),this._sr.dispose()}}}r.SileroLegacy=i,i.new=async(t,r)=>{a.log.debug("initializing vad");let o=await r(),s=await t.InferenceSession.create(o),n=new t.Tensor("int64",[16000n]),l=Array(128).fill(0),u=new t.Tensor("float32",l,[2,1,64]),d=new t.Tensor("float32",l,[2,1,64]);return a.log.debug("vad is initialized"),new i(t,s,u,d,n)}},50489:function(t,r,o){var a=this&&this.__createBinding||(Object.create?function(t,r,o,a){void 0===a&&(a=o);var i=Object.getOwnPropertyDescriptor(r,o);(!i||("get"in i?!r.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return r[o]}}),Object.defineProperty(t,a,i)}:function(t,r,o,a){void 0===a&&(a=o),t[a]=r[o]}),i=this&&this.__setModuleDefault||(Object.create?function(t,r){Object.defineProperty(t,"default",{enumerable:!0,value:r})}:function(t,r){t.default=r}),s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var r={};if(null!=t)for(var o in t)"default"!==o&&Object.prototype.hasOwnProperty.call(t,o)&&a(r,t,o);return i(r,t),r};Object.defineProperty(r,"__esModule",{value:!0}),r.MicVAD=r.getDefaultRealTimeVADOptions=r.ort=r.DEFAULT_MODEL=void 0;let n=s(o(20629)),l=o(88562),u=o(74337),d=o(96252),p=o(63603),c=o(93934),f=o(74902);async function h(t,r,o,a,i){await o.audioWorklet.addModule(t),r.processorOptions={...r.processorOptions??{},frameSamples:a};let s=new AudioWorkletNode(o,"vad-helper-worklet",r);return s.port.onmessage=async t=>{let r=t.data;if(!("object"==typeof r&&r&&"message"in r))return void console.error("Invalid message event",r);if(r.message===p.Message.AudioFrame){if(!("data"in r&&r.data instanceof ArrayBuffer))return void console.log("Audio frame message has no data");let t=new Float32Array(r.data);await i(t)}},s}async function m(t,r,o){let a=new f.Resampler({nativeSampleRate:t.sampleRate,targetSampleRate:16e3,targetFrameSize:r});d.log.debug("using script processor");let i=t.createScriptProcessor(4096,1,1),s=!1;return i.onaudioprocess=async t=>{if(!s){s=!0;try{let r=t.inputBuffer.getChannelData(0);for(let i of(t.outputBuffer.getChannelData(0).fill(0),a.process(r)))await o(i)}catch(t){console.error("Error processing audio:",t)}finally{s=!1}}},i.connect(t.destination),i}r.DEFAULT_MODEL="legacy",r.ort=n,r.getDefaultRealTimeVADOptions=t=>({...u.defaultFrameProcessorOptions,onFrameProcessed:()=>{},onVADMisfire:()=>{d.log.debug("VAD misfire")},onSpeechStart:()=>{d.log.debug("Detected speech start")},onSpeechEnd:()=>{d.log.debug("Detected speech end")},onSpeechRealStart:()=>{d.log.debug("Detected real speech start")},baseAssetPath:"./",onnxWASMBasePath:"./",model:t,workletOptions:{},getStream:async()=>await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0}}),pauseStream:async t=>{t.getTracks().forEach(t=>{t.stop()})},resumeStream:async()=>await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0}}),ortConfig:t=>{t.env.logLevel="error"},startOnLoad:!0,processorType:"auto"});class g{constructor(t,r,o,a,i=!1,s=null,n=null,l=null,u=null,c=null,f=null,g="uninitialized",y=!1){this.options=t,this.frameProcessor=r,this.model=o,this.frameSamples=a,this.listening=i,this.errored=s,this._stream=n,this._audioContext=l,this._vadNode=u,this._mediaStreamAudioSourceNode=c,this._audioProcessorAdapterType=f,this.initializationState=g,this.ownsAudioContext=y,this.getAudioInstances=()=>
1{if(null===this._stream||null===this._audioContext||null==this._vadNode||null==this._mediaStreamAudioSourceNode)throw Error("MicVAD has null stream, audio context, or processor adapter");return{stream:this._stream,audioContext:this._audioContext,vadNode:this._vadNode,mediaStreamAudioSourceNode:this._mediaStreamAudioSourceNode}},this.setErrored=t=>{this.initializationState="errored",this.errored=t},this.start=async()=>{switch(this.initializationState){case"uninitialized":d.log.debug("initializing micVAD"),this.initializationState="initializing",this.frameProcessor.resume();try{this._stream=await this.options.getStream()}catch(t){throw t instanceof Error?this.setErrored(t.message):this.setErrored(String(t)),t}if(this.options.audioContext?(console.log("using custom audio context"),this._audioContext=this.options.audioContext):(console.log("using default audio context"),this._audioContext=new AudioContext,this.ownsAudioContext=!0),!this._audioContext)throw this.setErrored("Audio context is null"),Error("Audio context is null");switch(this._audioProcessorAdapterType="auto"==this.options.processorType?"audioWorklet"in this._audioContext&&"function"==typeof AudioWorkletNode?"AudioWorklet":"ScriptProcessor":this.options.processorType,this._audioProcessorAdapterType){case"AudioWorklet":this._vadNode=await h(this.options.baseAssetPath+"vad.worklet.bundle.min.js",this.options.workletOptions,this._audioContext,this.frameSamples,this.processFrame);break;case"ScriptProcessor":this._vadNode=await m(this._audioContext,this.frameSamples,this.processFrame);break;default:throw Error(`Unsupported audio processor adapter type: ${this._audioProcessorAdapterType}`)}this._mediaStreamAudioSourceNode=new MediaStreamAudioSourceNode(this._audioContext,{mediaStream:this._stream}),this._mediaStreamAudioSourceNode.connect(this._vadNode),d.log.debug("started micVAD"),this.listening=!0,this.initializationState="initialized";break;case"initializing":d.log.warn("start called while initializing");break;case"initialized":{if(this.listening)return;this.listening=!0,this.frameProcessor.resume();let{stream:t,audioContext:r,vadNode:o}=this.getAudioInstances();this._stream=await this.options.resumeStream(t);let a=new MediaStreamAudioSourceNode(r,{mediaStream:this._stream});this._mediaStreamAudioSourceNode=a,a.connect(o);break}case"destroyed":d.log.warn("start called after destroyed");break;case"errored":d.log.error("start called after errored");break;default:d.log.warn("weird initialization state")}},this.pause=async()=>{if(!this.listening)return;this.listening=!1;let{stream:t,mediaStreamAudioSourceNode:r}=this.getAudioInstances();await this.options.pauseStream(t),r.disconnect(),this.frameProcessor.pause(this.handleFrameProcessorEvent)},this.destroy=async()=>{d.log.debug("destroy called"),this.initializationState="destroyed";let{vadNode:t}=this.getAudioInstances();t instanceof AudioWorkletNode&&t.port.postMessage(p.Message.SpeechStop),this.listening&&await this.pause(),await this.model.release(),this.ownsAudioContext&&await this._audioContext?.close()},this.setOptions=t=>{this.frameProcessor.setOptions(t)},this.processFrame=async t=>{await this.frameProcessor.process(t,this.handleFrameProcessorEvent)},this.handleFrameProcessorEvent=t=>{switch(t.msg){case p.Message.FrameProcessed:this.options.onFrameProcessed(t.probs,t.frame);break;case p.Message.SpeechStart:this.options.onSpeechStart();break;case p.Message.SpeechRealStart:this.options.onSpeechRealStart();break;case p.Message.VADMisfire:this.options.onVADMisfire();break;case p.Message.SpeechEnd:this.options.onSpeechEnd(t.audio)}}}static async new(t={}){let o,a={...(0,r.getDefaultRealTimeVADOptions)(t.model??r.DEFAULT_MODEL),...t};(0,u.validateOptions)(a),r.ort.env.wasm.wasmPaths=a.onnxWASMBasePath,void 0!==a.ortConfig&&a.ortConfig(r.ort);let i="v5"===a.model?"silero_vad_v5.onnx":"silero_vad_legacy.onnx",s=a.baseAssetPath+i,n="v5"===a.model?c.SileroV5.new:c.SileroLegacy.new;try{o=await n(r.ort,()=>(0,l.defaultModelFetcher)(s))}catch(t){throw console.error(`Encountered an error while loading model file ${s}`),t}let d="v5"===a.model?512:1536,p=new u.FrameProcessor(o.process,o.reset_state,{positiveSpeechThreshold:a.positiveSpeechThreshold,negativeSpeechThreshold:a.negativeSpeechThreshold,redemptionMs:a.redemptionMs,preSpeechPadMs:a.preSpeechPadMs,minSpeechMs:a.minSpeechMs,submitUserSpeechOnPause:a.submitUserSpeechOnPause},d/16),f=new g(a,p,o,d);if(a.startOnLoad)try{await f.start()}catch(t){throw console.error("Error starting micVad",t),t}return f}}r.MicVAD=g},63603:(t,r)=>{var o;
1Object.defineProperty(r,"__esModule",{value:!0}),r.Message=void 0,function(t){t.AudioFrame="AUDIO_FRAME",t.SpeechStart="SPEECH_START",t.VADMisfire="VAD_MISFIRE",t.SpeechEnd="SPEECH_END",t.SpeechStop="SPEECH_STOP",t.SpeechRealStart="SPEECH_REAL_START",t.FrameProcessed="FRAME_PROCESSED"}(o||(r.Message=o={}))},65491:function(t,r,o){var a=this&&this.__createBinding||(Object.create?function(t,r,o,a){void 0===a&&(a=o);var i=Object.getOwnPropertyDescriptor(r,o);(!i||("get"in i?!r.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return r[o]}}),Object.defineProperty(t,a,i)}:function(t,r,o,a){void 0===a&&(a=o),t[a]=r[o]}),i=this&&this.__setModuleDefault||(Object.create?function(t,r){Object.defineProperty(t,"default",{enumerable:!0,value:r})}:function(t,r){t.default=r}),s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var r={};if(null!=t)for(var o in t)"default"!==o&&Object.prototype.hasOwnProperty.call(t,o)&&a(r,t,o);return i(r,t),r};Object.defineProperty(r,"__esModule",{value:!0}),r.NonRealTimeVAD=r.defaultNonRealTimeVADOptions=void 0;let n=s(o(25577)),l=o(37887),u=o(88562),d=o(74337),p=o(63603),c=o(93934),f=o(74902);r.defaultNonRealTimeVADOptions={...d.defaultFrameProcessorOptions,modelURL:l.baseAssetPath+"silero_vad_legacy.onnx",modelFetcher:u.defaultModelFetcher};class h{static async new(t={}){let o={...r.defaultNonRealTimeVADOptions,...t};(0,d.validateOptions)(o),void 0!==o.ortConfig&&o.ortConfig(n);let a=()=>o.modelFetcher(o.modelURL),i=await c.SileroLegacy.new(n,a),s=new d.FrameProcessor(i.process,i.reset_state,{positiveSpeechThreshold:o.positiveSpeechThreshold,negativeSpeechThreshold:o.negativeSpeechThreshold,redemptionMs:o.redemptionMs,preSpeechPadMs:o.preSpeechPadMs,minSpeechMs:o.minSpeechMs,submitUserSpeechOnPause:o.submitUserSpeechOnPause},96);return s.resume(),new this(a,n,o,s)}constructor(t,r,o,a){this.modelFetcher=t,this.ort=r,this.options=o,this.frameProcessor=a,this.frameSamples=1536}async *run(t,r){let o={nativeSampleRate:r,targetSampleRate:16e3,targetFrameSize:this.frameSamples},a=new f.Resampler(o),i=0,s=0,n=0;for await(let r of a.stream(t)){let t=[];for(let o of(await this.frameProcessor.process(r,r=>{t.push(r)}),t))switch(o.msg){case p.Message.SpeechStart:i=n*this.frameSamples/16;break;case p.Message.SpeechEnd:s=(n+1)*this.frameSamples/16,yield{audio:o.audio,start:i,end:s}}n++}let l=[];for(let t of(this.frameProcessor.endSegment(t=>{l.push(t)}),l))t.msg===p.Message.SpeechEnd&&(yield{audio:t.audio,start:i,end:n*this.frameSamples/16})}}r.NonRealTimeVAD=h},74337:(t,r,o)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.FrameProcessor=r.validateOptions=r.defaultFrameProcessorOptions=void 0;let a=o(96252),i=o(63603);r.defaultFrameProcessorOptions={positiveSpeechThreshold:.3,negativeSpeechThreshold:.25,preSpeechPadMs:800,redemptionMs:1400,minSpeechMs:400,submitUserSpeechOnPause:!1},r.validateOptions=function(t){(t.positiveSpeechThreshold<0||t.positiveSpeechThreshold>1)&&a.log.error("positiveSpeechThreshold should be a number between 0 and 1"),(t.negativeSpeechThreshold<0||t.negativeSpeechThreshold>t.positiveSpeechThreshold)&&a.log.error("negativeSpeechThreshold should be between 0 and positiveSpeechThreshold"),t.preSpeechPadMs<0&&a.log.error("preSpeechPadMs should be positive"),t.redemptionMs<0&&a.log.error("redemptionMs should be positive"),t.minSpeechMs<0&&a.log.error("minSpeechMs should be positive")};let s=t=>{let r=t.reduce((t,r)=>(t.push(t.at(-1)+r.length),t),[0]),o=new Float32Array(r.at(-1));return t.forEach((t,a)=>{let i=r[a];o.set(t,i)}),o};function n(t,r){let o=Math.floor(t.redemptionMs/r);return{redemptionFrames:o,preSpeechPadFrames:Math.floor(t.preSpeechPadMs/r),minSpeechFrames:Math.floor(t.minSpeechMs/r)}}class l{constructor(t,r,o,a){this.modelProcessFunc=t,this.modelResetFunc=r,this.options=o,this.msPerFrame=a,this.speaking=!1,this.redemptionCounter=0,this.speechFrameCount=0,this.active=!1,this.speechRealStartFired=!1,this.setOptions=t=>{this.options={...this.options,...t};let{redemptionFrames:r,preSpeechPadFrames:o,minSpeechFrames:a}=n(this.options,this.msPerFrame);this.redemptionFrames=r,this.preSpeechPadFrames=o,this.minSpeechFrames=a},this.reset=()=>{this.speaking=!1,this.speechRealStartFired=!1,this.audioBuffer=[],this.modelResetFu
1nc(),this.redemptionCounter=0,this.speechFrameCount=0},this.pause=t=>{this.active=!1,this.options.submitUserSpeechOnPause?this.endSegment(t):this.reset()},this.resume=()=>{this.active=!0},this.endSegment=t=>{let r=this.audioBuffer;this.audioBuffer=[];let o=this.speaking;if(this.reset(),o)if(r.reduce((t,r)=>r.isSpeech?t+1:t,0)>=this.minSpeechFrames){let o=s(r.map(t=>t.frame));t({msg:i.Message.SpeechEnd,audio:o})}else t({msg:i.Message.VADMisfire});return{}},this.process=async(t,r)=>{if(!this.active)return;let o=await this.modelProcessFunc(t),a=o.isSpeech>=this.options.positiveSpeechThreshold;if(r({probs:o,msg:i.Message.FrameProcessed,frame:t}),this.audioBuffer.push({frame:t,isSpeech:a}),a&&(this.speechFrameCount++,this.redemptionCounter=0),a&&!this.speaking&&(this.speaking=!0,r({msg:i.Message.SpeechStart})),this.speaking&&this.speechFrameCount===this.minSpeechFrames&&!this.speechRealStartFired&&(this.speechRealStartFired=!0,r({msg:i.Message.SpeechRealStart})),o.isSpeech<this.options.negativeSpeechThreshold&&this.speaking&&++this.redemptionCounter>=this.redemptionFrames){this.redemptionCounter=0,this.speechFrameCount=0,this.speaking=!1,this.speechRealStartFired=!1;let t=this.audioBuffer;if(this.audioBuffer=[],t.reduce((t,r)=>r.isSpeech?t+1:t,0)>=this.minSpeechFrames){let o=s(t.map(t=>t.frame));r({msg:i.Message.SpeechEnd,audio:o})}else r({msg:i.Message.VADMisfire})}if(!this.speaking){for(;this.audioBuffer.length>this.preSpeechPadFrames;)this.audioBuffer.shift();this.speechFrameCount=0}},this.audioBuffer=[];let{redemptionFrames:l,preSpeechPadFrames:u,minSpeechFrames:d}=n(this.options,this.msPerFrame);this.redemptionFrames=l,this.preSpeechPadFrames=u,this.minSpeechFrames=d,this.reset()}}r.FrameProcessor=l},74902:(t,r,o)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.Resampler=void 0;let a=o(96252);class i{constructor(t){this.options=t,this.process=t=>{let r=[];for(let o of t)for(this.inputBuffer.push(o);this.hasEnoughDataForFrame();){let t=this.generateOutputFrame();r.push(t)}return r},t.nativeSampleRate<16e3&&a.log.error("nativeSampleRate is too low. Should have 16000 = targetSampleRate <= nativeSampleRate"),this.inputBuffer=[]}async *stream(t){for(let r of t)for(this.inputBuffer.push(r);this.hasEnoughDataForFrame();){let t=this.generateOutputFrame();yield t}}hasEnoughDataForFrame(){return this.inputBuffer.length*this.options.targetSampleRate/this.options.nativeSampleRate>=this.options.targetFrameSize}generateOutputFrame(){let t=new Float32Array(this.options.targetFrameSize),r=0,o=0;for(;r<this.options.targetFrameSize;){let a=0,i=0;for(;o<Math.min(this.inputBuffer.length,(r+1)*this.options.nativeSampleRate/this.options.targetSampleRate);){let t=this.inputBuffer[o];void 0!==t&&(a+=t,i++),o++}t[r]=a/i,r++}return this.inputBuffer=this.inputBuffer.slice(o),t}}r.Resampler=i},79084:(t,r)=>{function o(t,r,o){for(let a=0;a<o.length;a++)t.setUint8(r+a,o.charCodeAt(a))}Object.defineProperty(r,"__esModule",{value:!0}),r.audioFileToArray=r.encodeWAV=r.arrayBufferToBase64=r.minFramesForTargetMS=void 0,r.minFramesForTargetMS=function(t,r,o=16e3){return Math.ceil(t*o/1e3/r)},r.arrayBufferToBase64=function(t){let r=new Uint8Array(t),o=r.byteLength,a=Array(o);for(let t=0;t<o;t++){let o=r[t];if(void 0===o)break;a[t]=String.fromCharCode(o)}return btoa(a.join(""))},r.encodeWAV=function(t,r=3,a=16e3,i=1,s=32){let n=s/8,l=i*n,u=new ArrayBuffer(44+t.length*n),d=new DataView(u);return o(d,0,"RIFF"),d.setUint32(4,36+t.length*n,!0),o(d,8,"WAVE"),o(d,12,"fmt "),d.setUint32(16,16,!0),d.setUint16(20,r,!0),d.setUint16(22,i,!0),d.setUint32(24,a,!0),d.setUint32(28,a*l,!0),d.setUint16(32,l,!0),d.setUint16(34,s,!0),o(d,36,"data"),d.setUint32(40,t.length*n,!0),1===r?function(t,r,o){for(let a=0;a<o.length;a++,r+=2){let i=Math.max(-1,Math.min(1,o[a]));t.setInt16(r,i<0?32768*i:32767*i,!0)}}(d,44,t):function(t,r,o){for(let a=0;a<o.length;a++,r+=4)t.setFloat32(r,o[a],!0)}(d,44,t),u},r.audioFileToArray=async function(t){let r=new OfflineAudioContext(1,1,44100),o=new FileReader,a=null;if(await new Promise(i=>{o.addEventListener("loadend",()=>{let t=o.result;r.decodeAudioData(t,t=>{a=t,r.startRendering().then(()=>{console.log("Rendering completed successfully"),i()}).catch(t=>{console.error("Rendering failed: ",t)})},t=>{console.log("Error with decoding audio data: ",t)})}),o.readAsArrayBuffer(t)}),null===a)throw Error("some shit");let i=a,s=new Float32Array(i.length);for(let t=0;t<i.length;t++)for(let r=0;r<i.numberOfChannels;r++){let o=i.getChannelData(r)[t],a=s[t];if(void 0===o||void 0===a)throw Error("sample or out[i] is undefined");s[t]=a+o}return{audio:s,sampleRate:i.sampleRate}}},84011:(t,r)=>
1{Object.defineProperty(r,"__esModule",{value:!0})},86345:(t,r,o)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.getDefaultRealTimeVADOptions=r.MicVAD=r.DEFAULT_MODEL=r.utils=r.NonRealTimeVAD=r.Message=r.FrameProcessor=r.defaultModelFetcher=r.baseAssetPath=void 0;var a=o(37887);Object.defineProperty(r,"baseAssetPath",{enumerable:!0,get:function(){return a.baseAssetPath}});var i=o(88562);Object.defineProperty(r,"defaultModelFetcher",{enumerable:!0,get:function(){return i.defaultModelFetcher}});var s=o(74337);Object.defineProperty(r,"FrameProcessor",{enumerable:!0,get:function(){return s.FrameProcessor}});var n=o(63603);Object.defineProperty(r,"Message",{enumerable:!0,get:function(){return n.Message}});var l=o(65491);Object.defineProperty(r,"NonRealTimeVAD",{enumerable:!0,get:function(){return l.NonRealTimeVAD}});let u=o(79084);r.utils={audioFileToArray:u.audioFileToArray,minFramesForTargetMS:u.minFramesForTargetMS,arrayBufferToBase64:u.arrayBufferToBase64,encodeWAV:u.encodeWAV};var d=o(50489);Object.defineProperty(r,"DEFAULT_MODEL",{enumerable:!0,get:function(){return d.DEFAULT_MODEL}}),Object.defineProperty(r,"MicVAD",{enumerable:!0,get:function(){return d.MicVAD}}),Object.defineProperty(r,"getDefaultRealTimeVADOptions",{enumerable:!0,get:function(){return d.getDefaultRealTimeVADOptions}})},87535:(t,r,o)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.SileroV5=void 0;let a=o(96252);function i(t){let r=Array(256).fill(0);return new t.Tensor("float32",r,[2,1,128])}class s{constructor(t,r,o,a){this._session=t,this._state=r,this._sr=o,this.ortInstance=a,this.reset_state=()=>{this._state=i(this.ortInstance)},this.process=async t=>{let r={input:new this.ortInstance.Tensor("float32",t,[1,t.length]),state:this._state,sr:this._sr},o=await this._session.run(r);if(!o.stateN)throw Error("No state from model");if(this._state=o.stateN,!o.output?.data)throw Error("No output from model");let a=o.output.data[0];if("number"!=typeof a)throw Error("Weird output data");return{notSpeech:1-a,isSpeech:a}},this.release=async()=>{await this._session.release(),this._state.dispose(),this._sr.dispose()}}}r.SileroV5=s,s.new=async(t,r)=>{a.log.debug("Loading VAD...");let o=await r(),n=await t.InferenceSession.create(o),l=new t.Tensor("int64",[16000n]),u=i(t);return a.log.debug("...finished loading VAD"),new s(n,u,l,t)}},88562:(t,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.defaultModelFetcher=void 0,r.defaultModelFetcher=t=>fetch(t).then(t=>t.arrayBuffer())},93934:function(t,r,o){var a=this&&this.__createBinding||(Object.create?function(t,r,o,a){void 0===a&&(a=o);var i=Object.getOwnPropertyDescriptor(r,o);(!i||("get"in i?!r.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return r[o]}}),Object.defineProperty(t,a,i)}:function(t,r,o,a){void 0===a&&(a=o),t[a]=r[o]}),i=this&&this.__exportStar||function(t,r){for(var o in t)"default"===o||Object.prototype.hasOwnProperty.call(r,o)||a(r,t,o)};Object.defineProperty(r,"__esModule",{value:!0}),r.SileroV5=r.SileroLegacy=void 0,i(o(84011),r);var s=o(46417);Object.defineProperty(r,"SileroLegacy",{enumerable:!0,get:function(){return s.SileroLegacy}});var n=o(87535);Object.defineProperty(r,"SileroV5",{enumerable:!0,get:function(){return n.SileroV5}})},96252:(t,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.log=void 0;let o=t=>r=>{console.log(`VAD | ${t} >`,r)};r.log={error:o("error"),debug:o("debug"),warn:o("warn")}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.