vincentsaluzzo / node-microphone

microphone is a simple module that use `arecord` ALSA tools method to capture sound from a USB Microphone
56 stars 48 forks source link

Consider removing mp3 encoding? #10

Open nfriedly opened 8 years ago

nfriedly commented 8 years ago

Hi,

I'm trying to use this on a raspberry pi, but it won't install because of the lame dependency (https://github.com/TooTallNate/node-lame/issues/58). However, I don't actually need mp3 encoding, just wav will do. I can edit the module myself to remove lame and it does work then, but I thought I'd mention it here. Would you consider one of the following?

I think either of those options would be more in line with the node/unix philosophy of small modules that do one thing and do it well.

jbielick commented 8 years ago

:+1:

1j01 commented 8 years ago

:+1: Was gonna use this for a project on the raspberry pi, but it failed to install even locally because of lame, looked in the issues and found this. Double whammy.

1j01 commented 8 years ago

Looks like there are two pull requests, older and newer trying to update lame to fix compatibility with new node versions. Luckily the module can be expressed in 30 LOC (or 20), so I went a different route:


is_Mac_or_Windows = require('os').type().match(/Darwin|Windows/)
{spawn} = require('child_process')
{PassThrough} = require('stream')

child_process = null
audio = new PassThrough
info = new PassThrough

start = ->
    return if child_process?

    child_process =
        if is_Mac_or_Windows
            spawn('sox', ['-d', '-t', 'dat', '-p'])
        else
            spawn('arecord', ['-D', 'plughw:1,0', '-f', 'dat'])

    child_process.stdout.pipe(audio)
    child_process.stderr.pipe(info)

stop = ->
    child_process?.kill()
    child_process = null

exports.audioStream = audio
exports.infoStream = info
exports.startCapture = start
exports.stopCapture = stop
nfriedly commented 8 years ago

Nice work. That's about what I did, but your's is much cleaner.

@vincentsaluzzo you should just give @1j01 commit & npm publish permissions and call it a day ;)

(Or I'd be willing to take it over if he wasn't interested.)