I am writing an web application which requests for an .wav audio file from server, and the server returns the file encoded as base64 string. Then I need to download the file. The code is as following
let blob = _base64ToBlob(b64, 'audio/x-wav');
let url = window.URL.createObjectURL(blob);
let a = document.createElement('a');
a.href = url; a.download = 'tag.wav'; a.click();
function _base64ToBlob(base64, type) {
const bytes = atob(base64), len = bytes.length;
let buffer = new ArrayBuffer(len);
let view = new Uint8Array(buffer);
for(var i=0; i<len; i++) {
view[i] = bytes.charCodeAt(i) & 0xff;
}
return new Blob([buffer], {type: type});
},
My question is can the encoded wav file be converted to mp3 before downloading? Is there any client side JavaScript method to do that.