Convert base64 audio to file

前端 未结 1 1429
隐瞒了意图╮
隐瞒了意图╮ 2021-01-19 07:26

I have an audio blob, I then run

var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = () => {
  var base64data = reader.result;
         


        
相关标签:
1条回答
  • 2021-01-19 08:19

    You have binary data encoded in base64 string here. First of all you need trim data url meta info. Then you can create binary buffer from base64 string and store it to file.

    fs.writeFileSync('file.ogg', Buffer.from(base64data.replace('data:audio/ogg; codecs=opus;base64,', ''), 'base64'));
    
    0 讨论(0)
提交回复
热议问题