UNPKG

simple-rnnoise-wasm

Version:

Tiny Web Audio RNNoise wrapper compiled to WebAssembly with an AudioWorklet node.

2 lines 1 kB
let t,s;class e extends AudioWorkletProcessor{constructor(e){super({...e,numberOfInputs:1,numberOfOutputs:1,outputChannelCount:[1]}),t||(s=new Float32Array((t=new WebAssembly.Instance(e.processorOptions.module).exports).memory.buffer)),this.state=t.newState(),this.alive=!0,this.statSize=Math.ceil(sampleRate/128),this.stat=new Float32Array(2*this.statSize),this.statPtr=0,this.ts=0,this.port.onmessage=({data:s})=>{if(this.alive)if(s){let e={vadProb:t.getVadProb(this.state)};"stat"===s&&(e.stat=this.stat),this.port.postMessage(e)}else this.alive=!1,t.deleteState(this.state)}}process(e,a){if(!this.alive)return!1;let i=Date.now();s.set(e[0][0],t.getInput(this.state)/4);let r=a[0][0],h=t.pipe(this.state,r.length)/4;return h&&r.set(s.subarray(h,h+r.length)),0!==this.ts&&(this.stat[this.statPtr]=i-this.ts,this.stat[this.statPtr+this.statSize]=Date.now()-this.ts,this.statPtr=(this.statPtr+1)%this.statSize),this.ts=i,!0}}registerProcessor("rnnoise",e); //# sourceMappingURL=rnnoise.worklet.js.map