CPython Based Audio Processing Solution Sample using Krisp

Overview

CPython is the most popular Python framework. There are multiple frameworks dedicated to building CPython modules using C/C++ code. At Krisp, we have published the open-source CPython-based audio processing sample solution using pybind11 to be used as a reference to build a CPython module using the C++ based Krisp Audio SDK. 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 Python, 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

To use an audio processing sample you need to

  1. Import the compiled CPython module
  2. Set the sampling rate of the audio stream
  3. Specify Krisp NC model
  4. In the loop
    1. Provide an audio data buffer
    2. Extract processed audio in the form of a list of 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.

import audio_processor

sample_rate = 16000
model_path = "/Users/yourname/krisp-models/any_krisp_nc_model.kef"
ap_wrapper = AudioProcessorWrapper(sample_rate, 1, model_path)

def getAudioData():
  # return the available audio data
  pass
  
def processAudioFrames(procesed_10ms_frames):
  # process noise canceled audio frames according to the bussiness logic

# the continous audio processing loop  
while True:
  audio_data = getAudioData()
  ap_wrapper.store_audio_chunk(audio_data)
  nc_aggressiveness_toggle = 100 # from 1-100
  processed_10ms_frames = ap_wrapper.get_processed_frames(nc_aggressiveness_toggle)
  processAudioFrames(processed_10ms_frames)
  

ℹ️

Krisp NC tech can only process 10ms sized audio frames.

When calling theap_wrapper.store_audio_chunk(audio_data), if the audio_data size is not multiple to 10ms, the remainder will be kept in the system and will be concatenated to the beginninng of the next audio data.

Build

To build CPython based audio processing solution you need to

  1. download Krisp Audio SDK v9 for Windows, Linux or Mac.
  2. clone the https://github.com/krispai/Krisp-SDK-Sample-Apps
  3. select krisp-sdk-v9 branch
  4. follow instructions in details in the README.md file