Compare commits

..
Author SHA1 Message Date
jared 9e6fe75f14 Merge pull request 'fix(denoise): DeepFilterNet attenuation limit 60 → 25 dB (choppy word endings)' (#65) from fix/dfn-strength-25 into lotus
CI / Build embedded bundle (push) Successful in 5m59s
CI / Publish to Gitea npm registry (push) Successful in 4m12s
2026-10-30 18:58:29 -04:00
Lotus CIandClaude Opus 5.5 f180f76196 fix(denoise): DeepFilterNet attenuation limit 60 -> 25 dB
CI / Build embedded bundle (push) Skipped
CI / Build embedded bundle (pull_request) Successful in 8m5s
CI / Publish to Gitea npm registry (pull_request) Skipped
At 60 dB the background is muted outright (measured -61 to -64 dB), so
each word drops into dead silence and listeners hear the mic cutting out
at word ends. On room-echo speech (RT60 ~0.4 s) with fan and keyboard
noise at SNR 15 dB, 25 dB scored best:

  limit  PESQ clean/fan/keyboard   noise removed
  60     3.35 / 2.33 / 2.04        ~62 dB
  40     3.41 / 2.45 / 2.21        32-40 dB
  25     3.59 / 2.72 / 2.38        25 dB
  20     3.63 / 2.66 / 2.25        20 dB

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
2026-10-30 18:50:06 -04:00
jared 4ca3b0695c Merge pull request 'fix(denoise): stop DeepFilterNet silently passing raw audio through' (#64) from fix/dfn-model-bytes into lotus
CI / Build embedded bundle (push) Successful in 8m41s
CI / Publish to Gitea npm registry (push) Skipped
2026-10-30 15:16:25 -04:00
Lotus CIandClaude Opus 5.5 283b231c7a style: oxfmt
CI / Build embedded bundle (push) Skipped
CI / Build embedded bundle (pull_request) Successful in 5m2s
CI / Publish to Gitea npm registry (pull_request) Skipped
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
2026-10-30 15:11:19 -04:00
Lotus CIandClaude Opus 5.5 16f5f3d1a3 fix(denoise): stop DeepFilterNet silently passing raw audio through
CI / Build embedded bundle (push) Skipped
CI / Build embedded bundle (pull_request) Failing after 5m38s
CI / Publish to Gitea npm registry (pull_request) Skipped
If the DeepFilterNet model is served with `Content-Encoding: gzip` (vite
preview does this for .tar.gz; some CDNs and nginx gzip_static setups do
too), fetch() hands back the already-unpacked tar. The library's worklet
then fails inside df_create, swallows the error and passes the raw mic
through, while Lotus Call reports DeepFilterNet as active.

Check the bytes after initialize(): a gzip model is used as-is, an
unpacked tar is re-gzipped in the browser, and anything else throws so
the rnnoise fallback runs and the host is told the truth.

Measured in a two-browser call (fan noise, SNR 15 dB): before, 4.9 dB of
noise removed, i.e. none beyond gain differences; after, 30.9 dB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
2026-10-30 14:18:01 -04:00
jared 117467b1fb Merge pull request 'chore(deps): security fixes for dev/build tooling (Storybook, Vitest, Vite, transitive)' (#63) from chore/dev-tool-security into lotus
CI / Build embedded bundle (push) Successful in 5m37s
CI / Publish to Gitea npm registry (push) Skipped
2026-10-25 23:59:03 -04:00
2 changed files with 74 additions and 4 deletions
+35
View File
@@ -11,6 +11,7 @@ import { type AudioProcessorOptions } from "livekit-client";
import {
assertModuleExport,
type LotusDenoiseConfig,
normalizeDfnModelBytes,
LotusDenoiseProcessor,
prepareDenoiseAssets,
releasePreparedDenoiseAssets,
@@ -245,3 +246,37 @@ describe("assertModuleExport (#26)", () => {
);
});
});
describe("normalizeDfnModelBytes", () => {
const tar = (): Uint8Array => {
const b = new Uint8Array(1024);
b.set(new TextEncoder().encode("ustar"), 257);
b.set(new TextEncoder().encode("model.onnx"), 0);
return b;
};
const gunzip = async (buf: ArrayBuffer): Promise<Uint8Array> =>
new Uint8Array(
await new Response(
new Response(buf).body!.pipeThrough(new DecompressionStream("gzip")),
).arrayBuffer(),
);
test("passes a gzipped model through untouched", async () => {
const gz = new Uint8Array([0x1f, 0x8b, 8, 0, 1, 2, 3]).buffer;
expect(await normalizeDfnModelBytes(gz)).toBe(gz);
});
test("re-gzips a tar that a Content-Encoding server already unpacked", async () => {
const out = await normalizeDfnModelBytes(tar().buffer as ArrayBuffer);
const u8 = new Uint8Array(out);
expect([u8[0], u8[1]]).toEqual([0x1f, 0x8b]);
expect(await gunzip(out)).toEqual(tar());
});
test("rejects anything else (e.g. an HTML error page)", async () => {
const html = new TextEncoder().encode("<!doctype html><title>404</title>");
await expect(
normalizeDfnModelBytes(html.buffer as ArrayBuffer),
).rejects.toThrow(/neither gzip nor tar/);
});
});
+39 -4
View File
@@ -144,6 +144,8 @@ interface DfnCore {
initialize: () => Promise<void>;
createAudioWorkletNode: (ctx: AudioContext) => Promise<AudioNode>;
destroy: () => void;
/** Set by `initialize()`; the model bytes are handed to the worklet as-is. */
assets?: { wasmModule: WebAssembly.Module; modelBytes: ArrayBuffer } | null;
}
interface DfnModule {
DeepFilterNet3Core: new (opts: {
@@ -167,6 +169,33 @@ export function assertModuleExport<T>(
return mod as T;
}
/**
* Make sure the DeepFilterNet model is the gzipped tarball its wasm expects.
*
* A server or proxy that sends the `.tar.gz` with `Content-Encoding: gzip`
* (vite preview does; some CDNs and nginx `gzip_static` setups do too) makes
* `fetch()` hand back the inner tar. The library's worklet then fails inside
* `df_create`, swallows the error and passes the raw mic straight through,
* while we report DeepFilterNet as active. An already-decompressed tar is
* re-gzipped; anything else throws, so the rnnoise fallback runs and the host
* is told the truth.
*/
export async function normalizeDfnModelBytes(
bytes: ArrayBuffer,
): Promise<ArrayBuffer> {
const u8 = new Uint8Array(bytes);
if (u8.length > 2 && u8[0] === 0x1f && u8[1] === 0x8b) return bytes;
const isTar =
u8.length > 262 &&
String.fromCharCode(...u8.subarray(257, 262)) === "ustar";
if (!isTar)
throw new Error(
`denoise: DeepFilterNet model is neither gzip nor tar (${u8.length} bytes)`,
);
const gz = new Response(u8).body!.pipeThrough(new CompressionStream("gzip"));
return new Response(gz).arrayBuffer();
}
async function loadDfnCore(config: LotusDenoiseConfig): Promise<DfnCore> {
const base = config.assetBase;
const url = `${base}deepfilternet/index.esm.js`;
@@ -178,13 +207,19 @@ async function loadDfnCore(config: LotusDenoiseConfig): Promise<DfnCore> {
);
const core = new mod.DeepFilterNet3Core({
sampleRate: 48_000,
// 60, not 80: full-strength suppression is the main source of the
// "over-processed" character; a lower level keeps voice natural while
// the dry/wet floor handles the noise tail.
noiseReductionLevel: 60,
// Attenuation limit in dB. At 60 the background is muted outright
// (measured -61 to -64 dB), so every word drops into dead silence and
// listeners hear the mic "cutting out" at word ends. 25 keeps a quiet
// background bed and scored best on room-echo speech with fan and
// keyboard noise (PESQ 2.72 / 2.38 vs 2.33 / 2.04 at 60).
noiseReductionLevel: 25,
assetConfig: { cdnUrl: dfnBase },
});
await core.initialize();
if (core.assets)
core.assets.modelBytes = await normalizeDfnModelBytes(
core.assets.modelBytes,
);
return core;
}