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 code into your business logic.

Usage

  1. import compiled Node.js Krisp module
  2. specify the Krisp NC model path
  3. specify the sampling rate of the audio
  4. in the loop
    1. provide audio data
    2. get processed 10ms sized frames

Check the attached code snippet for the details. In the sample code, you need to 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 processAudioFrames(processed10msFrames) {
  // process audio data per your business logic
}
 
while (true) {
  const audioData = getAudioData();
  const processedAudio = Buffer.alloc(audioData.length);
  if (PcmFloat32) {
      audioProcessor.processFramesFloat32(audio_data, processed_frames);
  }
  else if (Pcm16) {
      audioProcessor.processFramesPcm16(audio_data, processed_frames);
  }
}

Build

  1. download Krisp Audio SDK v7 for Windows, Linux or Mac.
  2. clone the https://github.com/krispai/Krisp-SDK-Sample-Apps public GitHub repository
  3. switch to the krisp-sdk-v7 branch
  4. follow instructions in details in the README.md