-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.js
32 lines (29 loc) · 817 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var path = require('path');
var execFile = require('child_process').execFile;
var waveformBin = path.resolve(__dirname, "build", "Release", "waveform");
var flagNames = {
'scan': true,
'wjs-plain': true,
};
module.exports = function(audiofile, options, callback) {
var cmdline = [audiofile];
for (var optName in options) {
if (flagNames[optName]) {
cmdline.push('--' + optName);
} else {
var value = options[optName];
cmdline.push('--' + optName);
cmdline.push(value);
}
}
execFile(waveformBin, cmdline, {encoding: 'buffer', maxBuffer: 5000*1024}, function(err, stdout, stderr) {
if (err) {
err.stdout = stdout;
err.stderr = stderr;
err.stack += new Error().stack;
callback(err);
} else {
callback(null, stdout);
}
});
};