<template>
  <button @click="play">Button</button>
</template>
<script>
export default {
    mounted() {
      this.audioCtx = new AudioContext();
      console.log(this.audioCtx.sampleRate);
    this.buffer=  this.audioCtx.createBuffer(1,this.audioCtx.sampleRate*1,this.audioCtx.sampleRate);
      const channelData=this.buffer.getChannelData(0);
      for(let i=0;i<this.buffer.length;i++){
        channelData[i]=Math.random() * 2-1;
      }
    },
    data() {
      return {
        audioCtx: null,
        buffer:null
      }
    },
  methods:{
      play(){
        const primaryGainControl=this.audioCtx.createGain();
        primaryGainControl.gain.setValueAtTime(0.5,0);
        primaryGainControl.connect(this.audioCtx.destination);
        const whiteNoseSource=this.audioCtx.createBufferSource();
        whiteNoseSource.buffer=this.buffer;
        whiteNoseSource.connect(primaryGainControl);
        whiteNoseSource.start();
      }
  }

}
</script>