🎯 Voice AI Consulting
Get dedicated support and consultation to ensure your specific needs are met.
Consult an AI Expert

Real-time noise suppression (or noise cancellation) in C enables developers to build high-quality audio applications that work across Linux, Windows, macOS, and Raspberry Pi. By implementing on-device processing, you can deliver clear speech output for voice assistants, video conferencing, and speech-to-text systems without requiring cloud connectivity.

Background noise degrades speech clarity and reduces the accuracy of voice interfaces. This is especially problematic for real-time applications where users expect immediate, reliable responses. Noise cancellation solutions like Krisp, NVIDIA RTX Voice, and Koala Noise Suppression solve this by cleaning audio, enhancing speech intelligibility and recognition accuracy, which benefits use cases such as meeting transcriptions and voice-enabled smart fitness apps.

However, Krisp and NVIDIA RTX Voice are typically end-user tools, leaving adoption up to the user. In contrast, Koala Noise Suppression can be integrated directly into your application, delivering consistent, built-in noise cancellation that works across all major platforms.

This tutorial demonstrates how to implement production-ready noise suppression with Koala Noise Suppression, a cross-platform, on-device C library optimized for real-time performance. You'll learn how to load an audio file, process it through the noise suppression pipeline, and output the processed clean audio. By the end, you'll have a working application that delivers reliably cleaner speech audio across all supported platforms.

Prerequisites

  • C99-compatible compiler
  • Windows: MinGW
  • Noisy WAV audio file(s) for testing

Supported Platforms

  • Linux (x86_64)
  • macOS (x86_64, arm64)
  • Windows (x86_64, arm64)
  • Raspberry Pi (3, 4, 5)

Part 1. Set Up Your C Noise Suppression Project

This is the folder structure used in this tutorial. You can organize your files differently if you like, but make sure to update the paths in the examples accordingly:

Clone the dr_libs repo:

Add Koala library files

  1. Create a folder named koala/.
  2. Download the Koala header files from GitHub and place them in:
  1. Download a Koala model file and the correct library file for your platform and place them in:

Part 2. Cross-Platform Dynamic Library Loading

Koala Noise Suppression distributes pre-built platform libraries, meaning:

  • the shared library (.so, .dylib, .dll) is not linked at compile time
  • the program loads it at runtime
  • functions must be retrieved by name

So, we need to write small helper functions to:

  1. open the shared library
  2. look up function pointers
  3. close the shared library

Include platform-specific headers

Understanding the headers:

  • Windows-specific: windows.h provides LoadLibrary to load a shared library and GetProcAddress to retrieve individual function pointers
  • Unix-specific: dlfcn.h provides dlopen and dlsym, which provide the same functionality as LoadLibrary and GetProcAddress
  • UTF8_COMPOSITION_FLAG and NULL_TERMINATED: Constants for reading and writing audio files on Windows

Define dynamic loading helper functions

Open the shared library

Load function symbols

Close the dynamic library

Load the library file

Downloaded the correct library file for your platform and point library_path to the file:

Load dynamic library functions

Load all required function symbols for Koala Noise Suppression:

Part 3. Build Real-Time Noise Cancellation: Complete C Implementation Guide

Now that we've set up dynamic loading, we can actually use the Koala Noise Suppression API.

Initialize Koala Noise Suppression

  1. Sign up for an account on Picovoice Console for free and obtain your AccessKey
  2. Replace ${ACCESS_KEY} with your AccessKey
  3. Point model_path to your downloaded Koala model file.

Call pv_koala_init to create a Koala Noise Suppression instance:

The device parameter lets you choose what hardware the engine runs on.

Load input file (noisy)

Initialize and open your noisy audio file using the dr_wav library:

On Windows, the file path must be converted from UTF-8 to wide characters (UTF-16) before opening.

Prepare output file (cleaned audio)

Configure and create the output WAV file with specific audio parameters (16-bit PCM, mono channel, 16kHz sample rate):

This step only prepares the output WAV file. It creates and configures a file with the correct format. In the next steps, we'll write the noise-suppressed (cleaned) audio frames to it as they are processed.

Prepare for audio processing

Determine the delay in samples (between input and output) and allocate memory buffers for the input and output frames:

Key components:

  • pv_koala_delay_sample_func: Returns the number of samples of latency between input and output (delay due to processing time).
  • pv_koala_frame_length_func: Returns the exact number of audio samples required per processing frame.

Process noisy audio

Read the input audio in fixed-size frames, apply Koala's noise suppression to each frame, and write the enhanced output while correctly handling the delay to ensure proper alignment:

Processing flow:

  1. Frame reading: Audio is read in chunks matching Koala's required frame size, with zero-padding applied when needed.
  2. Noise suppression: Each frame is processed through pv_koala_process, which returns the enhanced audio with noise removed.
  3. Delay compensation: The output is carefully aligned by skipping the initial delay_samples and ensuring the final output matches the original audio's duration, accounting for both the delay and any partial frames at the end.

Cleanup Resources


Full Working Example: C Noise Suppression Application Code

Below is the complete koala_tutorial.c file you can copy, build, and run:

koala_tutorial.c

Before running, update:

  • INPUT_WAV_PATH to point to your noisy audio file
  • OUTPUT_WAV_PATH to specify where to save the enhanced audio
  • KOALA_MODEL_PATH to point to the Koala Noise Suppression model file (.pv)
  • KOALA_LIB_PATH to point to the correct Koala Noise Suppression library for your platform
  • PICOVOICE_ACCESS_KEY with your AccessKey from Picovoice Console

This is a simplified example but includes all the necessary components to get started. Check out the Koala C demo on GitHub for a complete demo application with WAV file I/O.

Compile and Run Your C Noise Suppression Application

Build and run the application:

Linux (gcc) and Raspberry Pi (gcc)

macOS (clang)

Windows (MinGW)

Conclusion

You now have a complete cross-platform noise suppression implementation in C that works on Linux, Windows, macOS, and Raspberry Pi. The dynamic loading approach gives you flexibility to deploy the same codebase across all supported platforms without modification.

This tutorial covered the essentials: setting up the Koala Noise Suppression library, implementing platform-specific dynamic loading, processing audio frames for noise suppression, and handling cleanup. You can extend this foundation by integrating real-time microphone input with PvRecorder, or adding noise suppression as a pre-processing step in other speech recognition pipelines, such as real-time speech-to-text or voice-controlled applications.

Start Building

Solving Common C Noise Suppression Implementation Problems

Audio file won't open or produces format errors

Confirm that your input audio file is in the correct format: 16-bit PCM, mono channel, and 16 kHz sample rate. Many audio files use different sample rates or stereo channels. Use audio conversion tools to resample and convert your files to the required format before processing.

Compilation fails with missing header errors

Double-check that all include paths in your compiler command match your actual folder structure. The -I flags should point to directories containing the header files, not the files themselves. Verify that you've downloaded all required header files and placed them in the correct locations.

Output audio is silent or corrupted

This often occurs when delay compensation isn't handled correctly. Ensure you're implementing the delay sample logic properly to align input and output streams. Also verify that memory buffers are properly allocated and that frame lengths match what the API expects.

Access key authentication fails

If initialization fails with an authentication error, verify that you've replaced the placeholder AccessKey with your actual key from Picovoice Console.


Frequently Asked Questions

Can I process real-time audio streams instead of files with Koala Noise Suppression?

Yes. The code examples use file I/O for simplicity, but Koala processes audio frame-by-frame. You can replace file reading with microphone input (e.g., via PvRecorder) or any streaming input. Just ensure you feed frames of the correct length to the processing function at the appropriate sample rate.

Does Koala Noise Suppression work with audio files in formats other than WAV?

Koala processes raw PCM audio data. You'll need to decode other formats (MP3, AAC, etc.) to 16-bit PCM at 16 kHz before passing audio to Koala.

How do I compile for cross-platform deployment from a single codebase?

The code in this tutorial is already cross-platform. Use conditional compilation directives to handle platform-specific library loading. Compile with the appropriate compiler for each target platform: gcc for Linux and Raspberry Pi, clang for macOS, MinGW for Windows.

Can I adjust the aggressiveness of noise suppression?

Koala Noise Suppression is tuned to provide optimal balance between noise suppression and speech quality. The model is designed to adapt automatically to different noise conditions without requiring manual tuning parameters.