从AudioBuffer在Node.js中写一个wav文件

时间:2017-10-07 18:12:34

标签: javascript node.js audiocontext

我是Node.js编程的新手,我正在尝试将m4a文件转换为wav文件。

我使用了audiobuffer-to-wav和web-audio-api。 这是我的代码:

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); 
});

我想知道如何将wav变量保存到Node.js

中的文件中

1 个答案:

答案 0 :(得分:4)

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) {
    });

});

这是我的答案。谢谢Kalamarico。