Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graphoarty/4256f42cd2a10cdbfb58f19de0720821 to your computer and use it in GitHub Desktop.
Save graphoarty/4256f42cd2a10cdbfb58f19de0720821 to your computer and use it in GitHub Desktop.
Gist for Converting an Array into a 32bit Floating Point Buffer for WebRTC Voice Activity Detection (javascript, node-vad)
// Javascript
// Using node-vad
floatingPointArray = [...];
let buf = Buffer.allocUnsafe(4 * floatingPointArray.length);
for (var k = 0 ; k < floatingPointArray.length ; k++) {
buf.writeFloatLE(floatingPointArray[k], k * 4);
}
let decision = await vad.processAudio(buf, 16000); // 16000 is the sampling rate
switch (decision) {
case VAD.Event.ERROR:
console.log("ERROR");
break;
case VAD.Event.NOISE:
console.log("NOISE");
break;
case VAD.Event.SILENCE:
console.log("SILENCE");
break;
case VAD.Event.VOICE:
console.log("VOICE");
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment