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');
// specify the audio data sample type, only PCM 16 or PCM FLOAT are supported
let sampleType = getAudioSampleType()
let KrispAudioProcessor;
switch (sampleType) {
case "PCM16":
KrispAudioProcessor = addon.KrispAudioProcessorPcm16;
break;
case "FLOAT32":
KrispAudioProcessor = addon.KrispAudioProcessorPcmFloat;
break;
default:
throw new Error("Unsupported sample type: " + sampleType);
}
const audioProcessor = new KrispAudioProcessor();
audioProcessor.configure(modelPath, sampleRate);
function getAudioData() {
// return the available audio data
}
function processNoiseCleanedAudioFrames(processed10msFrames) {
// process noise canceled audio data according to your business logic
}
// the continous audio processing loop
while (true) {
const audioData = getAudioData();
const processedAudio = Buffer.alloc(audioData.length);
audioProcessor.processFrames(audioData, processedAudio);
processNoiseCleanedAudioFrames(processedAudio);
}
Build
- download Krisp Audio SDK v9 for Windows, Linux or Mac.
- clone the <https://github.com/krispai/Krisp-SDK-Sample-Apps> public GitHub repository
- switch to the krisp-sdk-v9 branch
- follow instructions in details in the README.md
Updated 4 days ago