gillesdemey / node-record-lpcm16

:microphone: Records a 16-bit signed-integer linear pulse modulation code encoded audio file.
ISC License
212 stars 59 forks source link

Thresholds #65

Open ericmittler opened 2 years ago

ericmittler commented 2 years ago

Can someone point me to the documentation on thresholds? I am trying to get a recording to stop after a (configurable) moment of silence (say 2 seconds). I don't see any example of this, but it appears that it is possible with "endOnSilence" and thresholds.

Here's a bit of code that I would have thought would start after some 0.5 threshold (whatever that means) and ends after 1 second of silence meeting a thresholdEnd of 0.2 (whatever that means). But it just records forever.

import fs from 'fs'
import recorder from 'node-record-lpcm16'
const localAudioFileName = `/tmp/lpcm16recording.mp3`
const file = fs.createWriteStream(localAudioFileName, { encoding: 'binary' })
const recording = recorder.record({
  sampleRate: 16000, recordProgram: 'sox',
  thresholdStart: 0.5, thresholdEnd: 0.2, silence: 1.0, endOnSilence: true
}).stream().pipe(file)

What changes to this code would I have to make to have the recording stop when it detects silence?

UPDATE: I played with the thresholds and a different microphone and it seems to work. I would still like to see some docs on thresholds as I'm guessing what they do and I'd rather not guess. Is it also possible that 'rec' ignores thresholds and 'sox' implements them?

Thanks +Eric