Node.js
Audio Processing Sample Solution For Node.js
Overview
For Node.js and Electron integration with Krisp Audio SDK, we recommend using the Node.js Native Add-on. At Krisp, we have published the open-source audio processing sample solution for Node.js using Native Add-on to bring Krisp Audio SDK native libraries to Node.js. The audio processing sample works directly with the audio data, it does not include audio capturing logic.
Instead of mapping every function from C++ based SDK to Javascript, we find it more practical to provide an audio processing solution directly, which requires minimum configuration to embed Krisp tech into your business logic.
Usage
- Import compiled Node.js Krisp module
- Specify the Krisp NC model path
- Specify the sampling rate of the audio
- In the loop
- Provide audio data
- Get processed 10ms sized frames
Check the attached code snippet for the details. In the sample code, you must implement the getAudioData() and the processAudioFrames() functions to fit your business logic.
Limitation: audioData should be sized to the multiple to 10ms
It is not efficient to allocate buffer each time in the audio processing loop. Refer to the GitHub sample for more efficient approach.
Make sure audioData and processAudio frames buffers have the same size. Othewise exception will be thrown.
const addon = require('./nodejs-module.node');
const KrispAudioProcessor = addon.KrispAudioProcessor;
const audioProcessor = new KrispAudioProcessor();
audioProcessor.loadModel(modelPath);
audioProcessor.setSampleRate(sampleRate);
function getAudioData() {
// get audio binary data per your business logic
}
function processNoiseCleanedAudioFrames(processed10msFrames) {
// process audio data per your business logic
}
while (true) {
const audioData = getAudioData();
const processedAudio = Buffer.alloc(audioData.length);
if (PcmFloat32) {
audioProcessor.processFramesFloat32(audioData, processedAudio);
}
else if (Pcm16) {
audioProcessor.processFramesPcm16(audioData, processedAudio);
}
processNoiseCleanedAudioFrames(processedAudio);
}
Build
- download Krisp Audio SDK v7 for Windows, Linux or Mac.
- clone the https://github.com/krispai/Krisp-SDK-Sample-Apps public GitHub repository
- switch to the krisp-sdk-v7 branch
- follow instructions in details in the README.md
Updated 8 days ago