Anira Documentation#

anira Logo#

build_test codecov build_benchmark build_examples build_sanitizer build_docs on_tag


Anira is a high-performance library designed to enable easy real-time safe integration of neural network inference within audio applications. Compatible with multiple inference backends, LibTorch, ONNXRuntime, and Tensorflow Lite, anira bridges the gap between advanced neural network architectures and real-time audio processing. In the paper you can find more information about the architecture and the design decisions of anira, as well as extensive performance evaluations with the built-in benchmarking capabilities.

News#

anira user research: September to October 2026

As part of our work funded by the Prototype Fund, we want to provide example implementations with ready-made, plug-and-play models that the open-source community actually needs, e.g. for real-time audio or video processing.

To find out which models would be most useful, we’d love to hear from you, whether you already use anira or are just interested in real-time AI.

Take the survey (open until the end of October 2026)

Already using anira? We’d love a short interview about your experience. Just reach out at contact@tanh-lab.com.

Features#

  • Real-time Safe Execution: Ensures deterministic runtimes suitable for real-time audio applications

  • Thread Pool Management: Utilizes a static thread pool to avoid oversubscription and enables efficient parallel inference

  • Minimal Latency: Designed to minimize latency while maintaining real-time safety

  • Built-in Benchmarking: Includes tools for evaluating the real-time performance of neural networks

  • Comprehensive Inference Engine Support: Integrates common inference engines, LibTorch, ONNXRuntime, LiteRT, TensorFlow Lite and ExecuTorch

  • Flexible Neural Network Integration: Supports a variety of neural network models, including stateful and stateless models

  • Cross-Platform Compatibility: Works seamlessly on macOS, Linux, Windows, Android and iOS, and in the browser via WebAssembly

Usage#

The basic usage of anira is as follows:

#include <anira/anira.h>

anira::InferenceConfig inference_config(
        {{"path/to/your/model.onnx", anira::InferenceBackend::ONNX}}, // Model path
        {{{256, 1, 1}}, {{256, 1}}},  // Input, Output shape
        5.33f // Maximum inference time in ms
);

// Create a pre- and post-processor instance
anira::PrePostProcessor pp_processor(inference_config);

// Create an InferenceHandler instance
anira::InferenceHandler inference_handler(pp_processor, inference_config);

// Pass the host configuration and allocate memory for audio processing
inference_handler.prepare({buffer_size, sample_rate});

// Select the inference backend
inference_handler.set_inference_backend(anira::InferenceBackend::ONNX);

// Optionally get the latency of the inference process in samples
unsigned int latency_in_samples = inference_handler.get_latency();

// Real-time safe audio processing in process callback of your application
process(float** audio_data, int num_samples) {
    inference_handler.process(audio_data, num_samples);
}
// audio_data now contains the processed audio samples

Installation#

C++ Library#

Anira can be easily integrated into your CMake project. You can either add anira as a submodule, download the pre-built binaries from the releases page, or build from source.

Option 2: Use Pre-built Binaries#

Download pre-built binaries from the releases page.

In your CMakeLists.txt:

# Setup your project and target
project(your_project)
add_executable(your_target main.cpp ...)

# Add the path to the anira library as cmake prefix path and find the package
list(APPEND CMAKE_PREFIX_PATH "path/to/anira")
find_package(anira REQUIRED)

# Link your target to the anira library
target_link_libraries(your_target anira::anira)

# Only if your own code calls an engine: link its anira::<engine> target too
target_link_libraries(your_target anira::onnxruntime)

anira::anira carries anira’s headers and the USE_<ENGINE> definitions, but no engine header: the engines are linked privately. A target that calls an engine itself links the matching engine target — anira::onnxruntime, anira::tflite, anira::litert, anira::libtorch or anira::executorch — which exists both in the build tree and in the installed package, carries the engine’s headers, and is the very file anira links, so the process never holds a second copy of the engine.

Option 3: Build from Source#

git clone https://github.com/anira-project/anira.git
cd anira
cmake . -B build -DCMAKE_BUILD_TYPE=Release -DANIRA_WITH_INSTALL=ON
cmake --build build --config Release --target anira
cmake --install build --prefix /path/to/install/directory

Or with the bundled presets (desktop-install-release / desktop-install-debug):

cmake --preset desktop-install-release
cmake --build --preset desktop-install-release
cmake --install build/desktop/Install/Release --prefix /path/to/install/directory

Without --prefix, the tree is installed to <build dir>/anira-<version>.

The install tree also carries the Apache-2.0 core component of tanh-lib that backs anira’s buffers, together with its own CMake package; find_package(anira) resolves it automatically via find_dependency(tanh COMPONENTS Core), so consumers only add the anira prefix to CMAKE_PREFIX_PATH.

C++ Build Options#

By default, LibTorch, ONNXRuntime, LiteRT and ExecuTorch are enabled. You can disable specific backends as needed:

  • LibTorch: -DANIRA_WITH_LIBTORCH=OFF

  • OnnxRuntime: -DANIRA_WITH_ONNXRUNTIME=OFF

  • LiteRT (LiteRt* C API): -DANIRA_WITH_LITERT=OFF — runs .tflite models through LiteRT’s native CompiledModel runtime. Enabled by default; it is the modern TensorFlow-Lite-family backend.

  • TensorFlow Lite (legacy TfLite* C API): -DANIRA_WITH_TFLITE=ON — the same runtime as LiteRT exposed through the older C API, so the two are mutually exclusive. To use it, disable LiteRT: -DANIRA_WITH_LITERT=OFF -DANIRA_WITH_TFLITE=ON.

  • ExecuTorch: -DANIRA_WITH_EXECUTORCH=OFF — runs .pte programs exported ahead-of-time with torch.export; PyTorch’s edge/mobile inference stack (CPU execution via XNNPACK). Enabled by default; static-only.

Platform / backend support#

anira builds on the targets below; the pre-built backends it downloads ship per target as shared and/or static. Backend linkage follows BUILD_SHARED_LIBS: a shared anira links shared backends, a static anira links static backends, and an engine that does not ship the required linkage is disabled with a warning:

Target

LibTorch

ONNXRuntime

LiteRT

TFLite (legacy)

ExecuTorch

macOS x86_64

shared

shared · static

shared · static

shared · static

static

macOS arm64

shared

shared · static

shared · static

shared · static

static

macOS universal

shared

shared · static

shared · static

shared · static

static

Linux x86_64

shared

shared · static

shared · static

shared · static

static

Linux aarch64

shared

shared · static

shared · static

shared · static

static

Windows x86_64

shared

shared · static

shared · static

shared · static

static

Windows arm64

shared

shared · static

shared · static

shared · static

static

WASM (Emscripten)

—

static

—

—

—

LibTorch is shared-only (disabled in a static anira build); ExecuTorch is static-only (disabled in a shared anira build). iOS and WebAssembly are static-only altogether (-DBUILD_SHARED_LIBS=OFF). LiteRT and TFLite are the same runtime via two C APIs and are mutually exclusive (LiteRT is the default). In a fully static anira build ExecuTorch cannot be combined with LiteRT or TFLite (each bundles its own copy of XNNPACK, whose symbols collide in one static image) — ExecuTorch is then auto-disabled; disable LiteRT/TFLite to build a static anira with ExecuTorch. On WebAssembly only ONNX Runtime is supported. Backends for Android and iOS are also published in the anira-project/backends release for cross-builds. — = not provided.

Pre-built backend binaries are downloaded at configure time from the anira-project/backends release pinned by ANIRA_BACKENDS_VERSION. Integrity is checked live: when GitHub is reachable, anira fetches each asset’s published SHA256 and re-downloads any backend whose archive changed upstream or downloaded incompletely (the download is verified against that hash). Nothing is pinned in-repo. The source is configurable (the linkage is not: it follows BUILD_SHARED_LIBS, see above):

  • Backends release tag: -DANIRA_BACKENDS_VERSION=v2.1.1.

  • Offline / reproducible builds: -DANIRA_BACKENDS_SKIP_REMOTE_CHECK=ON skips the GitHub query and reuses whatever is already in modules/.

  • Bring your own backend (no fork): -DANIRA_<ENGINE>_ROOTDIR=/path/to/prebuilt (a tree with include/ + lib/), or a custom source via -DANIRA_<ENGINE>_URL=... -DANIRA_<ENGINE>_SHA256=....

Moreover, the following options are available:

  • Build anira with benchmark capabilities: -DANIRA_WITH_BENCHMARK=ON

  • Build example applications, plugins and populate example neural models: -DANIRA_WITH_EXAMPLES=ON

  • Build anira with tests: -DANIRA_WITH_TESTS=ON

  • Build anira with documentation: -DANIRA_WITH_DOCS=ON

  • Disable the logging system (compiles every anira log call out; anira otherwise logs through tanh-lib’s thl::Logger): -DANIRA_WITH_LOGGING=OFF

Anira Web (Web / JavaScript)#

Anira is available as the @anira-project/anira package for use in web applications:

# npm
npm install @anira-project/anira

# pnpm
pnpm add @anira-project/anira

# yarn
yarn add @anira-project/anira

Building @anira-project/anira from source#

If you want to build the WASM module and JavaScript bindings yourself, you need to provide your own Emscripten SDK. The CMake presets expect the EMSDK environment variable to be set to the root of your emsdk installation.

git clone https://github.com/anira-project/anira.git
cd anira

export EMSDK=/path/to/your/emsdk

# Configure and build the WASM module (release)
cmake --preset web-prod
cmake --build --preset web-prod

# Build the JavaScript package
cd web
npm install
npm run build

For packaging it locally, use

npm pack

in the web folder, which will create a .tgz file that can be installed with npm or yarn.

Then install the package in your project:

npm install path/to/anira/web/anira-project-anira-x.x.x.tgz

A debug preset is also available via cmake --preset web / cmake --build --preset web.

Examples#

Build in examples#

  • Simple JUCE Audio Plugin: Demonstrates how to use anira in a real-time audio JUCE / VST3-Plugin.

  • CLAP Plugin Example: Demonstrates how to use anira in a real-time clap plugin.

  • Benchmark: Demonstrates how to use anira for benchmarking of different neural network models, backends and audio configurations.

  • Minimal Inference: Demonstrates how minimal inference applications can be implemented in all three backends.

Other examples#

  • nn-inference-template: Another more JUCE / VST3-Plugin that uses anira for real-time safe neural network inference. This plugin is more complex than the simple JUCE Audio Plugin example as it has a more appealing GUI.

Real-time safety#

anira’s real-time safety is checked in this repository with the rtsan sanitizer.

Citation#

If you use anira in your research or project, please cite either the paper or the software itself:

@inproceedings{ackvaschulz2024anira,
    author={Ackva, Valentin and Schulz, Fares},
    booktitle={2024 IEEE 5th International Symposium on the Internet of Sounds (IS2)},
    title={ANIRA: An Architecture for Neural Network Inference in Real-Time Audio Applications},
    year={2024},
    volume={},
    number={},
    pages={1-10},
    publisher={IEEE},
    doi={10.1109/IS262782.2024.10704099}
}

@software{ackvaschulz2024anira,
    author = {Valentin Ackva and Fares Schulz},
    title = {anira: an architecture for neural network inference in real-time audio application},
    url = {https://github.com/anira-project/anira},
    version = {x.x.x},
    year = {2024},
}

Contributors#

License#

This project is licensed under Apache-2.0.

Next Steps#

New to Anira? Start with Getting Started for installation and basic usage.

Ready to dive deeper? Check out the Usage Guide and explore Custom Pre/Post Processing or Custom Backend Definition for advanced use cases.

Having issues? See Troubleshooting & FAQ or visit the GitHub repository for support.