简体   繁体   中英

how to convert an audio (mp3) file into a binary file in javascript?

i am trying to convert an audio file into a binary file using js or node.js, as i need it for my project

Here's the code that i have tried. the file got converted but is not in binary format.

fs.readFile('bell-ring-01.mp3', function(err, data) {
if (err) throw err;

var encodedmp3 = new Buffer(data, 'binary').toString(2);
if(encodedmp3)
{
    console.log(encodedmp3);
}

//perform the encryption, then

fs.writeFileSync("music.sam", encodedmp3, function(err) {
    if(err) {
        return console.log(err);
    }

   // console.log(encodedmp3);
}); 

The short answer is that you are looking for a JavaScript library for MP3s.

You are probably looking for the ffmpeg library. You can read a little tutorial on Medium . Alternately, you might look at the Howler.js library if you want a simple interface.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM