resample audio buffer from 44100 to 16000

前端 未结 5 393
不思量自难忘°
不思量自难忘° 2021-02-04 09:56

I have audio data in format of data-uri, then I converted this data-uri into a buffer now I need this buffer data in new samplerate, currently audio data is in 44.1khz and I nee

5条回答
  •  失恋的感觉
    2021-02-04 10:47

    if you are using chrome browser you can directly specify sample rate in AudioContext .

    1.You can directly record sound via microphone .

    var context = new AudioContext({
        sampleRate: 16000,
    });
    

    2.If you already has a file or ArrayBuffer .Then you can resample it using the same audio context

        const fileReader = new FileReader();
        fileReader.readAsArrayBuffer(target.files[0]);
        
        fileReader.onload =  (e) => {
            //e.target.result is an ArrayBuffer
            context.decodeAudioData(e.target.result, async function(buffer) {
            console.log(buffer)
        })
            
        
    

提交回复
热议问题