Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resample audio buffer from 44100 to 16000

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 need data in 16khz, and If I recorded the audio using RecordRTC API and if I record audio in low sample rate then I got distorted audio voice, So I am not getting how to resample my audio buffer,

If any of you any idea regarding this then please help me out.

Thanks in advance :)

like image 923
Mahendra Garg Avatar asked Dec 22 '14 07:12

Mahendra Garg


1 Answers

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)
    })
        
    
like image 185
Masthan Avatar answered Sep 28 '22 03:09

Masthan