A Node.js module to detect audio features in an streaming audio source. The detector is written in Rust, and provides a Writable / Async Iterator interface to NodeJS code.
Warning
This is very, very alpha code. The interfaces may change at any time. The audio matching logic will also be changing heavily.
At this time, the detector code assumes 16-bit 16kHz signed-integer raw audio data. Providing anything else will probably result in garbage output.
import { AudioSnippetDetector } from "@kotobamedia/audio-snippet-detector";
const detector = new AudioSnippetDetector();
// add the sounds you want to detect
detector.add_database('chime', fs.readFileSync('../audio.raw'));
// now, you're ready to detect sounds
const streamingInput = fs.createReadStream('../some-large-file.raw');
streamingInput.pipe(detector);
for await (const item of detector) {
console.log(`I detected ${item.label} (score: ${item.score})`);
}
Tip
score
is an arbitrary value between 0 and 1. Values closer to 1 represent high similarity, but the scale is not linear. Use with caution.
...I will write this later...
Building this package requires a supported version of Node and Rust.
To run the build, run:
$ npm run build
This command uses the @neon-rs/cli utility to assemble the binary Node addon from the output of cargo
.