@nanoya-biz/tauri-plugin-noise-suppression (0.2.0)

Published 2026-06-10 02:04:25 +02:00 by shjackal

Installation

@nanoya-biz:registry=
npm config set @nanoya-biz:registry=
npm install @nanoya-biz/tauri-plugin-noise-suppression@0.2.0
"@nanoya-biz/tauri-plugin-noise-suppression": "0.2.0"

About this package

tauri-plugin-noise-suppression

Tauri 2.x plugin that exposes rkd-noise-suppression-core::Denoiser to the webview via Tauri commands.

Status — Phase 3b. Plugin built and type-checked; demo scaffold committed. Awaiting manual run-through validation (npm run tauri:dev in examples/tauri-demo/). Do not depend on this in production until that validation step has been completed and documented.


Build

The plugin has two parts: a Rust crate and a JS wrapper. The Rust crate is built automatically by Cargo when your Tauri app compiles. The JS wrapper must be built once manually so the dist-js/ directory exists for the demo or any consuming app.

cd crates/tauri-plugin
npm install
npm run build

This produces dist-js/{index.js, index.mjs, index.d.ts} from the TypeScript source in guest-js/index.ts.


Add to a Tauri 2.x app

1. Cargo dependency

In src-tauri/Cargo.toml:

[dependencies]
tauri-plugin-noise-suppression = { path = "<relative-path-to>/crates/tauri-plugin" }

Once the plugin is published to crates.io (Phase 3b-2), this becomes:

tauri-plugin-noise-suppression = "0.1"

2. JS dependency

In your app's package.json:

{
  "dependencies": {
    "tauri-plugin-noise-suppression": "file:../../crates/tauri-plugin"
  }
}

Build the JS wrapper first (npm install && npm run build in crates/tauri-plugin/) so the dist-js/ output exists before your app's npm install resolves the file dep.

3. Register the plugin

In src-tauri/src/main.rs:

fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_noise_suppression::init())
        // … other plugins …
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

4. Enable the capability

In src-tauri/capabilities/default.json:

{
  "identifier": "default",
  "windows": ["main"],
  "permissions": [
    "core:default",
    "noise-suppression:default"
  ]
}

The noise-suppression:default permission grants all six commands: init_denoiser, frame_size_at_48k, process_frame, reset, set_setting, get_setting.

5. Use from frontend code

import {
  initDenoiser,
  frameSizeAt48k,
  processFrame,
  reset,
} from "tauri-plugin-noise-suppression";

// Initialize once (before audio capture starts).
await initDenoiser({ modelDir: "/path/to/models/dfn2", sampleRate: 48000 });

// Per-frame call (~100/sec at 48 kHz with 480-sample frames).
const denoised: Float32Array = await processFrame(inputFrame);

// Clean up (e.g. on session end).
await reset();

Setting ORT_DYLIB_PATH

The plugin uses ONNX Runtime via deepfilter-rt. On Windows, the system may have a stale onnxruntime.dll in System32 that will be loaded in preference to the version this plugin expects (=2.0.0-rc.11 ORT ABI). Set ORT_DYLIB_PATH to the bundled runtime before tauri dev starts:

# PowerShell (Windows)
$env:ORT_DYLIB_PATH = "C:\path\to\onnxruntime\lib\onnxruntime.dll"
npm run tauri:dev

# bash / macOS / Linux
ORT_DYLIB_PATH="/path/to/onnxruntime/lib/libonnxruntime.dylib" npm run tauri:dev

Or set it programmatically in src-tauri/src/main.rs before the builder runs:

fn main() {
    // Set before any ORT initialization happens.
    std::env::set_var(
        "ORT_DYLIB_PATH",
        "/absolute/path/to/onnxruntime/lib/onnxruntime.dll",
    );
    tauri::Builder::default()
        .plugin(tauri_plugin_noise_suppression::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

ORT version pin

This plugin pins ort = "=2.0.0-rc.11" — the same version as crates/napi. Both depend on deepfilter-rt which bundles its own ORT C ABI expectations. Do not upgrade ORT independently; upgrade both together when deepfilter-rt releases a new version.


Caveats

  • Per-frame invoke overhead. Each processFrame call crosses the webview→Tauri IPC boundary, which adds ~1–5 ms on Windows. At 100 frames/sec this is usually inaudible, but on very loaded systems it can cause occasional audio glitches. The SharedArrayBuffer ring-buffer path (Phase 3c) eliminates this overhead.

  • Binary IPC. The plugin uses tauri::ipc::Response::new(bytes) and raw binary request bodies to avoid per-frame JSON serialization. If you invoke process_frame via the standard JSON path you will get a "expected raw binary body" error. Always pass a Uint8Array/ArrayBuffer as the invoke payload.

  • Single instance. The current implementation manages one Denoiser instance per plugin registration. Multi-mic scenarios (multiple streams denoised simultaneously) require multiple plugin registrations or a future session-keyed API.

  • State is app-lifetime. initDenoiser fails with AlreadyInitialized if called twice. Call reset to clear internal ring buffers without re-initializing, or use initDenoiser after app restart.


Reference

See docs/integrations/tauri.md for the full integration guide including audio graph wiring, bundling, performance analysis, and troubleshooting.

Dependencies

Development dependencies

ID Version
@rollup/plugin-typescript ^12.0.0
@tauri-apps/api ^2.0.0
rollup ^4.0.0
tslib ^2.6.0
typescript ^5.6.0

Peer dependencies

ID Version
@tauri-apps/api ^2.0.0
Details
npm
2026-06-10 02:04:25 +02:00
2
2026-11-12 11:42:36 +01:00
Apache-2.0
3.7 KiB
Assets (1)
Versions (9) View all
0.2.3-rc.3 2026-11-21
0.2.3-rc.2 2026-11-21
0.2.3-rc.1 2026-11-21
0.2.1 2026-06-10
0.2.0 2026-06-10