Created
July 21, 2020 14:44
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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