Write a wav file in Node.js from an AudioBuffer

别等时光非礼了梦想. 提交于 2020-01-13 20:28:48

问题


I am new in Node.js programming and I am trying to convert a m4a file to wav file.

I used audiobuffer-to-wav, and web-audio-api. This is my code:

const fs = require('fs');
const toWav = require('audiobuffer-to-wav');
const AudioContext = require('web-audio-api').AudioContext;
const audioContext = new AudioContext;

let resp = fs.readFileSync('sample.m4a');

audioContext.decodeAudioData(resp, buffer => {
  let wav = toWav(buffer);
  console.log(buffer.length);
  console.log(wav); 
});

I want to know how to save the wav variable into a file in Node.js


回答1:


const fs = require('fs');
const toWav = require('audiobuffer-to-wav');
const AudioContext = require('web-audio-api').AudioContext;
const audioContext = new AudioContext;
 let resp = fs.readFileSync('sample.m4a');

var audioStack = [];

var header = require('waveheader');

audioContext.decodeAudioData(resp, buffer => {
    let wav = toWav(buffer); 
    var chunk = new Uint8Array(wav);
    console.log(chunk); 
    fs.appendFile('bb.wav', new Buffer(chunk), function (err) {
    });

});

This is my answer. Thanks Kalamarico.



来源:https://stackoverflow.com/questions/46623517/write-a-wav-file-in-node-js-from-an-audiobuffer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!