├── .npmignore ├── .gitignore ├── package.json ├── index.js └── README.md /.npmignore: -------------------------------------------------------------------------------- 1 | .nide 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .nide 2 | node_modules/ -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "microphone", 3 | "description": "microphone is a simple module that use `arecord` ALSA tools method to capture sound from a USB Microphone", 4 | "version": "1.0.8", 5 | "author": "Vincent Saluzzo", 6 | "contributors": [ 7 | { 8 | "name": "JiaJian", 9 | "email": "its@jiajian.me" 10 | } 11 | ], 12 | "dependencies": { 13 | "lame": "1.0.3" 14 | }, 15 | "devDependencies": {}, 16 | "homepage": "http://github.com/vincentsaluzzo/node-microphone", 17 | "keywords": [ 18 | "microphone", 19 | "alsa", 20 | "mic", 21 | "record", 22 | "audio", 23 | "capture" 24 | ], 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/vincentsaluzzo/node-microphone.git" 28 | }, 29 | "bugs": "http://github.com/vincentsaluzzo/node-microphone/issues" 30 | } 31 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var isMacOrWin = require('os').type() == 'Darwin' || require('os').type().indexOf('Windows') > -1; 2 | var spawn = require('child_process').spawn 3 | var PassThrough = require('stream').PassThrough; 4 | var lame = require('lame'); 5 | 6 | var ps = null; 7 | 8 | var audio = new PassThrough; 9 | var info = new PassThrough; 10 | 11 | var start = function(options) { 12 | options = options || {}; 13 | 14 | if(ps == null) { 15 | ps = isMacOrWin 16 | ? spawn('sox', ['-d', '-t', 'dat', '-p']) 17 | : spawn('arecord', ['-D', 'plughw:1,0', '-f', 'dat']); 18 | 19 | if(options.mp3output === true) { 20 | var encoder = new lame.Encoder( { 21 | channels: 2, 22 | bitDepth: 16, 23 | sampleRate: 44100 24 | }); 25 | 26 | ps.stdout.pipe(encoder); 27 | encoder.pipe(audio); 28 | ps.stderr.pipe(info); 29 | 30 | } else { 31 | ps.stdout.pipe(audio); 32 | ps.stderr.pipe(info); 33 | 34 | } 35 | } 36 | }; 37 | 38 | var stop = function() { 39 | if(ps) { 40 | ps.kill(); 41 | ps = null; 42 | } 43 | }; 44 | 45 | exports.audioStream = audio; 46 | exports.infoStream = info; 47 | exports.startCapture = start; 48 | exports.stopCapture = stop; 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Information 2 | 3 |
| Package | microphone | 6 |
| Description | 9 |microphone is a simple module that use `arecord` ALSA tools on Linux or SoX on OSX & Windows method to capture sound from a USB Microphone | 10 |