node-microphone icon indicating copy to clipboard operation
node-microphone copied to clipboard

Consider removing mp3 encoding?

Open nfriedly opened this issue 9 years ago • 4 comments

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?

  • Split this into two modules: microphone and mp3-microphone OR
  • Move the mp3 part out of the core and into an example

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.

nfriedly avatar Sep 08 '15 02:09 nfriedly

:+1:

jbielick avatar Jan 10 '16 15:01 jbielick

:+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 avatar Mar 07 '16 18:03 1j01

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

1j01 avatar Mar 07 '16 18:03 1j01

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.)

nfriedly avatar Mar 07 '16 19:03 nfriedly