Skip to content

Decode Base 64 audio file Mp3 into playable Mp3

I am converting the audio MP3 file and storing it as base64 in database using WEB API, now I am fetching the base64 file using ajax and I am getting the base64, the problem is how can I convert the base64 file back to mp3 file and play it using JavaScript.

This if for demo I am using input file, I am getting base64 file from server

<input type='file' onchange='openFile(event)' id="EdituserProfileImage">
var fileName;
var filetype;
var filesize;
var VoiceBase64;
var openFile = function (event) {
    var input =;
    fileName = input.files[0].name;
    filetype = input.files[0].type;
    filesize = input.files[0].size;
    var reader = new FileReader();
    reader.onload = function (evt) {
        var voiceInBinay =;
        VoiceBase64 = btoa(voiceInBinay);

This function “contvertBase64toBinaray” using for converting base64 to Binary, I have binary file, need to save as mp3 from this below binary

function contvertBase64toBinaray(VoiceBase64) {
    var audiofile = atob(VoiceBase64)



Use window.atob function to decode your base 64 data.

This question shows you how you can play the mp3 in JS.

User contributions licensed under: CC BY-SA
6 People found this is helpful