@k4ung/vad-web
Advanced tools
@@ -139,3 +139,3 @@ /* | ||
| eval("\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n});\nvar __importStar = (this && this.__importStar) || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.AudioNodeVAD = exports.MicVAD = exports.defaultRealTimeVADOptions = void 0;\nconst ort = __importStar(__webpack_require__(/*! onnxruntime-web */ \"onnxruntime-web\"));\nconst _common_1 = __webpack_require__(/*! ./_common */ \"./dist/_common/index.js\");\nconst model_fetcher_1 = __webpack_require__(/*! ./model-fetcher */ \"./dist/model-fetcher.js\");\nconst asset_path_1 = __webpack_require__(/*! ./asset-path */ \"./dist/asset-path.js\");\nconst _getWorkletURL = () => {\n return (0, asset_path_1.assetPath)(\"vad.worklet.bundle.min.js\");\n};\nexports.defaultRealTimeVADOptions = {\n ..._common_1.defaultFrameProcessorOptions,\n onFrameProcessed: (probabilities) => { },\n onVADMisfire: () => {\n _common_1.log.debug(\"VAD misfire\");\n },\n onSpeechStart: () => {\n _common_1.log.debug(\"Detected speech start\");\n },\n onSpeechEnd: () => {\n _common_1.log.debug(\"Detected speech end\");\n },\n workletURL: _getWorkletURL(),\n stream: undefined,\n};\nclass MicVAD {\n static async new(options = {}) {\n const vad = new MicVAD({ ...exports.defaultRealTimeVADOptions, ...options });\n await vad.init();\n return vad;\n }\n constructor(options) {\n this.options = options;\n this.listening = false;\n this.init = async () => {\n if (this.options.stream === undefined)\n this.stream = await navigator.mediaDevices.getUserMedia({\n audio: {\n ...this.options.additionalAudioConstraints,\n channelCount: 1,\n echoCancellation: true,\n autoGainControl: true,\n noiseSuppression: true,\n },\n });\n else\n this.stream = this.options.stream;\n this.audioContext = new AudioContext();\n const source = new MediaStreamAudioSourceNode(this.audioContext, {\n mediaStream: this.stream,\n });\n this.audioNodeVAD = await AudioNodeVAD.new(this.audioContext, this.options);\n this.audioNodeVAD.receive(source);\n };\n this.pause = () => {\n this.audioNodeVAD.pause();\n this.listening = false;\n };\n this.start = () => {\n this.audioNodeVAD.start();\n this.listening = true;\n };\n this.destroy = () => {\n if (this.listening) {\n this.pause();\n }\n this.stream.getTracks().forEach(t => t.stop());\n };\n (0, _common_1.validateOptions)(options);\n }\n}\nexports.MicVAD = MicVAD;\nclass AudioNodeVAD {\n static async new(ctx, options = {}) {\n const vad = new AudioNodeVAD(ctx, {\n ...exports.defaultRealTimeVADOptions,\n ...options,\n });\n await vad.init();\n return vad;\n }\n constructor(ctx, options) {\n this.ctx = ctx;\n this.options = options;\n this.pause = () => {\n this.frameProcessor.pause();\n };\n this.start = () => {\n this.frameProcessor.resume();\n };\n this.receive = (node) => {\n node.connect(this.entryNode);\n };\n this.processFrame = async (frame) => {\n const { probs, msg, audio } = await this.frameProcessor.process(frame);\n if (probs !== undefined) {\n this.options.onFrameProcessed(probs);\n }\n switch (msg) {\n case _common_1.Message.SpeechStart:\n this.options.onSpeechStart();\n break;\n case _common_1.Message.VADMisfire:\n this.options.onVADMisfire();\n break;\n case _common_1.Message.SpeechEnd:\n // @ts-ignore\n this.options.onSpeechEnd(audio);\n break;\n default:\n break;\n }\n };\n this.init = async () => {\n await this.ctx.audioWorklet.addModule(this.options.workletURL);\n const vadNode = new AudioWorkletNode(this.ctx, \"vad-helper-worklet\", {\n processorOptions: {\n frameSamples: this.options.frameSamples,\n },\n });\n this.entryNode = vadNode;\n const model = await _common_1.Silero.new(ort, model_fetcher_1.modelFetcher);\n this.frameProcessor = new _common_1.FrameProcessor(model.process, model.reset_state, {\n frameSamples: this.options.frameSamples,\n positiveSpeechThreshold: this.options.positiveSpeechThreshold,\n negativeSpeechThreshold: this.options.negativeSpeechThreshold,\n redemptionFrames: this.options.redemptionFrames,\n preSpeechPadFrames: this.options.preSpeechPadFrames,\n minSpeechFrames: this.options.minSpeechFrames,\n });\n vadNode.port.onmessage = async (ev) => {\n switch (ev.data?.message) {\n case _common_1.Message.AudioFrame:\n const buffer = ev.data.data;\n const frame = new Float32Array(buffer);\n await this.processFrame(frame);\n break;\n default:\n break;\n }\n };\n };\n (0, _common_1.validateOptions)(options);\n }\n}\nexports.AudioNodeVAD = AudioNodeVAD;\n//# sourceMappingURL=real-time-vad.js.map\n\n//# sourceURL=webpack://vad/./dist/real-time-vad.js?"); | ||
| eval("\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n});\nvar __importStar = (this && this.__importStar) || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.AudioNodeVAD = exports.MicVAD = exports.defaultRealTimeVADOptions = void 0;\nconst ort = __importStar(__webpack_require__(/*! onnxruntime-web */ \"onnxruntime-web\"));\nconst _common_1 = __webpack_require__(/*! ./_common */ \"./dist/_common/index.js\");\nconst model_fetcher_1 = __webpack_require__(/*! ./model-fetcher */ \"./dist/model-fetcher.js\");\nconst asset_path_1 = __webpack_require__(/*! ./asset-path */ \"./dist/asset-path.js\");\nconst _getWorkletURL = () => {\n return (0, asset_path_1.assetPath)(\"vad.worklet.bundle.min.js\");\n};\nexports.defaultRealTimeVADOptions = {\n ..._common_1.defaultFrameProcessorOptions,\n onFrameProcessed: (probabilities) => { },\n onVADMisfire: () => {\n _common_1.log.debug(\"VAD misfire\");\n },\n onSpeechStart: () => {\n _common_1.log.debug(\"Detected speech start\");\n },\n onSpeechEnd: () => {\n _common_1.log.debug(\"Detected speech end\");\n },\n workletURL: _getWorkletURL(),\n stream: undefined,\n};\nclass MicVAD {\n static async new(options = {}) {\n const vad = new MicVAD({ ...exports.defaultRealTimeVADOptions, ...options });\n await vad.init();\n return vad;\n }\n constructor(options) {\n this.options = options;\n this.listening = false;\n this.init = async () => {\n if (this.options.stream === undefined)\n this.stream = await navigator.mediaDevices.getUserMedia({\n audio: {\n ...this.options.additionalAudioConstraints,\n channelCount: 1,\n echoCancellation: true,\n autoGainControl: true,\n noiseSuppression: true,\n },\n });\n else\n this.stream = this.options.stream;\n this.audioContext = new AudioContext();\n const source = new MediaStreamAudioSourceNode(this.audioContext, {\n mediaStream: this.stream,\n });\n this.audioNodeVAD = await AudioNodeVAD.new(this.audioContext, this.options);\n this.audioNodeVAD.receive(source);\n };\n this.pause = () => {\n this.audioNodeVAD.pause();\n this.listening = false;\n };\n this.start = () => {\n this.audioNodeVAD.start();\n this.listening = true;\n };\n this.destroy = () => {\n if (this.listening) {\n this.pause();\n }\n this.stream.getTracks().forEach((t) => t.stop());\n this.audioContext.close();\n };\n (0, _common_1.validateOptions)(options);\n }\n}\nexports.MicVAD = MicVAD;\nclass AudioNodeVAD {\n static async new(ctx, options = {}) {\n const vad = new AudioNodeVAD(ctx, {\n ...exports.defaultRealTimeVADOptions,\n ...options,\n });\n await vad.init();\n return vad;\n }\n constructor(ctx, options) {\n this.ctx = ctx;\n this.options = options;\n this.pause = () => {\n this.frameProcessor.pause();\n };\n this.start = () => {\n this.frameProcessor.resume();\n };\n this.receive = (node) => {\n node.connect(this.entryNode);\n };\n this.processFrame = async (frame) => {\n const { probs, msg, audio } = await this.frameProcessor.process(frame);\n if (probs !== undefined) {\n this.options.onFrameProcessed(probs);\n }\n switch (msg) {\n case _common_1.Message.SpeechStart:\n this.options.onSpeechStart();\n break;\n case _common_1.Message.VADMisfire:\n this.options.onVADMisfire();\n break;\n case _common_1.Message.SpeechEnd:\n // @ts-ignore\n this.options.onSpeechEnd(audio);\n break;\n default:\n break;\n }\n };\n this.init = async () => {\n await this.ctx.audioWorklet.addModule(this.options.workletURL);\n const vadNode = new AudioWorkletNode(this.ctx, \"vad-helper-worklet\", {\n processorOptions: {\n frameSamples: this.options.frameSamples,\n },\n });\n this.entryNode = vadNode;\n const model = await _common_1.Silero.new(ort, model_fetcher_1.modelFetcher);\n this.frameProcessor = new _common_1.FrameProcessor(model.process, model.reset_state, {\n frameSamples: this.options.frameSamples,\n positiveSpeechThreshold: this.options.positiveSpeechThreshold,\n negativeSpeechThreshold: this.options.negativeSpeechThreshold,\n redemptionFrames: this.options.redemptionFrames,\n preSpeechPadFrames: this.options.preSpeechPadFrames,\n minSpeechFrames: this.options.minSpeechFrames,\n });\n vadNode.port.onmessage = async (ev) => {\n switch (ev.data?.message) {\n case _common_1.Message.AudioFrame:\n const buffer = ev.data.data;\n const frame = new Float32Array(buffer);\n await this.processFrame(frame);\n break;\n default:\n break;\n }\n };\n };\n (0, _common_1.validateOptions)(options);\n }\n}\nexports.AudioNodeVAD = AudioNodeVAD;\n//# sourceMappingURL=real-time-vad.js.map\n\n//# sourceURL=webpack://vad/./dist/real-time-vad.js?"); | ||
@@ -142,0 +142,0 @@ /***/ }), |
@@ -1,1 +0,1 @@ | ||
| !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("onnxruntime-web")):"function"==typeof define&&define.amd?define(["onnxruntime-web"],t):"object"==typeof exports?exports.vad=t(require("onnxruntime-web")):e.vad=t(e.ort)}(self,(e=>(()=>{"use strict";var t={428:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FrameProcessor=t.validateOptions=t.defaultFrameProcessorOptions=void 0;const i=s(294),o=s(842),r=[512,1024,1536];t.defaultFrameProcessorOptions={positiveSpeechThreshold:.5,negativeSpeechThreshold:.35,preSpeechPadFrames:1,redemptionFrames:8,frameSamples:1536,minSpeechFrames:3},t.validateOptions=function(e){r.includes(e.frameSamples)||o.log.warn("You are using an unusual frame size"),(e.positiveSpeechThreshold<0||e.negativeSpeechThreshold>1)&&o.log.error("postiveSpeechThreshold should be a number between 0 and 1"),(e.negativeSpeechThreshold<0||e.negativeSpeechThreshold>e.positiveSpeechThreshold)&&o.log.error("negativeSpeechThreshold should be between 0 and postiveSpeechThreshold"),e.preSpeechPadFrames<0&&o.log.error("preSpeechPadFrames should be positive"),e.redemptionFrames<0&&o.log.error("preSpeechPadFrames should be positive")};const n=e=>{const t=e.reduce(((e,t)=>(e.push(e.at(-1)+t.length),e)),[0]),s=new Float32Array(t.at(-1));return e.forEach(((e,i)=>{const o=t[i];s.set(e,o)})),s};t.FrameProcessor=class{constructor(e,t,s){this.modelProcessFunc=e,this.modelResetFunc=t,this.options=s,this.speaking=!1,this.redemptionCounter=0,this.active=!1,this.reset=()=>{this.speaking=!1,this.audioBuffer=[],this.modelResetFunc(),this.redemptionCounter=0},this.pause=()=>{this.active=!1,this.reset()},this.resume=()=>{this.active=!0},this.endSegment=()=>{const e=this.audioBuffer;this.audioBuffer=[];const t=this.speaking;this.reset();const s=e.reduce(((e,t)=>e+ +t.isSpeech),0);if(t){if(s>=this.options.minSpeechFrames){const t=n(e.map((e=>e.frame)));return{msg:i.Message.SpeechEnd,audio:t}}return{msg:i.Message.VADMisfire}}return{}},this.process=async e=>{if(!this.active)return{};const t=await this.modelProcessFunc(e);if(this.audioBuffer.push({frame:e,isSpeech:t.isSpeech>=this.options.positiveSpeechThreshold}),t.isSpeech>=this.options.positiveSpeechThreshold&&this.redemptionCounter&&(this.redemptionCounter=0),t.isSpeech>=this.options.positiveSpeechThreshold&&!this.speaking)return this.speaking=!0,{probs:t,msg:i.Message.SpeechStart};if(t.isSpeech<this.options.negativeSpeechThreshold&&this.speaking&&++this.redemptionCounter>=this.options.redemptionFrames){this.redemptionCounter=0,this.speaking=!1;const e=this.audioBuffer;if(this.audioBuffer=[],e.reduce(((e,t)=>e+ +t.isSpeech),0)>=this.options.minSpeechFrames){const s=n(e.map((e=>e.frame)));return{probs:t,msg:i.Message.SpeechEnd,audio:s}}return{probs:t,msg:i.Message.VADMisfire}}if(!this.speaking)for(;this.audioBuffer.length>this.options.preSpeechPadFrames;)this.audioBuffer.shift();return{probs:t}},this.audioBuffer=[],this.reset()}}},14:function(e,t,s){var i=this&&this.__createBinding||(Object.create?function(e,t,s,i){void 0===i&&(i=s);var o=Object.getOwnPropertyDescriptor(t,s);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,i,o)}:function(e,t,s,i){void 0===i&&(i=s),e[i]=t[s]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var s in e)"default"!==s&&Object.prototype.hasOwnProperty.call(e,s)&&i(t,e,s);return o(t,e),t},n=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||i(t,e,s)};Object.defineProperty(t,"__esModule",{value:!0}),t.utils=void 0;const a=r(s(26));t.utils={minFramesForTargetMS:a.minFramesForTargetMS,arrayBufferToBase64:a.arrayBufferToBase64,encodeWAV:a.encodeWAV},n(s(405),t),n(s(428),t),n(s(294),t),n(s(842),t),n(s(260),t),n(s(724),t)},842:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.log=t.LOG_PREFIX=void 0,t.LOG_PREFIX="[VAD]";const s=["error","debug","warn"].reduce(((e,s)=>(e[s]=function(e){return(...s)=>{console[e](t.LOG_PREFIX,...s)}}(s),e)),{});t.log=s},294:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.Message=void 0,(s=t.Message||(t.Message={})).AudioFrame="AUDIO_FRAME",s.SpeechStart="SPEECH_START",s.VADMisfire="VAD_MISFIRE",s.SpeechEnd="SPEECH_END"},260:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Silero=void 0;const i=s(842);class o{constructor(e,t){this.ort=e,this.modelFetcher=t,this.init=async()=>{i.log.debug("initializing vad");const e=await this.modelFetcher();this._session=await this.ort.InferenceSession.create(e),this._sr=new this.ort.Tensor("int64",[16000n]),this.reset_state(),i.log.debug("vad is initialized")},this.reset_state=()=>{const e=Array(128).fill(0);this._h=new this.ort.Tensor("float32",e,[2,1,64]),this._c=new this.ort.Tensor("float32",e,[2,1,64])},this.process=async e=>{const t={input:new this.ort.Tensor("float32",e,[1,e.length]),h:this._h,c:this._c,sr:this._sr},s=await this._session.run(t);this._h=s.hn,this._c=s.cn;const[i]=s.output.data;return{notSpeech:1-i,isSpeech:i}}}}t.Silero=o,o.new=async(e,t)=>{const s=new o(e,t);return await s.init(),s}},405:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PlatformAgnosticNonRealTimeVAD=t.defaultNonRealTimeVADOptions=void 0;const i=s(428),o=s(294),r=s(260),n=s(724);t.defaultNonRealTimeVADOptions={...i.defaultFrameProcessorOptions},t.PlatformAgnosticNonRealTimeVAD=class{static async _new(e,s,i={}){const o=new this(e,s,{...t.defaultNonRealTimeVADOptions,...i});return await o.init(),o}constructor(e,t,s){this.modelFetcher=e,this.ort=t,this.options=s,this.init=async()=>{const e=await r.Silero.new(this.ort,this.modelFetcher);this.frameProcessor=new i.FrameProcessor(e.process,e.reset_state,{frameSamples:this.options.frameSamples,positiveSpeechThreshold:this.options.positiveSpeechThreshold,negativeSpeechThreshold:this.options.negativeSpeechThreshold,redemptionFrames:this.options.redemptionFrames,preSpeechPadFrames:this.options.preSpeechPadFrames,minSpeechFrames:this.options.minSpeechFrames}),this.frameProcessor.resume()},this.run=async function*(e,t){const s={nativeSampleRate:t,targetSampleRate:16e3,targetFrameSize:this.options.frameSamples},i=new n.Resampler(s).process(e);let r,a;for(const e of[...Array(i.length)].keys()){const t=i[e],{msg:s,audio:n}=await this.frameProcessor.process(t);switch(s){case o.Message.SpeechStart:r=e*this.options.frameSamples/16;break;case o.Message.SpeechEnd:a=(e+1)*this.options.frameSamples/16,yield{audio:n,start:r,end:a}}}const{msg:c,audio:h}=this.frameProcessor.endSegment();c==o.Message.SpeechEnd&&(yield{audio:h,start:r,end:i.length*this.options.frameSamples/16})},(0,i.validateOptions)(s)}}},724:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Resampler=void 0;const i=s(842);t.Resampler=class{constructor(e){this.options=e,this.process=e=>{const t=[];for(const t of e)this.inputBuffer.push(t);for(;this.inputBuffer.length*this.options.targetSampleRate/this.options.nativeSampleRate>this.options.targetFrameSize;){const e=new Float32Array(this.options.targetFrameSize);let s=0,i=0;for(;s<this.options.targetFrameSize;){let t=0,o=0;for(;i<Math.min(this.inputBuffer.length,(s+1)*this.options.nativeSampleRate/this.options.targetSampleRate);)t+=this.inputBuffer[i],o++,i++;e[s]=t/o,s++}this.inputBuffer=this.inputBuffer.slice(i),t.push(e)}return t},e.nativeSampleRate<16e3&&i.log.error("nativeSampleRate is too low. Should have 16000 = targetSampleRate <= nativeSampleRate"),this.inputBuffer=[]}}},26:(e,t)=>{function s(e,t,s){for(var i=0;i<s.length;i++)e.setUint8(t+i,s.charCodeAt(i))}Object.defineProperty(t,"__esModule",{value:!0}),t.encodeWAV=t.arrayBufferToBase64=t.minFramesForTargetMS=void 0,t.minFramesForTargetMS=function(e,t,s=16e3){return Math.ceil(e*s/1e3/t)},t.arrayBufferToBase64=function(e){for(var t="",s=new Uint8Array(e),i=s.byteLength,o=0;o<i;o++)t+=String.fromCharCode(s[o]);return btoa(t)},t.encodeWAV=function(e,t=3,i=16e3,o=1,r=32){var n=r/8,a=o*n,c=new ArrayBuffer(44+e.length*n),h=new DataView(c);return s(h,0,"RIFF"),h.setUint32(4,36+e.length*n,!0),s(h,8,"WAVE"),s(h,12,"fmt "),h.setUint32(16,16,!0),h.setUint16(20,t,!0),h.setUint16(22,o,!0),h.setUint32(24,i,!0),h.setUint32(28,i*a,!0),h.setUint16(32,a,!0),h.setUint16(34,r,!0),s(h,36,"data"),h.setUint32(40,e.length*n,!0),1===t?function(e,t,s){for(var i=0;i<s.length;i++,t+=2){var o=Math.max(-1,Math.min(1,s[i]));e.setInt16(t,o<0?32768*o:32767*o,!0)}}(h,44,e):function(e,t,s){for(var i=0;i<s.length;i++,t+=4)e.setFloat32(t,s[i],!0)}(h,44,e),c}},485:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.assetPath=void 0;const s=window.document.currentScript;let i="";s&&(i=s.src.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/")),t.assetPath=e=>i+e},590:function(e,t,s){var i=this&&this.__createBinding||(Object.create?function(e,t,s,i){void 0===i&&(i=s);var o=Object.getOwnPropertyDescriptor(t,s);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,i,o)}:function(e,t,s,i){void 0===i&&(i=s),e[i]=t[s]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var s in e)"default"!==s&&Object.prototype.hasOwnProperty.call(e,s)&&i(t,e,s);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.defaultRealTimeVADOptions=t.AudioNodeVAD=t.MicVAD=t.NonRealTimeVAD=t.Message=t.FrameProcessor=t.utils=void 0;const n=r(s(656)),a=s(14);Object.defineProperty(t,"FrameProcessor",{enumerable:!0,get:function(){return a.FrameProcessor}}),Object.defineProperty(t,"Message",{enumerable:!0,get:function(){return a.Message}});const c=s(273),h=s(787);class u extends a.PlatformAgnosticNonRealTimeVAD{static async new(e={}){return await this._new(c.modelFetcher,n,e)}}t.NonRealTimeVAD=u,t.utils={audioFileToArray:h.audioFileToArray,...a.utils};var l=s(746);Object.defineProperty(t,"MicVAD",{enumerable:!0,get:function(){return l.MicVAD}}),Object.defineProperty(t,"AudioNodeVAD",{enumerable:!0,get:function(){return l.AudioNodeVAD}}),Object.defineProperty(t,"defaultRealTimeVADOptions",{enumerable:!0,get:function(){return l.defaultRealTimeVADOptions}})},273:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.modelFetcher=void 0;const i=s(485);t.modelFetcher=async()=>{const e=(0,i.assetPath)("silero_vad.onnx");return await fetch(e).then((e=>e.arrayBuffer()))}},746:function(e,t,s){var i=this&&this.__createBinding||(Object.create?function(e,t,s,i){void 0===i&&(i=s);var o=Object.getOwnPropertyDescriptor(t,s);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,i,o)}:function(e,t,s,i){void 0===i&&(i=s),e[i]=t[s]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var s in e)"default"!==s&&Object.prototype.hasOwnProperty.call(e,s)&&i(t,e,s);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.AudioNodeVAD=t.MicVAD=t.defaultRealTimeVADOptions=void 0;const n=r(s(656)),a=s(14),c=s(273),h=s(485);t.defaultRealTimeVADOptions={...a.defaultFrameProcessorOptions,onFrameProcessed:e=>{},onVADMisfire:()=>{a.log.debug("VAD misfire")},onSpeechStart:()=>{a.log.debug("Detected speech start")},onSpeechEnd:()=>{a.log.debug("Detected speech end")},workletURL:(0,h.assetPath)("vad.worklet.bundle.min.js"),stream:void 0};class u{static async new(e={}){const s=new u({...t.defaultRealTimeVADOptions,...e});return await s.init(),s}constructor(e){this.options=e,this.listening=!1,this.init=async()=>{void 0===this.options.stream?this.stream=await navigator.mediaDevices.getUserMedia({audio:{...this.options.additionalAudioConstraints,channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0}}):this.stream=this.options.stream,this.audioContext=new AudioContext;const e=new MediaStreamAudioSourceNode(this.audioContext,{mediaStream:this.stream});this.audioNodeVAD=await l.new(this.audioContext,this.options),this.audioNodeVAD.receive(e)},this.pause=()=>{this.audioNodeVAD.pause(),this.listening=!1},this.start=()=>{this.audioNodeVAD.start(),this.listening=!0},this.destroy=()=>{this.listening&&this.pause(),this.stream.getTracks().forEach((e=>e.stop()))},(0,a.validateOptions)(e)}}t.MicVAD=u;class l{static async new(e,s={}){const i=new l(e,{...t.defaultRealTimeVADOptions,...s});return await i.init(),i}constructor(e,t){this.ctx=e,this.options=t,this.pause=()=>{this.frameProcessor.pause()},this.start=()=>{this.frameProcessor.resume()},this.receive=e=>{e.connect(this.entryNode)},this.processFrame=async e=>{const{probs:t,msg:s,audio:i}=await this.frameProcessor.process(e);switch(void 0!==t&&this.options.onFrameProcessed(t),s){case a.Message.SpeechStart:this.options.onSpeechStart();break;case a.Message.VADMisfire:this.options.onVADMisfire();break;case a.Message.SpeechEnd:this.options.onSpeechEnd(i)}},this.init=async()=>{await this.ctx.audioWorklet.addModule(this.options.workletURL);const e=new AudioWorkletNode(this.ctx,"vad-helper-worklet",{processorOptions:{frameSamples:this.options.frameSamples}});this.entryNode=e;const t=await a.Silero.new(n,c.modelFetcher);this.frameProcessor=new a.FrameProcessor(t.process,t.reset_state,{frameSamples:this.options.frameSamples,positiveSpeechThreshold:this.options.positiveSpeechThreshold,negativeSpeechThreshold:this.options.negativeSpeechThreshold,redemptionFrames:this.options.redemptionFrames,preSpeechPadFrames:this.options.preSpeechPadFrames,minSpeechFrames:this.options.minSpeechFrames}),e.port.onmessage=async e=>{if(e.data?.message===a.Message.AudioFrame){const t=e.data.data,s=new Float32Array(t);await this.processFrame(s)}}},(0,a.validateOptions)(t)}}t.AudioNodeVAD=l},787:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.audioFileToArray=void 0,t.audioFileToArray=async function(e){const t=new OfflineAudioContext(1,1,44100),s=new FileReader;let i=null;if(await new Promise((o=>{s.addEventListener("loadend",(e=>{const r=s.result;t.decodeAudioData(r,(e=>{i=e,t.startRendering().then((e=>{console.log("Rendering completed successfully"),o()})).catch((e=>{console.error(`Rendering failed: ${e}`)}))}),(e=>{console.log(`Error with decoding audio data: ${e}`)}))})),s.readAsArrayBuffer(e)})),null===i)throw Error("some shit");let o=i,r=new Float32Array(o.length);for(let e=0;e<o.length;e++)for(let t=0;t<o.numberOfChannels;t++)r[e]+=o.getChannelData(t)[e];return{audio:r,sampleRate:o.sampleRate}}},656:t=>{t.exports=e}},s={};return function e(i){var o=s[i];if(void 0!==o)return o.exports;var r=s[i]={exports:{}};return t[i].call(r.exports,r,r.exports,e),r.exports}(590)})())); | ||
| !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("onnxruntime-web")):"function"==typeof define&&define.amd?define(["onnxruntime-web"],t):"object"==typeof exports?exports.vad=t(require("onnxruntime-web")):e.vad=t(e.ort)}(self,(e=>(()=>{"use strict";var t={428:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FrameProcessor=t.validateOptions=t.defaultFrameProcessorOptions=void 0;const i=s(294),o=s(842),r=[512,1024,1536];t.defaultFrameProcessorOptions={positiveSpeechThreshold:.5,negativeSpeechThreshold:.35,preSpeechPadFrames:1,redemptionFrames:8,frameSamples:1536,minSpeechFrames:3},t.validateOptions=function(e){r.includes(e.frameSamples)||o.log.warn("You are using an unusual frame size"),(e.positiveSpeechThreshold<0||e.negativeSpeechThreshold>1)&&o.log.error("postiveSpeechThreshold should be a number between 0 and 1"),(e.negativeSpeechThreshold<0||e.negativeSpeechThreshold>e.positiveSpeechThreshold)&&o.log.error("negativeSpeechThreshold should be between 0 and postiveSpeechThreshold"),e.preSpeechPadFrames<0&&o.log.error("preSpeechPadFrames should be positive"),e.redemptionFrames<0&&o.log.error("preSpeechPadFrames should be positive")};const n=e=>{const t=e.reduce(((e,t)=>(e.push(e.at(-1)+t.length),e)),[0]),s=new Float32Array(t.at(-1));return e.forEach(((e,i)=>{const o=t[i];s.set(e,o)})),s};t.FrameProcessor=class{constructor(e,t,s){this.modelProcessFunc=e,this.modelResetFunc=t,this.options=s,this.speaking=!1,this.redemptionCounter=0,this.active=!1,this.reset=()=>{this.speaking=!1,this.audioBuffer=[],this.modelResetFunc(),this.redemptionCounter=0},this.pause=()=>{this.active=!1,this.reset()},this.resume=()=>{this.active=!0},this.endSegment=()=>{const e=this.audioBuffer;this.audioBuffer=[];const t=this.speaking;this.reset();const s=e.reduce(((e,t)=>e+ +t.isSpeech),0);if(t){if(s>=this.options.minSpeechFrames){const t=n(e.map((e=>e.frame)));return{msg:i.Message.SpeechEnd,audio:t}}return{msg:i.Message.VADMisfire}}return{}},this.process=async e=>{if(!this.active)return{};const t=await this.modelProcessFunc(e);if(this.audioBuffer.push({frame:e,isSpeech:t.isSpeech>=this.options.positiveSpeechThreshold}),t.isSpeech>=this.options.positiveSpeechThreshold&&this.redemptionCounter&&(this.redemptionCounter=0),t.isSpeech>=this.options.positiveSpeechThreshold&&!this.speaking)return this.speaking=!0,{probs:t,msg:i.Message.SpeechStart};if(t.isSpeech<this.options.negativeSpeechThreshold&&this.speaking&&++this.redemptionCounter>=this.options.redemptionFrames){this.redemptionCounter=0,this.speaking=!1;const e=this.audioBuffer;if(this.audioBuffer=[],e.reduce(((e,t)=>e+ +t.isSpeech),0)>=this.options.minSpeechFrames){const s=n(e.map((e=>e.frame)));return{probs:t,msg:i.Message.SpeechEnd,audio:s}}return{probs:t,msg:i.Message.VADMisfire}}if(!this.speaking)for(;this.audioBuffer.length>this.options.preSpeechPadFrames;)this.audioBuffer.shift();return{probs:t}},this.audioBuffer=[],this.reset()}}},14:function(e,t,s){var i=this&&this.__createBinding||(Object.create?function(e,t,s,i){void 0===i&&(i=s);var o=Object.getOwnPropertyDescriptor(t,s);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,i,o)}:function(e,t,s,i){void 0===i&&(i=s),e[i]=t[s]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var s in e)"default"!==s&&Object.prototype.hasOwnProperty.call(e,s)&&i(t,e,s);return o(t,e),t},n=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||i(t,e,s)};Object.defineProperty(t,"__esModule",{value:!0}),t.utils=void 0;const a=r(s(26));t.utils={minFramesForTargetMS:a.minFramesForTargetMS,arrayBufferToBase64:a.arrayBufferToBase64,encodeWAV:a.encodeWAV},n(s(405),t),n(s(428),t),n(s(294),t),n(s(842),t),n(s(260),t),n(s(724),t)},842:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.log=t.LOG_PREFIX=void 0,t.LOG_PREFIX="[VAD]";const s=["error","debug","warn"].reduce(((e,s)=>(e[s]=function(e){return(...s)=>{console[e](t.LOG_PREFIX,...s)}}(s),e)),{});t.log=s},294:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.Message=void 0,(s=t.Message||(t.Message={})).AudioFrame="AUDIO_FRAME",s.SpeechStart="SPEECH_START",s.VADMisfire="VAD_MISFIRE",s.SpeechEnd="SPEECH_END"},260:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Silero=void 0;const i=s(842);class o{constructor(e,t){this.ort=e,this.modelFetcher=t,this.init=async()=>{i.log.debug("initializing vad");const e=await this.modelFetcher();this._session=await this.ort.InferenceSession.create(e),this._sr=new this.ort.Tensor("int64",[16000n]),this.reset_state(),i.log.debug("vad is initialized")},this.reset_state=()=>{const e=Array(128).fill(0);this._h=new this.ort.Tensor("float32",e,[2,1,64]),this._c=new this.ort.Tensor("float32",e,[2,1,64])},this.process=async e=>{const t={input:new this.ort.Tensor("float32",e,[1,e.length]),h:this._h,c:this._c,sr:this._sr},s=await this._session.run(t);this._h=s.hn,this._c=s.cn;const[i]=s.output.data;return{notSpeech:1-i,isSpeech:i}}}}t.Silero=o,o.new=async(e,t)=>{const s=new o(e,t);return await s.init(),s}},405:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PlatformAgnosticNonRealTimeVAD=t.defaultNonRealTimeVADOptions=void 0;const i=s(428),o=s(294),r=s(260),n=s(724);t.defaultNonRealTimeVADOptions={...i.defaultFrameProcessorOptions},t.PlatformAgnosticNonRealTimeVAD=class{static async _new(e,s,i={}){const o=new this(e,s,{...t.defaultNonRealTimeVADOptions,...i});return await o.init(),o}constructor(e,t,s){this.modelFetcher=e,this.ort=t,this.options=s,this.init=async()=>{const e=await r.Silero.new(this.ort,this.modelFetcher);this.frameProcessor=new i.FrameProcessor(e.process,e.reset_state,{frameSamples:this.options.frameSamples,positiveSpeechThreshold:this.options.positiveSpeechThreshold,negativeSpeechThreshold:this.options.negativeSpeechThreshold,redemptionFrames:this.options.redemptionFrames,preSpeechPadFrames:this.options.preSpeechPadFrames,minSpeechFrames:this.options.minSpeechFrames}),this.frameProcessor.resume()},this.run=async function*(e,t){const s={nativeSampleRate:t,targetSampleRate:16e3,targetFrameSize:this.options.frameSamples},i=new n.Resampler(s).process(e);let r,a;for(const e of[...Array(i.length)].keys()){const t=i[e],{msg:s,audio:n}=await this.frameProcessor.process(t);switch(s){case o.Message.SpeechStart:r=e*this.options.frameSamples/16;break;case o.Message.SpeechEnd:a=(e+1)*this.options.frameSamples/16,yield{audio:n,start:r,end:a}}}const{msg:c,audio:h}=this.frameProcessor.endSegment();c==o.Message.SpeechEnd&&(yield{audio:h,start:r,end:i.length*this.options.frameSamples/16})},(0,i.validateOptions)(s)}}},724:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Resampler=void 0;const i=s(842);t.Resampler=class{constructor(e){this.options=e,this.process=e=>{const t=[];for(const t of e)this.inputBuffer.push(t);for(;this.inputBuffer.length*this.options.targetSampleRate/this.options.nativeSampleRate>this.options.targetFrameSize;){const e=new Float32Array(this.options.targetFrameSize);let s=0,i=0;for(;s<this.options.targetFrameSize;){let t=0,o=0;for(;i<Math.min(this.inputBuffer.length,(s+1)*this.options.nativeSampleRate/this.options.targetSampleRate);)t+=this.inputBuffer[i],o++,i++;e[s]=t/o,s++}this.inputBuffer=this.inputBuffer.slice(i),t.push(e)}return t},e.nativeSampleRate<16e3&&i.log.error("nativeSampleRate is too low. Should have 16000 = targetSampleRate <= nativeSampleRate"),this.inputBuffer=[]}}},26:(e,t)=>{function s(e,t,s){for(var i=0;i<s.length;i++)e.setUint8(t+i,s.charCodeAt(i))}Object.defineProperty(t,"__esModule",{value:!0}),t.encodeWAV=t.arrayBufferToBase64=t.minFramesForTargetMS=void 0,t.minFramesForTargetMS=function(e,t,s=16e3){return Math.ceil(e*s/1e3/t)},t.arrayBufferToBase64=function(e){for(var t="",s=new Uint8Array(e),i=s.byteLength,o=0;o<i;o++)t+=String.fromCharCode(s[o]);return btoa(t)},t.encodeWAV=function(e,t=3,i=16e3,o=1,r=32){var n=r/8,a=o*n,c=new ArrayBuffer(44+e.length*n),h=new DataView(c);return s(h,0,"RIFF"),h.setUint32(4,36+e.length*n,!0),s(h,8,"WAVE"),s(h,12,"fmt "),h.setUint32(16,16,!0),h.setUint16(20,t,!0),h.setUint16(22,o,!0),h.setUint32(24,i,!0),h.setUint32(28,i*a,!0),h.setUint16(32,a,!0),h.setUint16(34,r,!0),s(h,36,"data"),h.setUint32(40,e.length*n,!0),1===t?function(e,t,s){for(var i=0;i<s.length;i++,t+=2){var o=Math.max(-1,Math.min(1,s[i]));e.setInt16(t,o<0?32768*o:32767*o,!0)}}(h,44,e):function(e,t,s){for(var i=0;i<s.length;i++,t+=4)e.setFloat32(t,s[i],!0)}(h,44,e),c}},485:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.assetPath=void 0;const s=window.document.currentScript;let i="";s&&(i=s.src.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/")),t.assetPath=e=>i+e},590:function(e,t,s){var i=this&&this.__createBinding||(Object.create?function(e,t,s,i){void 0===i&&(i=s);var o=Object.getOwnPropertyDescriptor(t,s);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,i,o)}:function(e,t,s,i){void 0===i&&(i=s),e[i]=t[s]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var s in e)"default"!==s&&Object.prototype.hasOwnProperty.call(e,s)&&i(t,e,s);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.defaultRealTimeVADOptions=t.AudioNodeVAD=t.MicVAD=t.NonRealTimeVAD=t.Message=t.FrameProcessor=t.utils=void 0;const n=r(s(656)),a=s(14);Object.defineProperty(t,"FrameProcessor",{enumerable:!0,get:function(){return a.FrameProcessor}}),Object.defineProperty(t,"Message",{enumerable:!0,get:function(){return a.Message}});const c=s(273),h=s(787);class u extends a.PlatformAgnosticNonRealTimeVAD{static async new(e={}){return await this._new(c.modelFetcher,n,e)}}t.NonRealTimeVAD=u,t.utils={audioFileToArray:h.audioFileToArray,...a.utils};var l=s(746);Object.defineProperty(t,"MicVAD",{enumerable:!0,get:function(){return l.MicVAD}}),Object.defineProperty(t,"AudioNodeVAD",{enumerable:!0,get:function(){return l.AudioNodeVAD}}),Object.defineProperty(t,"defaultRealTimeVADOptions",{enumerable:!0,get:function(){return l.defaultRealTimeVADOptions}})},273:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.modelFetcher=void 0;const i=s(485);t.modelFetcher=async()=>{const e=(0,i.assetPath)("silero_vad.onnx");return await fetch(e).then((e=>e.arrayBuffer()))}},746:function(e,t,s){var i=this&&this.__createBinding||(Object.create?function(e,t,s,i){void 0===i&&(i=s);var o=Object.getOwnPropertyDescriptor(t,s);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,i,o)}:function(e,t,s,i){void 0===i&&(i=s),e[i]=t[s]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var s in e)"default"!==s&&Object.prototype.hasOwnProperty.call(e,s)&&i(t,e,s);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.AudioNodeVAD=t.MicVAD=t.defaultRealTimeVADOptions=void 0;const n=r(s(656)),a=s(14),c=s(273),h=s(485);t.defaultRealTimeVADOptions={...a.defaultFrameProcessorOptions,onFrameProcessed:e=>{},onVADMisfire:()=>{a.log.debug("VAD misfire")},onSpeechStart:()=>{a.log.debug("Detected speech start")},onSpeechEnd:()=>{a.log.debug("Detected speech end")},workletURL:(0,h.assetPath)("vad.worklet.bundle.min.js"),stream:void 0};class u{static async new(e={}){const s=new u({...t.defaultRealTimeVADOptions,...e});return await s.init(),s}constructor(e){this.options=e,this.listening=!1,this.init=async()=>{void 0===this.options.stream?this.stream=await navigator.mediaDevices.getUserMedia({audio:{...this.options.additionalAudioConstraints,channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0}}):this.stream=this.options.stream,this.audioContext=new AudioContext;const e=new MediaStreamAudioSourceNode(this.audioContext,{mediaStream:this.stream});this.audioNodeVAD=await l.new(this.audioContext,this.options),this.audioNodeVAD.receive(e)},this.pause=()=>{this.audioNodeVAD.pause(),this.listening=!1},this.start=()=>{this.audioNodeVAD.start(),this.listening=!0},this.destroy=()=>{this.listening&&this.pause(),this.stream.getTracks().forEach((e=>e.stop())),this.audioContext.close()},(0,a.validateOptions)(e)}}t.MicVAD=u;class l{static async new(e,s={}){const i=new l(e,{...t.defaultRealTimeVADOptions,...s});return await i.init(),i}constructor(e,t){this.ctx=e,this.options=t,this.pause=()=>{this.frameProcessor.pause()},this.start=()=>{this.frameProcessor.resume()},this.receive=e=>{e.connect(this.entryNode)},this.processFrame=async e=>{const{probs:t,msg:s,audio:i}=await this.frameProcessor.process(e);switch(void 0!==t&&this.options.onFrameProcessed(t),s){case a.Message.SpeechStart:this.options.onSpeechStart();break;case a.Message.VADMisfire:this.options.onVADMisfire();break;case a.Message.SpeechEnd:this.options.onSpeechEnd(i)}},this.init=async()=>{await this.ctx.audioWorklet.addModule(this.options.workletURL);const e=new AudioWorkletNode(this.ctx,"vad-helper-worklet",{processorOptions:{frameSamples:this.options.frameSamples}});this.entryNode=e;const t=await a.Silero.new(n,c.modelFetcher);this.frameProcessor=new a.FrameProcessor(t.process,t.reset_state,{frameSamples:this.options.frameSamples,positiveSpeechThreshold:this.options.positiveSpeechThreshold,negativeSpeechThreshold:this.options.negativeSpeechThreshold,redemptionFrames:this.options.redemptionFrames,preSpeechPadFrames:this.options.preSpeechPadFrames,minSpeechFrames:this.options.minSpeechFrames}),e.port.onmessage=async e=>{if(e.data?.message===a.Message.AudioFrame){const t=e.data.data,s=new Float32Array(t);await this.processFrame(s)}}},(0,a.validateOptions)(t)}}t.AudioNodeVAD=l},787:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.audioFileToArray=void 0,t.audioFileToArray=async function(e){const t=new OfflineAudioContext(1,1,44100),s=new FileReader;let i=null;if(await new Promise((o=>{s.addEventListener("loadend",(e=>{const r=s.result;t.decodeAudioData(r,(e=>{i=e,t.startRendering().then((e=>{console.log("Rendering completed successfully"),o()})).catch((e=>{console.error(`Rendering failed: ${e}`)}))}),(e=>{console.log(`Error with decoding audio data: ${e}`)}))})),s.readAsArrayBuffer(e)})),null===i)throw Error("some shit");let o=i,r=new Float32Array(o.length);for(let e=0;e<o.length;e++)for(let t=0;t<o.numberOfChannels;t++)r[e]+=o.getChannelData(t)[e];return{audio:r,sampleRate:o.sampleRate}}},656:t=>{t.exports=e}},s={};return function e(i){var o=s[i];if(void 0!==o)return o.exports;var r=s[i]={exports:{}};return t[i].call(r.exports,r,r.exports,e),r.exports}(590)})())); |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"real-time-vad.d.ts","sourceRoot":"","sources":["../src/real-time-vad.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,mBAAmB,EAEnB,cAAc,EACd,qBAAqB,EAEtB,MAAM,WAAW,CAAA;AAIlB,UAAU,oBAAoB;IAC5B,4GAA4G;IAC5G,gBAAgB,EAAE,CAAC,aAAa,EAAE,mBAAmB,KAAK,GAAG,CAAA;IAE7D;;OAEG;IACH,YAAY,EAAE,MAAM,GAAG,CAAA;IAEvB,oDAAoD;IACpD,aAAa,EAAE,MAAM,GAAG,CAAA;IAExB;;;;OAIG;IACH,WAAW,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,GAAG,CAAA;CAC1C;AAED;;;GAGG;AACH,KAAK,gBAAgB,GAAG,IAAI,CAC1B,qBAAqB,EACrB,cAAc,GAAG,kBAAkB,GAAG,iBAAiB,GAAG,kBAAkB,CAC7E,CAAA;AAED,UAAU,+BACR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;IAE9B,SAAS,EAAE,SAAS,CAAA;WAEP,GAAG,CACd,GAAG,EAAE,YAAY,EACjB,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAM;gBAUxB,GAAG,EAAE,YAAY,EAAS,OAAO,EAAE,kBAAkB;IAIxE,KAAK,aAEJ;IAED,KAAK,aAEJ;IAED,OAAO,SAAU,SAAS,UAEzB;IAED,YAAY,UAAiB,YAAY,mBAsBxC;IAED,IAAI,sBAgCH;CACF"} |
@@ -90,3 +90,4 @@ "use strict"; | ||
| } | ||
| this.stream.getTracks().forEach(t => t.stop()); | ||
| this.stream.getTracks().forEach((t) => t.stop()); | ||
| this.audioContext.close(); | ||
| }; | ||
@@ -93,0 +94,0 @@ (0, _common_1.validateOptions)(options); |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"real-time-vad.js","sourceRoot":"","sources":["../src/real-time-vad.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAsC;AACtC,uCASkB;AAClB,mDAA8C;AAC9C,6CAAwC;AAkDxC,MAAM,cAAc,GAAG,GAAG,EAAE;IAC1B,OAAO,IAAA,sBAAS,EAAC,2BAA2B,CAAC,CAAA;AAC/C,CAAC,CAAA;AAEY,QAAA,yBAAyB,GAAuB;IAC3D,GAAG,sCAA4B;IAC/B,gBAAgB,EAAE,CAAC,aAAa,EAAE,EAAE,GAAE,CAAC;IACvC,YAAY,EAAE,GAAG,EAAE;QACjB,aAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;IAC1B,CAAC;IACD,aAAa,EAAE,GAAG,EAAE;QAClB,aAAG,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAA;IACpC,CAAC;IACD,WAAW,EAAE,GAAG,EAAE;QAChB,aAAG,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAA;IAClC,CAAC;IACD,UAAU,EAAE,cAAc,EAAE;IAC5B,MAAM,EAAE,SAAS;CAClB,CAAA;AAED,MAAa,MAAM;IASjB,M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AK,GAAG,MAAM,gBAAM,CAAC,GAAG,CAAC,GAAG,EAAE,4BAAY,CAAC,CAAA;YAEjD,IAAI,CAAC,cAAc,GAAG,IAAI,wBAAc,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,WAAW,EAAE;gBACzE,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY;gBACvC,uBAAuB,EAAE,IAAI,CAAC,OAAO,CAAC,uBAAuB;gBAC7D,uBAAuB,EAAE,IAAI,CAAC,OAAO,CAAC,uBAAuB;gBAC7D,gBAAgB,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB;gBAC/C,kBAAkB,EAAE,IAAI,CAAC,OAAO,CAAC,kBAAkB;gBACnD,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,eAAe;aAC9C,CAAC,CAAA;YAEF,OAAO,CAAC,IAAI,CAAC,SAAS,GAAG,KAAK,EAAE,EAAgB,EAAE,EAAE;gBAClD,QAAQ,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE;oBACxB,KAAK,iBAAO,CAAC,UAAU;wBACrB,MAAM,MAAM,GAAgB,EAAE,CAAC,IAAI,CAAC,IAAI,CAAA;wBACxC,MAAM,KAAK,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAA;wBACtC,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;wBAC9B,MAAK;oBAEP;wBACE,MAAK;iBACR;YACH,CAAC,CAAA;QACH,CAAC,CAAA;QAvEC,IAAA,yBAAe,EAAC,OAAO,CAAC,CAAA;IAC1B,CAAC;CAuEF;AA3FD,oCA2FC"} |
@@ -19,3 +19,3 @@ /* | ||
| eval("\n/*\nSome of this code, together with the default options found in index.ts,\nwere taken (or took inspiration) from https://github.com/snakers4/silero-vad\n*/\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.FrameProcessor = exports.validateOptions = exports.defaultFrameProcessorOptions = void 0;\nconst messages_1 = __webpack_require__(/*! ./messages */ \"./dist/_common/messages.js\");\nconst logging_1 = __webpack_require__(/*! ./logging */ \"./dist/_common/logging.js\");\nconst RECOMMENDED_FRAME_SAMPLES = [512, 1024, 1536];\nexports.defaultFrameProcessorOptions = {\n positiveSpeechThreshold: 0.5,\n negativeSpeechThreshold: 0.5 - 0.15,\n preSpeechPadFrames: 1,\n redemptionFrames: 8,\n frameSamples: 1536,\n minSpeechFrames: 3,\n};\nfunction validateOptions(options) {\n if (!RECOMMENDED_FRAME_SAMPLES.includes(options.frameSamples)) {\n logging_1.log.warn(\"You are using an unusual frame size\");\n }\n if (options.positiveSpeechThreshold < 0 ||\n options.negativeSpeechThreshold > 1) {\n logging_1.log.error(\"postiveSpeechThreshold should be a number between 0 and 1\");\n }\n if (options.negativeSpeechThreshold < 0 ||\n options.negativeSpeechThreshold > options.positiveSpeechThreshold) {\n logging_1.log.error(\"negativeSpeechThreshold should be between 0 and postiveSpeechThreshold\");\n }\n if (options.preSpeechPadFrames < 0) {\n logging_1.log.error(\"preSpeechPadFrames should be positive\");\n }\n if (options.redemptionFrames < 0) {\n logging_1.log.error(\"preSpeechPadFrames should be positive\");\n }\n}\nexports.validateOptions = validateOptions;\nconst concatArrays = (arrays) => {\n const sizes = arrays.reduce((out, next) => {\n out.push(out.at(-1) + next.length);\n return out;\n }, [0]);\n const outArray = new Float32Array(sizes.at(-1));\n arrays.forEach((arr, index) => {\n const place = sizes[index];\n outArray.set(arr, place);\n });\n return outArray;\n};\nclass FrameProcessor {\n constructor(modelProcessFunc, modelResetFunc, options) {\n this.modelProcessFunc = modelProcessFunc;\n this.modelResetFunc = modelResetFunc;\n this.options = options;\n this.speaking = false;\n this.redemptionCounter = 0;\n this.active = false;\n this.reset = () => {\n this.speaking = false;\n this.audioBuffer = [];\n this.modelResetFunc();\n this.redemptionCounter = 0;\n };\n this.pause = () => {\n this.active = false;\n this.reset();\n };\n this.resume = () => {\n this.active = true;\n };\n this.endSegment = () => {\n const audioBuffer = this.audioBuffer;\n this.audioBuffer = [];\n const speaking = this.speaking;\n this.reset();\n const speechFrameCount = audioBuffer.reduce((acc, item) => {\n return acc + +item.isSpeech;\n }, 0);\n if (speaking) {\n if (speechFrameCount >= this.options.minSpeechFrames) {\n const audio = concatArrays(audioBuffer.map((item) => item.frame));\n return { msg: messages_1.Message.SpeechEnd, audio };\n }\n else {\n return { msg: messages_1.Message.VADMisfire };\n }\n }\n return {};\n };\n this.process = async (frame) => {\n if (!this.active) {\n return {};\n }\n const probs = await this.modelProcessFunc(frame);\n this.audioBuffer.push({\n frame,\n isSpeech: probs.isSpeech >= this.options.positiveSpeechThreshold,\n });\n if (probs.isSpeech >= this.options.positiveSpeechThreshold &&\n this.redemptionCounter) {\n this.redemptionCounter = 0;\n }\n if (probs.isSpeech >= this.options.positiveSpeechThreshold &&\n !this.speaking) {\n this.speaking = true;\n return { probs, msg: messages_1.Message.SpeechStart };\n }\n if (probs.isSpeech < this.options.negativeSpeechThreshold &&\n this.speaking &&\n ++this.redemptionCounter >= this.options.redemptionFrames) {\n this.redemptionCounter = 0;\n this.speaking = false;\n const audioBuffer = this.audioBuffer;\n this.audioBuffer = [];\n const speechFrameCount = audioBuffer.reduce((acc, item) => {\n return acc + +item.isSpeech;\n }, 0);\n if (speechFrameCount >= this.options.minSpeechFrames) {\n const audio = concatArrays(audioBuffer.map((item) => item.frame));\n return { probs, msg: messages_1.Message.SpeechEnd, audio };\n }\n else {\n return { probs, msg: messages_1.Message.VADMisfire };\n }\n }\n if (!this.speaking) {\n while (this.audioBuffer.length > this.options.preSpeechPadFrames) {\n this.audioBuffer.shift();\n }\n }\n return { probs };\n };\n this.audioBuffer = [];\n this.reset();\n }\n}\nexports.FrameProcessor = FrameProcessor;\n//# sourceMappingURL=frame-processor.js.map\n\n//# sourceURL=webpack://@ricky0123/vad-web/./dist/_common/frame-processor.js?"); | ||
| eval("\n/*\nSome of this code, together with the default options found in index.ts,\nwere taken (or took inspiration) from https://github.com/snakers4/silero-vad\n*/\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.FrameProcessor = exports.validateOptions = exports.defaultFrameProcessorOptions = void 0;\nconst messages_1 = __webpack_require__(/*! ./messages */ \"./dist/_common/messages.js\");\nconst logging_1 = __webpack_require__(/*! ./logging */ \"./dist/_common/logging.js\");\nconst RECOMMENDED_FRAME_SAMPLES = [512, 1024, 1536];\nexports.defaultFrameProcessorOptions = {\n positiveSpeechThreshold: 0.5,\n negativeSpeechThreshold: 0.5 - 0.15,\n preSpeechPadFrames: 1,\n redemptionFrames: 8,\n frameSamples: 1536,\n minSpeechFrames: 3,\n};\nfunction validateOptions(options) {\n if (!RECOMMENDED_FRAME_SAMPLES.includes(options.frameSamples)) {\n logging_1.log.warn(\"You are using an unusual frame size\");\n }\n if (options.positiveSpeechThreshold < 0 ||\n options.negativeSpeechThreshold > 1) {\n logging_1.log.error(\"postiveSpeechThreshold should be a number between 0 and 1\");\n }\n if (options.negativeSpeechThreshold < 0 ||\n options.negativeSpeechThreshold > options.positiveSpeechThreshold) {\n logging_1.log.error(\"negativeSpeechThreshold should be between 0 and postiveSpeechThreshold\");\n }\n if (options.preSpeechPadFrames < 0) {\n logging_1.log.error(\"preSpeechPadFrames should be positive\");\n }\n if (options.redemptionFrames < 0) {\n logging_1.log.error(\"preSpeechPadFrames should be positive\");\n }\n}\nexports.validateOptions = validateOptions;\nconst concatArrays = (arrays) => {\n const sizes = arrays.reduce((out, next) => {\n out.push(out.at(-1) + next.length);\n return out;\n }, [0]);\n const outArray = new Float32Array(sizes.at(-1));\n arrays.forEach((arr, index) => {\n const place = sizes[index];\n outArray.set(arr, place);\n });\n return outArray;\n};\nclass FrameProcessor {\n constructor(modelProcessFunc, modelResetFunc, options) {\n this.modelProcessFunc = modelProcessFunc;\n this.modelResetFunc = modelResetFunc;\n this.options = options;\n this.speaking = false;\n this.redemptionCounter = 0;\n this.active = false;\n this.reset = () => {\n this.speaking = false;\n this.audioBuffer = [];\n this.modelResetFunc();\n this.redemptionCounter = 0;\n };\n this.pause = () => {\n this.active = false;\n this.reset();\n };\n this.resume = () => {\n this.active = true;\n };\n this.endSegment = () => {\n const audioBuffer = this.audioBuffer;\n this.audioBuffer = [];\n const speaking = this.speaking;\n this.reset();\n const speechFrameCount = audioBuffer.reduce((acc, item) => {\n return acc + +item.isSpeech;\n }, 0);\n if (speaking) {\n if (speechFrameCount >= this.options.minSpeechFrames) {\n const audio = concatArrays(audioBuffer.map((item) => item.frame));\n return { msg: messages_1.Message.SpeechEnd, audio };\n }\n else {\n return { msg: messages_1.Message.VADMisfire };\n }\n }\n return {};\n };\n this.process = async (frame) => {\n if (!this.active) {\n return {};\n }\n const probs = await this.modelProcessFunc(frame);\n this.audioBuffer.push({\n frame,\n isSpeech: probs.isSpeech >= this.options.positiveSpeechThreshold,\n });\n if (probs.isSpeech >= this.options.positiveSpeechThreshold &&\n this.redemptionCounter) {\n this.redemptionCounter = 0;\n }\n if (probs.isSpeech >= this.options.positiveSpeechThreshold &&\n !this.speaking) {\n this.speaking = true;\n return { probs, msg: messages_1.Message.SpeechStart };\n }\n if (probs.isSpeech < this.options.negativeSpeechThreshold &&\n this.speaking &&\n ++this.redemptionCounter >= this.options.redemptionFrames) {\n this.redemptionCounter = 0;\n this.speaking = false;\n const audioBuffer = this.audioBuffer;\n this.audioBuffer = [];\n const speechFrameCount = audioBuffer.reduce((acc, item) => {\n return acc + +item.isSpeech;\n }, 0);\n if (speechFrameCount >= this.options.minSpeechFrames) {\n const audio = concatArrays(audioBuffer.map((item) => item.frame));\n return { probs, msg: messages_1.Message.SpeechEnd, audio };\n }\n else {\n return { probs, msg: messages_1.Message.VADMisfire };\n }\n }\n if (!this.speaking) {\n while (this.audioBuffer.length > this.options.preSpeechPadFrames) {\n this.audioBuffer.shift();\n }\n }\n return { probs };\n };\n this.audioBuffer = [];\n this.reset();\n }\n}\nexports.FrameProcessor = FrameProcessor;\n//# sourceMappingURL=frame-processor.js.map\n\n//# sourceURL=webpack://@k4ung/vad-web/./dist/_common/frame-processor.js?"); | ||
@@ -30,3 +30,3 @@ /***/ }), | ||
| eval("\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n});\nvar __importStar = (this && this.__importStar) || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n};\nvar __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.utils = void 0;\nconst _utils = __importStar(__webpack_require__(/*! ./utils */ \"./dist/_common/utils.js\"));\nexports.utils = {\n minFramesForTargetMS: _utils.minFramesForTargetMS,\n arrayBufferToBase64: _utils.arrayBufferToBase64,\n encodeWAV: _utils.encodeWAV,\n};\n__exportStar(__webpack_require__(/*! ./non-real-time-vad */ \"./dist/_common/non-real-time-vad.js\"), exports);\n__exportStar(__webpack_require__(/*! ./frame-processor */ \"./dist/_common/frame-processor.js\"), exports);\n__exportStar(__webpack_require__(/*! ./messages */ \"./dist/_common/messages.js\"), exports);\n__exportStar(__webpack_require__(/*! ./logging */ \"./dist/_common/logging.js\"), exports);\n__exportStar(__webpack_require__(/*! ./models */ \"./dist/_common/models.js\"), exports);\n__exportStar(__webpack_require__(/*! ./resampler */ \"./dist/_common/resampler.js\"), exports);\n//# sourceMappingURL=index.js.map\n\n//# sourceURL=webpack://@ricky0123/vad-web/./dist/_common/index.js?"); | ||
| eval("\nvar __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n var desc = Object.getOwnPropertyDescriptor(m, k);\n if (!desc || (\"get\" in desc ? !m.__esModule : desc.writable || desc.configurable)) {\n desc = { enumerable: true, get: function() { return m[k]; } };\n }\n Object.defineProperty(o, k2, desc);\n}) : (function(o, m, k, k2) {\n if (k2 === undefined) k2 = k;\n o[k2] = m[k];\n}));\nvar __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\n}) : function(o, v) {\n o[\"default\"] = v;\n});\nvar __importStar = (this && this.__importStar) || function (mod) {\n if (mod && mod.__esModule) return mod;\n var result = {};\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\n __setModuleDefault(result, mod);\n return result;\n};\nvar __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.utils = void 0;\nconst _utils = __importStar(__webpack_require__(/*! ./utils */ \"./dist/_common/utils.js\"));\nexports.utils = {\n minFramesForTargetMS: _utils.minFramesForTargetMS,\n arrayBufferToBase64: _utils.arrayBufferToBase64,\n encodeWAV: _utils.encodeWAV,\n};\n__exportStar(__webpack_require__(/*! ./non-real-time-vad */ \"./dist/_common/non-real-time-vad.js\"), exports);\n__exportStar(__webpack_require__(/*! ./frame-processor */ \"./dist/_common/frame-processor.js\"), exports);\n__exportStar(__webpack_require__(/*! ./messages */ \"./dist/_common/messages.js\"), exports);\n__exportStar(__webpack_require__(/*! ./logging */ \"./dist/_common/logging.js\"), exports);\n__exportStar(__webpack_require__(/*! ./models */ \"./dist/_common/models.js\"), exports);\n__exportStar(__webpack_require__(/*! ./resampler */ \"./dist/_common/resampler.js\"), exports);\n//# sourceMappingURL=index.js.map\n\n//# sourceURL=webpack://@k4ung/vad-web/./dist/_common/index.js?"); | ||
@@ -41,3 +41,3 @@ /***/ }), | ||
| eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.log = exports.LOG_PREFIX = void 0;\nexports.LOG_PREFIX = \"[VAD]\";\nconst levels = [\"error\", \"debug\", \"warn\"];\nfunction getLog(level) {\n return (...args) => {\n console[level](exports.LOG_PREFIX, ...args);\n };\n}\nconst _log = levels.reduce((acc, level) => {\n acc[level] = getLog(level);\n return acc;\n}, {});\nexports.log = _log;\n//# sourceMappingURL=logging.js.map\n\n//# sourceURL=webpack://@ricky0123/vad-web/./dist/_common/logging.js?"); | ||
| eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.log = exports.LOG_PREFIX = void 0;\nexports.LOG_PREFIX = \"[VAD]\";\nconst levels = [\"error\", \"debug\", \"warn\"];\nfunction getLog(level) {\n return (...args) => {\n console[level](exports.LOG_PREFIX, ...args);\n };\n}\nconst _log = levels.reduce((acc, level) => {\n acc[level] = getLog(level);\n return acc;\n}, {});\nexports.log = _log;\n//# sourceMappingURL=logging.js.map\n\n//# sourceURL=webpack://@k4ung/vad-web/./dist/_common/logging.js?"); | ||
@@ -52,3 +52,3 @@ /***/ }), | ||
| eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Message = void 0;\nvar Message;\n(function (Message) {\n Message[\"AudioFrame\"] = \"AUDIO_FRAME\";\n Message[\"SpeechStart\"] = \"SPEECH_START\";\n Message[\"VADMisfire\"] = \"VAD_MISFIRE\";\n Message[\"SpeechEnd\"] = \"SPEECH_END\";\n})(Message = exports.Message || (exports.Message = {}));\n//# sourceMappingURL=messages.js.map\n\n//# sourceURL=webpack://@ricky0123/vad-web/./dist/_common/messages.js?"); | ||
| eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Message = void 0;\nvar Message;\n(function (Message) {\n Message[\"AudioFrame\"] = \"AUDIO_FRAME\";\n Message[\"SpeechStart\"] = \"SPEECH_START\";\n Message[\"VADMisfire\"] = \"VAD_MISFIRE\";\n Message[\"SpeechEnd\"] = \"SPEECH_END\";\n})(Message = exports.Message || (exports.Message = {}));\n//# sourceMappingURL=messages.js.map\n\n//# sourceURL=webpack://@k4ung/vad-web/./dist/_common/messages.js?"); | ||
@@ -63,3 +63,3 @@ /***/ }), | ||
| eval("\nvar _a;\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Silero = void 0;\n// @ts-ignore\nconst logging_1 = __webpack_require__(/*! ./logging */ \"./dist/_common/logging.js\");\nclass Silero {\n constructor(ort, modelFetcher) {\n this.ort = ort;\n this.modelFetcher = modelFetcher;\n this.init = async () => {\n logging_1.log.debug(\"initializing vad\");\n const modelArrayBuffer = await this.modelFetcher();\n this._session = await this.ort.InferenceSession.create(modelArrayBuffer);\n this._sr = new this.ort.Tensor(\"int64\", [16000n]);\n this.reset_state();\n logging_1.log.debug(\"vad is initialized\");\n };\n this.reset_state = () => {\n const zeroes = Array(2 * 64).fill(0);\n this._h = new this.ort.Tensor(\"float32\", zeroes, [2, 1, 64]);\n this._c = new this.ort.Tensor(\"float32\", zeroes, [2, 1, 64]);\n };\n this.process = async (audioFrame) => {\n const t = new this.ort.Tensor(\"float32\", audioFrame, [1, audioFrame.length]);\n const inputs = {\n input: t,\n h: this._h,\n c: this._c,\n sr: this._sr,\n };\n const out = await this._session.run(inputs);\n this._h = out.hn;\n this._c = out.cn;\n const [isSpeech] = out.output.data;\n const notSpeech = 1 - isSpeech;\n return { notSpeech, isSpeech };\n };\n }\n}\nexports.Silero = Silero;\n_a = Silero;\nSilero.new = async (ort, modelFetcher) => {\n const model = new Silero(ort, modelFetcher);\n await model.init();\n return model;\n};\n//# sourceMappingURL=models.js.map\n\n//# sourceURL=webpack://@ricky0123/vad-web/./dist/_common/models.js?"); | ||
| eval("\nvar _a;\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Silero = void 0;\n// @ts-ignore\nconst logging_1 = __webpack_require__(/*! ./logging */ \"./dist/_common/logging.js\");\nclass Silero {\n constructor(ort, modelFetcher) {\n this.ort = ort;\n this.modelFetcher = modelFetcher;\n this.init = async () => {\n logging_1.log.debug(\"initializing vad\");\n const modelArrayBuffer = await this.modelFetcher();\n this._session = await this.ort.InferenceSession.create(modelArrayBuffer);\n this._sr = new this.ort.Tensor(\"int64\", [16000n]);\n this.reset_state();\n logging_1.log.debug(\"vad is initialized\");\n };\n this.reset_state = () => {\n const zeroes = Array(2 * 64).fill(0);\n this._h = new this.ort.Tensor(\"float32\", zeroes, [2, 1, 64]);\n this._c = new this.ort.Tensor(\"float32\", zeroes, [2, 1, 64]);\n };\n this.process = async (audioFrame) => {\n const t = new this.ort.Tensor(\"float32\", audioFrame, [1, audioFrame.length]);\n const inputs = {\n input: t,\n h: this._h,\n c: this._c,\n sr: this._sr,\n };\n const out = await this._session.run(inputs);\n this._h = out.hn;\n this._c = out.cn;\n const [isSpeech] = out.output.data;\n const notSpeech = 1 - isSpeech;\n return { notSpeech, isSpeech };\n };\n }\n}\nexports.Silero = Silero;\n_a = Silero;\nSilero.new = async (ort, modelFetcher) => {\n const model = new Silero(ort, modelFetcher);\n await model.init();\n return model;\n};\n//# sourceMappingURL=models.js.map\n\n//# sourceURL=webpack://@k4ung/vad-web/./dist/_common/models.js?"); | ||
@@ -74,3 +74,3 @@ /***/ }), | ||
| eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.PlatformAgnosticNonRealTimeVAD = exports.defaultNonRealTimeVADOptions = void 0;\nconst frame_processor_1 = __webpack_require__(/*! ./frame-processor */ \"./dist/_common/frame-processor.js\");\nconst messages_1 = __webpack_require__(/*! ./messages */ \"./dist/_common/messages.js\");\nconst models_1 = __webpack_require__(/*! ./models */ \"./dist/_common/models.js\");\nconst resampler_1 = __webpack_require__(/*! ./resampler */ \"./dist/_common/resampler.js\");\nexports.defaultNonRealTimeVADOptions = {\n ...frame_processor_1.defaultFrameProcessorOptions,\n};\nclass PlatformAgnosticNonRealTimeVAD {\n static async _new(modelFetcher, ort, options = {}) {\n const vad = new this(modelFetcher, ort, {\n ...exports.defaultNonRealTimeVADOptions,\n ...options,\n });\n await vad.init();\n return vad;\n }\n constructor(modelFetcher, ort, options) {\n this.modelFetcher = modelFetcher;\n this.ort = ort;\n this.options = options;\n this.init = async () => {\n const model = await models_1.Silero.new(this.ort, this.modelFetcher);\n this.frameProcessor = new frame_processor_1.FrameProcessor(model.process, model.reset_state, {\n frameSamples: this.options.frameSamples,\n positiveSpeechThreshold: this.options.positiveSpeechThreshold,\n negativeSpeechThreshold: this.options.negativeSpeechThreshold,\n redemptionFrames: this.options.redemptionFrames,\n preSpeechPadFrames: this.options.preSpeechPadFrames,\n minSpeechFrames: this.options.minSpeechFrames,\n });\n this.frameProcessor.resume();\n };\n this.run = async function* (inputAudio, sampleRate) {\n const resamplerOptions = {\n nativeSampleRate: sampleRate,\n targetSampleRate: 16000,\n targetFrameSize: this.options.frameSamples,\n };\n const resampler = new resampler_1.Resampler(resamplerOptions);\n const frames = resampler.process(inputAudio);\n let start, end;\n for (const i of [...Array(frames.length)].keys()) {\n const f = frames[i];\n const { msg, audio } = await this.frameProcessor.process(f);\n switch (msg) {\n case messages_1.Message.SpeechStart:\n start = (i * this.options.frameSamples) / 16;\n break;\n case messages_1.Message.SpeechEnd:\n end = ((i + 1) * this.options.frameSamples) / 16;\n // @ts-ignore\n yield { audio, start, end };\n break;\n default:\n break;\n }\n }\n const { msg, audio } = this.frameProcessor.endSegment();\n if (msg == messages_1.Message.SpeechEnd) {\n yield {\n audio,\n // @ts-ignore\n start,\n end: (frames.length * this.options.frameSamples) / 16,\n };\n }\n };\n (0, frame_processor_1.validateOptions)(options);\n }\n}\nexports.PlatformAgnosticNonRealTimeVAD = PlatformAgnosticNonRealTimeVAD;\n//# sourceMappingURL=non-real-time-vad.js.map\n\n//# sourceURL=webpack://@ricky0123/vad-web/./dist/_common/non-real-time-vad.js?"); | ||
| eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.PlatformAgnosticNonRealTimeVAD = exports.defaultNonRealTimeVADOptions = void 0;\nconst frame_processor_1 = __webpack_require__(/*! ./frame-processor */ \"./dist/_common/frame-processor.js\");\nconst messages_1 = __webpack_require__(/*! ./messages */ \"./dist/_common/messages.js\");\nconst models_1 = __webpack_require__(/*! ./models */ \"./dist/_common/models.js\");\nconst resampler_1 = __webpack_require__(/*! ./resampler */ \"./dist/_common/resampler.js\");\nexports.defaultNonRealTimeVADOptions = {\n ...frame_processor_1.defaultFrameProcessorOptions,\n};\nclass PlatformAgnosticNonRealTimeVAD {\n static async _new(modelFetcher, ort, options = {}) {\n const vad = new this(modelFetcher, ort, {\n ...exports.defaultNonRealTimeVADOptions,\n ...options,\n });\n await vad.init();\n return vad;\n }\n constructor(modelFetcher, ort, options) {\n this.modelFetcher = modelFetcher;\n this.ort = ort;\n this.options = options;\n this.init = async () => {\n const model = await models_1.Silero.new(this.ort, this.modelFetcher);\n this.frameProcessor = new frame_processor_1.FrameProcessor(model.process, model.reset_state, {\n frameSamples: this.options.frameSamples,\n positiveSpeechThreshold: this.options.positiveSpeechThreshold,\n negativeSpeechThreshold: this.options.negativeSpeechThreshold,\n redemptionFrames: this.options.redemptionFrames,\n preSpeechPadFrames: this.options.preSpeechPadFrames,\n minSpeechFrames: this.options.minSpeechFrames,\n });\n this.frameProcessor.resume();\n };\n this.run = async function* (inputAudio, sampleRate) {\n const resamplerOptions = {\n nativeSampleRate: sampleRate,\n targetSampleRate: 16000,\n targetFrameSize: this.options.frameSamples,\n };\n const resampler = new resampler_1.Resampler(resamplerOptions);\n const frames = resampler.process(inputAudio);\n let start, end;\n for (const i of [...Array(frames.length)].keys()) {\n const f = frames[i];\n const { msg, audio } = await this.frameProcessor.process(f);\n switch (msg) {\n case messages_1.Message.SpeechStart:\n start = (i * this.options.frameSamples) / 16;\n break;\n case messages_1.Message.SpeechEnd:\n end = ((i + 1) * this.options.frameSamples) / 16;\n // @ts-ignore\n yield { audio, start, end };\n break;\n default:\n break;\n }\n }\n const { msg, audio } = this.frameProcessor.endSegment();\n if (msg == messages_1.Message.SpeechEnd) {\n yield {\n audio,\n // @ts-ignore\n start,\n end: (frames.length * this.options.frameSamples) / 16,\n };\n }\n };\n (0, frame_processor_1.validateOptions)(options);\n }\n}\nexports.PlatformAgnosticNonRealTimeVAD = PlatformAgnosticNonRealTimeVAD;\n//# sourceMappingURL=non-real-time-vad.js.map\n\n//# sourceURL=webpack://@k4ung/vad-web/./dist/_common/non-real-time-vad.js?"); | ||
@@ -85,3 +85,3 @@ /***/ }), | ||
| eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Resampler = void 0;\nconst logging_1 = __webpack_require__(/*! ./logging */ \"./dist/_common/logging.js\");\nclass Resampler {\n constructor(options) {\n this.options = options;\n this.process = (audioFrame) => {\n const outputFrames = [];\n for (const sample of audioFrame) {\n this.inputBuffer.push(sample);\n }\n while ((this.inputBuffer.length * this.options.targetSampleRate) /\n this.options.nativeSampleRate >\n this.options.targetFrameSize) {\n const outputFrame = new Float32Array(this.options.targetFrameSize);\n let outputIndex = 0;\n let inputIndex = 0;\n while (outputIndex < this.options.targetFrameSize) {\n let sum = 0;\n let num = 0;\n while (inputIndex <\n Math.min(this.inputBuffer.length, ((outputIndex + 1) * this.options.nativeSampleRate) /\n this.options.targetSampleRate)) {\n sum += this.inputBuffer[inputIndex];\n num++;\n inputIndex++;\n }\n outputFrame[outputIndex] = sum / num;\n outputIndex++;\n }\n this.inputBuffer = this.inputBuffer.slice(inputIndex);\n outputFrames.push(outputFrame);\n }\n return outputFrames;\n };\n if (options.nativeSampleRate < 16000) {\n logging_1.log.error(\"nativeSampleRate is too low. Should have 16000 = targetSampleRate <= nativeSampleRate\");\n }\n this.inputBuffer = [];\n }\n}\nexports.Resampler = Resampler;\n//# sourceMappingURL=resampler.js.map\n\n//# sourceURL=webpack://@ricky0123/vad-web/./dist/_common/resampler.js?"); | ||
| eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.Resampler = void 0;\nconst logging_1 = __webpack_require__(/*! ./logging */ \"./dist/_common/logging.js\");\nclass Resampler {\n constructor(options) {\n this.options = options;\n this.process = (audioFrame) => {\n const outputFrames = [];\n for (const sample of audioFrame) {\n this.inputBuffer.push(sample);\n }\n while ((this.inputBuffer.length * this.options.targetSampleRate) /\n this.options.nativeSampleRate >\n this.options.targetFrameSize) {\n const outputFrame = new Float32Array(this.options.targetFrameSize);\n let outputIndex = 0;\n let inputIndex = 0;\n while (outputIndex < this.options.targetFrameSize) {\n let sum = 0;\n let num = 0;\n while (inputIndex <\n Math.min(this.inputBuffer.length, ((outputIndex + 1) * this.options.nativeSampleRate) /\n this.options.targetSampleRate)) {\n sum += this.inputBuffer[inputIndex];\n num++;\n inputIndex++;\n }\n outputFrame[outputIndex] = sum / num;\n outputIndex++;\n }\n this.inputBuffer = this.inputBuffer.slice(inputIndex);\n outputFrames.push(outputFrame);\n }\n return outputFrames;\n };\n if (options.nativeSampleRate < 16000) {\n logging_1.log.error(\"nativeSampleRate is too low. Should have 16000 = targetSampleRate <= nativeSampleRate\");\n }\n this.inputBuffer = [];\n }\n}\nexports.Resampler = Resampler;\n//# sourceMappingURL=resampler.js.map\n\n//# sourceURL=webpack://@k4ung/vad-web/./dist/_common/resampler.js?"); | ||
@@ -96,3 +96,3 @@ /***/ }), | ||
| eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.encodeWAV = exports.arrayBufferToBase64 = exports.minFramesForTargetMS = void 0;\nfunction minFramesForTargetMS(targetDuration, frameSamples, sr = 16000) {\n return Math.ceil((targetDuration * sr) / 1000 / frameSamples);\n}\nexports.minFramesForTargetMS = minFramesForTargetMS;\nfunction arrayBufferToBase64(buffer) {\n var binary = \"\";\n var bytes = new Uint8Array(buffer);\n var len = bytes.byteLength;\n for (var i = 0; i < len; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\nexports.arrayBufferToBase64 = arrayBufferToBase64;\n/*\nThis rest of this was mostly copied from https://github.com/linto-ai/WebVoiceSDK\n*/\nfunction encodeWAV(samples, format = 3, sampleRate = 16000, numChannels = 1, bitDepth = 32) {\n var bytesPerSample = bitDepth / 8;\n var blockAlign = numChannels * bytesPerSample;\n var buffer = new ArrayBuffer(44 + samples.length * bytesPerSample);\n var view = new DataView(buffer);\n /* RIFF identifier */\n writeString(view, 0, \"RIFF\");\n /* RIFF chunk length */\n view.setUint32(4, 36 + samples.length * bytesPerSample, true);\n /* RIFF type */\n writeString(view, 8, \"WAVE\");\n /* format chunk identifier */\n writeString(view, 12, \"fmt \");\n /* format chunk length */\n view.setUint32(16, 16, true);\n /* sample format (raw) */\n view.setUint16(20, format, true);\n /* channel count */\n view.setUint16(22, numChannels, true);\n /* sample rate */\n view.setUint32(24, sampleRate, true);\n /* byte rate (sample rate * block align) */\n view.setUint32(28, sampleRate * blockAlign, true);\n /* block align (channel count * bytes per sample) */\n view.setUint16(32, blockAlign, true);\n /* bits per sample */\n view.setUint16(34, bitDepth, true);\n /* data chunk identifier */\n writeString(view, 36, \"data\");\n /* data chunk length */\n view.setUint32(40, samples.length * bytesPerSample, true);\n if (format === 1) {\n // Raw PCM\n floatTo16BitPCM(view, 44, samples);\n }\n else {\n writeFloat32(view, 44, samples);\n }\n return buffer;\n}\nexports.encodeWAV = encodeWAV;\nfunction interleave(inputL, inputR) {\n var length = inputL.length + inputR.length;\n var result = new Float32Array(length);\n var index = 0;\n var inputIndex = 0;\n while (index < length) {\n result[index++] = inputL[inputIndex];\n result[index++] = inputR[inputIndex];\n inputIndex++;\n }\n return result;\n}\nfunction writeFloat32(output, offset, input) {\n for (var i = 0; i < input.length; i++, offset += 4) {\n output.setFloat32(offset, input[i], true);\n }\n}\nfunction floatTo16BitPCM(output, offset, input) {\n for (var i = 0; i < input.length; i++, offset += 2) {\n var s = Math.max(-1, Math.min(1, input[i]));\n output.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7fff, true);\n }\n}\nfunction writeString(view, offset, string) {\n for (var i = 0; i < string.length; i++) {\n view.setUint8(offset + i, string.charCodeAt(i));\n }\n}\n//# sourceMappingURL=utils.js.map\n\n//# sourceURL=webpack://@ricky0123/vad-web/./dist/_common/utils.js?"); | ||
| eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.encodeWAV = exports.arrayBufferToBase64 = exports.minFramesForTargetMS = void 0;\nfunction minFramesForTargetMS(targetDuration, frameSamples, sr = 16000) {\n return Math.ceil((targetDuration * sr) / 1000 / frameSamples);\n}\nexports.minFramesForTargetMS = minFramesForTargetMS;\nfunction arrayBufferToBase64(buffer) {\n var binary = \"\";\n var bytes = new Uint8Array(buffer);\n var len = bytes.byteLength;\n for (var i = 0; i < len; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\nexports.arrayBufferToBase64 = arrayBufferToBase64;\n/*\nThis rest of this was mostly copied from https://github.com/linto-ai/WebVoiceSDK\n*/\nfunction encodeWAV(samples, format = 3, sampleRate = 16000, numChannels = 1, bitDepth = 32) {\n var bytesPerSample = bitDepth / 8;\n var blockAlign = numChannels * bytesPerSample;\n var buffer = new ArrayBuffer(44 + samples.length * bytesPerSample);\n var view = new DataView(buffer);\n /* RIFF identifier */\n writeString(view, 0, \"RIFF\");\n /* RIFF chunk length */\n view.setUint32(4, 36 + samples.length * bytesPerSample, true);\n /* RIFF type */\n writeString(view, 8, \"WAVE\");\n /* format chunk identifier */\n writeString(view, 12, \"fmt \");\n /* format chunk length */\n view.setUint32(16, 16, true);\n /* sample format (raw) */\n view.setUint16(20, format, true);\n /* channel count */\n view.setUint16(22, numChannels, true);\n /* sample rate */\n view.setUint32(24, sampleRate, true);\n /* byte rate (sample rate * block align) */\n view.setUint32(28, sampleRate * blockAlign, true);\n /* block align (channel count * bytes per sample) */\n view.setUint16(32, blockAlign, true);\n /* bits per sample */\n view.setUint16(34, bitDepth, true);\n /* data chunk identifier */\n writeString(view, 36, \"data\");\n /* data chunk length */\n view.setUint32(40, samples.length * bytesPerSample, true);\n if (format === 1) {\n // Raw PCM\n floatTo16BitPCM(view, 44, samples);\n }\n else {\n writeFloat32(view, 44, samples);\n }\n return buffer;\n}\nexports.encodeWAV = encodeWAV;\nfunction interleave(inputL, inputR) {\n var length = inputL.length + inputR.length;\n var result = new Float32Array(length);\n var index = 0;\n var inputIndex = 0;\n while (index < length) {\n result[index++] = inputL[inputIndex];\n result[index++] = inputR[inputIndex];\n inputIndex++;\n }\n return result;\n}\nfunction writeFloat32(output, offset, input) {\n for (var i = 0; i < input.length; i++, offset += 4) {\n output.setFloat32(offset, input[i], true);\n }\n}\nfunction floatTo16BitPCM(output, offset, input) {\n for (var i = 0; i < input.length; i++, offset += 2) {\n var s = Math.max(-1, Math.min(1, input[i]));\n output.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7fff, true);\n }\n}\nfunction writeString(view, offset, string) {\n for (var i = 0; i < string.length; i++) {\n view.setUint8(offset + i, string.charCodeAt(i));\n }\n}\n//# sourceMappingURL=utils.js.map\n\n//# sourceURL=webpack://@k4ung/vad-web/./dist/_common/utils.js?"); | ||
@@ -107,3 +107,3 @@ /***/ }), | ||
| eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nconst _common_1 = __webpack_require__(/*! ./_common */ \"./dist/_common/index.js\");\nclass Processor extends AudioWorkletProcessor {\n constructor(options) {\n super();\n this._initialized = false;\n this.init = async () => {\n _common_1.log.debug(\"initializing worklet\");\n this.resampler = new _common_1.Resampler({\n nativeSampleRate: sampleRate,\n targetSampleRate: 16000,\n targetFrameSize: this.options.frameSamples,\n });\n this._initialized = true;\n _common_1.log.debug(\"initialized worklet\");\n };\n this.options = options.processorOptions;\n this.init();\n }\n process(inputs, outputs, parameters) {\n // @ts-ignore\n const arr = inputs[0][0];\n if (this._initialized && arr instanceof Float32Array) {\n const frames = this.resampler.process(arr);\n for (const frame of frames) {\n this.port.postMessage({ message: _common_1.Message.AudioFrame, data: frame.buffer }, [frame.buffer]);\n }\n }\n return true;\n }\n}\nregisterProcessor(\"vad-helper-worklet\", Processor);\n//# sourceMappingURL=worklet.js.map\n\n//# sourceURL=webpack://@ricky0123/vad-web/./dist/worklet.js?"); | ||
| eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nconst _common_1 = __webpack_require__(/*! ./_common */ \"./dist/_common/index.js\");\nclass Processor extends AudioWorkletProcessor {\n constructor(options) {\n super();\n this._initialized = false;\n this.init = async () => {\n _common_1.log.debug(\"initializing worklet\");\n this.resampler = new _common_1.Resampler({\n nativeSampleRate: sampleRate,\n targetSampleRate: 16000,\n targetFrameSize: this.options.frameSamples,\n });\n this._initialized = true;\n _common_1.log.debug(\"initialized worklet\");\n };\n this.options = options.processorOptions;\n this.init();\n }\n process(inputs, outputs, parameters) {\n // @ts-ignore\n const arr = inputs[0][0];\n if (this._initialized && arr instanceof Float32Array) {\n const frames = this.resampler.process(arr);\n for (const frame of frames) {\n this.port.postMessage({ message: _common_1.Message.AudioFrame, data: frame.buffer }, [frame.buffer]);\n }\n }\n return true;\n }\n}\nregisterProcessor(\"vad-helper-worklet\", Processor);\n//# sourceMappingURL=worklet.js.map\n\n//# sourceURL=webpack://@k4ung/vad-web/./dist/worklet.js?"); | ||
@@ -110,0 +110,0 @@ /***/ }) |
+1
-1
@@ -15,3 +15,3 @@ { | ||
| "homepage": "https://github.com/ricky0123/vad", | ||
| "version": "0.0.1", | ||
| "version": "0.0.2", | ||
| "license": "ISC", | ||
@@ -18,0 +18,0 @@ "main": "dist/index.js", |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
1970839
0.01%1484
0.07%