Skip to content Skip to sidebar Skip to footer

How To Replay An Audio-blob In Javascript?

I want to replay an audio blob (wav), recorded in javascript using the Web Audio API. I tried the following: function replayBlob( blob ) { var blobURL = window.URL.createObject

Solution 1:

If you're using Web Audio to record, I figure you can use it for playback as well, right? If so, recorder.js has a how-to in the README: https://github.com/mattdiamond/Recorderjs

I'll go ahead and copy the gist of here, in case recorder.js changes in the future. You have two Float32Arrays (left and right channel) and then do this;

function getBufferCallback( buffers ) {
    var newSource = audioContext.createBufferSource();
    var newBuffer = audioContext.createBuffer( 2, buffers[0].length, audioContext.sampleRate );
    newBuffer.getChannelData(0).set(buffers[0]);
    newBuffer.getChannelData(1).set(buffers[1]);
    newSource.buffer = newBuffer;

    newSource.connect( audioContext.destination );
    newSource.start(0);
}

Solution 2:

The simplest option is to convert to a 64 bit encoding

const reader = newFileReader();
reader.onload = function(e) {
    const srcUrl = e.target.result;
    audioNode.src = srcUrl;
};
reader.readAsDataURL(blob);

Post a Comment for "How To Replay An Audio-blob In Javascript?"