I want to convert audio file into base64 using Javascript only.
We can convert images into base64 using canvas. But how can we convert audio files.
Any help will be grateful.
Convert Files to Base64Just select your file or drag & drop it below, press the Convert to Base64 button, and you'll get a base64 string. Press a button – get base64. No ads, nonsense, or garbage. The input file can also be an mp3 or mp4.
Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding.
you can give the below code a try, it uses btoa
function getData(audioFile, callback) {
var reader = new FileReader();
reader.onload = function(event) {
var data = event.target.result.split(',')
, decodedImageData = btoa(data[1]); // the actual conversion of data from binary to base64 format
callback(decodedImageData);
};
reader.readAsDataURL(audioFile);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With