-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
72 lines (63 loc) · 1.99 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env node
(function() {
const fs = require('fs');
const wav = require('wav');
const program = require('commander');
const meyda = require('meyda');
const main = require('./main');
const ChunkStream = require('./chunks');
program
.version(require('./package.json').version)
.description("A command line interface to Meyda, audio feature extraction in Javascript")
.usage('[options] <file>')
.option('-w, --windowingFunction [name]',
'Set the windowing function [hanning]',
'hanning')
.option('-s, --bufferSize <n>',
'Set the buffer size, must be a power of 2',
1024,
parseInt)
.option('-f, --features <items>',
'A list of audio features (default all available features).',
(string) => string.split(','))
.arguments('<file> [env]')
.action((file, env) => {
}).parse(process.argv);
// output help by default
if (!process.argv.slice(2).length) {
program.outputHelp();
process.exit(1);
}
// TODO get filename from Commander
//const filename = process.argv.slice(-1)[0];
console.log(program.features);
try {
// If we've been given a file, open a file stream
const stream = (() => {
// TODO check the wav file is valid
// if (validWavFile(filename)) {
try {
return fs.createReadStream(filename);
} catch (e) {
// Otherwise, use stdin
return process.stdin;
}
})();
const extract = main(program.file,
program.features,
program.windowingFunction,
program.bufferSize);
// TODO pass input through the wav stream encoder
const chunkStream = new ChunkStream(extract, program.bufferSize);
const wavReader = new wav.Reader();
stream.pipe(wavReader);
wavReader.on('format',() => {
wavReader.pipe(chunkStream);
});
chunkStream.pipe(process.stdout);
} catch (e) {
console.error(e);
program.outputHelp();
process.exit(e.statusCode);
}
})();