npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@subcueai/tauri-plugin-system-audio

v0.1.1

Published

Tauri 2 JS bindings for dual audio capture — microphone + system audio (WASAPI loopback) with WebRTC AEC3.

Readme

tauri-plugin-system-audio

npm crates.io docs.rs license: MIT

Capture what your app hears and what the computer plays — with echo cancellation — in Tauri 2.

Microphone + system audio (WASAPI loopback) dual capture for Windows, with WebRTC AEC3 echo cancellation, anti-aliased resampling to 16 kHz mono PCM, and 10 Hz level metering. Extracted from the production desktop app of SubcueAI, where it feeds live dual-stream speech-to-text during video calls.

  ┌─────────────┐    ┌─────────────┐    ┌───────────┐
  │ mic capture │───▶│  resampler  │───▶│   APM     │──▶ Pcm { source: "mic" }
  └─────────────┘    │  to 16k f32 │    │ near-end  │
                     └─────────────┘    └───────────┘
  ┌─────────────┐    ┌─────────────┐    ┌───────────┐
  │ loopback*   │───▶│  resampler  │───▶│   APM     │──▶ Pcm { source: "loopback" }
  └─────────────┘    │  to 16k f32 │    │ reverse   │
     *Windows only    └─────────────┘    └───────────┘

Why this exists

Capturing system audio in a Tauri app is a recurring pain point: browsers can't do it, getDisplayMedia audio is unreliable, and most examples stop at "open a mic stream". This plugin packages the hard parts:

  • WASAPI loopback via cpal 0.16 — capturing the default output device as an input stream (AUDCLNT_STREAMFLAGS_LOOPBACK), so you hear Zoom/Meet/Teams/whatever the machine plays. No virtual audio driver, no Stereo Mix.
  • Echo cancellation that actually works — the loopback feed doubles as WebRTC AEC3's far-end reference, so your own speakers are subtracted from the mic before your app sees it. Without this, speaker bleed re-enters the mic and wrecks downstream STT/recording.
  • Dual independent streams — mic and loopback are emitted as separate tagged PCM streams (not premixed), so you can route them to two STT sessions and label "local speaker" vs "remote party". A sample-and-hold Mixer is included if you want one combined stream.
  • STT-grade signal path — f32 end to end (no precision-eating i16 round-trips), 129-tap windowed-sinc anti-alias filter on downsample, i16 quantisation only at the serialisation boundary, 20 ms frames for continuous interim STT partials.
  • The boring-but-vital details — Windows mic-consent registry preflight (otherwise you capture silence forever), permission-aware error categories for UI deep-links, allocation-free hot path, drift-tolerant frame pairing, clean stream teardown order.

Platform behavior: Windows = full pipeline. macOS/Linux = mic-only (loopback and APM compile to stubs; on macOS, Apple's VPIO already does AEC at the OS level, and system-audio capture there is ScreenCaptureKit's job — out of scope for this plugin).

Install

Rust side (src-tauri/Cargo.toml):

cargo add tauri-plugin-system-audio
[dependencies]
tauri-plugin-system-audio = "0.1"

Register the plugin:

fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_system_audio::init())
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

Allow the commands in your capability file (src-tauri/capabilities/default.json):

{ "permissions": ["system-audio:default"] }

Echo cancellation dll (Windows)

AEC needs webrtc-apm/webrtc-apm.dll (a C-ABI build of WebRTC's AudioProcessing module, BSD-3 licensed — ABI reference). Copy it into src-tauri/resources/ and bundle it:

// tauri.conf.json
{ "bundle": { "resources": ["resources/webrtc-apm.dll"] } }

The plugin resolves the bundled dll automatically (dev and build). Missing dll degrades gracefully: capture keeps working, just without echo cancellation — a warning is logged.

Use (JavaScript)

npm i @subcueai/tauri-plugin-system-audio
import { start, stop, decodePcm } from '@subcueai/tauri-plugin-system-audio';

await start((event) => {
  switch (event.kind) {
    case 'pcm': {
      const samples = decodePcm(event.samples_base64); // Int16Array, 16 kHz mono, 20 ms
      if (event.source === 'mic') sttLocal.send(samples);
      else sttRemote.send(samples); // system audio: the remote party
      break;
    }
    case 'level': // 10 Hz meter: event.mic_rms / event.loopback_rms (0..1)
      break;
    case 'failure': // category: 'permission' | 'device' | 'io' | 'lifecycle'
      break;
  }
});

// later
await stop();

Options (all optional): start(onEvent, { loopback: true, processing: true, levelOnly: false })

  • loopback: false — mic only.
  • processing: false — skip WebRTC APM entirely.
  • levelOnly: true — no PCM at all, just 10 Hz levels (~0% upload, <1% CPU) for an idle "mic check" meter.

Pre-flight the mic permission for your Settings UI:

const status = await permissionStatus(); // 'allowed' | 'denied' | 'unknown'

Event reference

| Event | Payload | Notes | |---|---|---| | pcm | seq, source (mic|loopback), sample_rate (16000), channels (1), samples_base64 | 20 ms frames; i16 LE, base64 | | level | mic_rms, loopback_rms (0..1) | ≤10 Hz, deduped below 0.005 delta | | failure | category, message | Worker exited; permission → deep-link OS Settings |

FAQ

Why 16 kHz mono? It's the native rate of speech models and WebRTC APM's processing band. Capturing at device rate and downsampling once (with a proper anti-alias FIR) beats letting each downstream consumer resample.

Why base64 over a Tauri Channel instead of raw buffers? One ordered channel carries tagged heterogeneous events (pcm/level/failure) with backpressure, ~160 KB/s per stream — trivial for the IPC. Decode cost is one atob per 20 ms.

Can it capture a specific app's audio only? No — WASAPI loopback captures the default render endpoint mix. Per-process capture needs the Windows 10 2004+ AUDIOCLIENT_PROCESS_LOOPBACK path, which cpal doesn't expose yet.

Does AEC work if the user wears headphones? There's simply no echo to cancel — AEC3 idles. Loopback capture still works and is unaffected.

macOS system audio? Use ScreenCaptureKit from native code (that's what SubcueAI's own macOS app does); this plugin intentionally stays cpal-only.

Provenance & license

This is the audio pipeline that ships in SubcueAI's Windows desktop app (Tauri 2 + React), extracted with its production comments and tests intact.

MIT © 2026 Subcue AI LLC. webrtc-apm.dll is built from BSD-3-Clause WebRTC — see THIRD-PARTY.md.