ashishbajaj99 / mic

A simple stream wrapper for arecord (Linux (including Raspbian)) and sox (Mac, Windows). Returns a Passthrough stream object so that stream control like pause(), resume(), pipe(), etc. are all available.
MIT License
103 stars 61 forks source link

How to process input #9

Closed mydigitalself closed 7 years ago

mydigitalself commented 7 years ago

Hi there, thanks for the module. I had a question and forgive my naivety on how this whole thing works and not overly familiar with streams. How can I get access to the data so I can process it as a series of amplitudes?

ashishbajaj99 commented 7 years ago

Take a look at mic/lib/silenceTransform.js

<snip>
for(i=0; i<chunk.length; i=i+2) {
            if(chunk[i+1] > 128) {
                speechSample = (chunk[i+1] - 256) * 256;
            } else {
                speechSample = chunk[i+1] * 256;
            }
            speechSample += chunk[i];

            if(Math.abs(speechSample) > 2000) {
                if (debug) {
                  console.log("Found speech block");
                }
                resetConsecSilence();
                break;
            } else {
                silenceLength++;
            }

        }
<snip>