converting audio file to base64 using javascript

后端 未结 1 1714
面向向阳花
面向向阳花 2020-12-10 18:19

I want to convert audio file into base64 using Javascript only.

We can convert images into base64 using canvas. Bu

相关标签:
1条回答
  • 2020-12-10 18:50

    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);
    }
    
    0 讨论(0)
提交回复
热议问题