Search code examples
javascripthtml5-audio

accessing browser audio codecs for encoding


from the docs (here):

The decodeAudioData() method of the BaseAudioContext Interface is used to asynchronously decode audio file data contained in an ArrayBuffer.

ctx.decodeAudioData(audioData).then(function(decodedData) {
 // use the decoded data here
});

My question is can we access the browser's audio codecs in order to perform encoding instead of decoding (i.e. convert raw pcm -> flac/opus/mp3 etc..)?


Solution

  • Unfortunately this is not yet possible. There is currently a proposal for a new API or a set of APIs called WebCodecs which may support that use case in the future.

    Until then the only native way I could think of to encode audio would be using the MediaRecorder. But it can't be used to accurately encode an AudioBuffer since it's start() and stop() methods are not precise.