class a{constructor(t){this.onDataAvailable=t,this.audioContext=null,this.mediaStream=null,this.mediaStreamSource=null,this.workletNode=null}async start(t){try{this.audioContext=new AudioContext({sampleRate:24e3}),await this.audioContext.audioWorklet.addModule("/themes/default/assets/js/audio/audio-worklet-processor.js"),this.mediaStream=t,this.mediaStreamSource=this.audioContext.createMediaStreamSource(this.mediaStream),this.workletNode=new AudioWorkletNode(this.audioContext,"audio-worklet-processor"),this.workletNode.port.onmessage=e=>this.onDataAvailable(e.data.buffer),this.mediaStreamSource.connect(this.workletNode)}catch(e){console.error("Error in recorder start:",e),this.stop()}}stop(){this.mediaStream&&this.mediaStream.getTracks().forEach(t=>t.stop()),this.audioContext&&this.audioContext.state!=="closed"&&this.audioContext.close()}getMediaStreamSource(){return this.mediaStreamSource}}export{a as R};
