Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving latency of audio #231

Open
alexdufetel opened this issue Nov 25, 2018 · 0 comments
Open

Improving latency of audio #231

alexdufetel opened this issue Nov 25, 2018 · 0 comments

Comments

@alexdufetel
Copy link

alexdufetel commented Nov 25, 2018

I'm using "ReSpeaker Mic Array - Far-field w/ 7 PDM Microphones" with a Raspberry Pi. I can get it to work properly for audio capture / hotword detection. I also want to display volume from my Node app, but I can't get my VU meter under a ~1s latency.

I'm capturing audio via arecord called from Node. I measure audio levels directly through the data being sent by the card (see code below). Any suggestion on how I can bring the latency down? I'd like my VU meter to react approximately as fast as the leds on the Mic Array. I'm open to any solution.

Thanks to anyone who can help out!

`
const arProcess = spawn('arecord', [
'-q',
'-r', 16000,
'-c', 1,
'-t', 'wav',
'-f', 'S16_LE',
'-D', 'plughw:AR',
'-V', 'mono',
], { encoding: 'binary'});

arProcess.stdout.on('data', _update);
function _update(buffer){
var bufLength = buffer.length;
var min = 0;
var max = 0;
var sample;

    for (var i = 0;  i < bufLength; i += 2) {
        //Reads an unsigned 16-bit integer from buf at the specified offset with specified endian format (readUInt16BE() returns big endian, readUInt16LE() returns little endian).
        sample = buffer.readInt16LE(i + 0, true);
        min = (sample < min ? sample : min);
        max = (sample > max ? sample : max);
    }
   console.log(_log10(Math.max(max, -min) / 32768) * 20); 
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant