-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (54 loc) · 1.46 KB
/
index.js
File metadata and controls
67 lines (54 loc) · 1.46 KB
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
/**
* ACRON
*/
var fs = require('fs');
var path = require('path');
var proc = require('child_process');
var moment = require('moment');
var config = require('./config');
var getOptionArgEquivalent = function( option ){
switch ( option ){
default: return null;
case 'duration': return '-d';
case 'bitRate': return '-r';
case 'device': return '-D';
case 'format': return '-f';
}
};
var optionsToArgs = function( options ){
var args = [];
Object.keys( options ).forEach( function( k ){
args.push( getOptionArgEquivalent( k ), options[ k ] );
});
return args;
};
module.exports.record = function( options, callback ){
if ( typeof options === 'function' ){
callback = options
options = {};
}
callback = callback || function(){};
var defaults = {
duration: 60
, bitRate: 64
, device: 'plughw:1,0'
, format: 'cd'
, output: moment().format( config.filenameFormat ) + '.wav'
};
for ( var key in defaults ){
if ( !(key in options) ) options[ key ] = defaults[ key ];
}
var output = options.output;
delete options.output;
var args = optionsToArgs( options ).concat(
path.join( config.wavDir, output )
);
console.log( 'arecord', args.join(' ') );
var arecord = proc.spawn( 'arecord', args );
// arecord.on( 'error', function( code, error ){
// callback( error );
// });
// arecord.on( 'close', function( code ){
// callback();
// });
};