Skip to content

Add support for latest DPDFNet models and offline attenuation limit - #3824

Merged
csukuangfj merged 10 commits into
k2-fsa:masterfrom
danielr-ceva:dpdfnet_2
Aug 10, 2026
Merged

csukuangfj merged 10 commits into
k2-fsa:masterfrom
danielr-ceva:dpdfnet_2

Conversation

@danielr-ceva

@danielr-ceva danielr-ceva commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add support for the official DPDFNet model variants at 8, 16, and 48 kHz.
  • Extend the online denoiser’s accepted profiles for the new 8 and 48 kHz models.
  • Add the offline DPDFNet attenuation-limit feature.
  • Expose the attenuation limit through the CLI and supported language bindings.
  • Update DPDFNet examples and documentation.

Summary by CodeRabbit

  • New Features

    • Added configurable DPDFNet attenuation limiting for offline speech enhancement, with a default of 0 dB (disabled).
    • Expanded support and guidance for 8 kHz, 16 kHz, and 48 kHz DPDFNet models.
    • Added support for additional 8 kHz streaming model profiles.
  • Bug Fixes

    • Updated speech-enhancement examples across supported APIs to apply attenuation settings consistently.
    • Added configuration validation for attenuation values from 0 to 100 dB.

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The DPDFNet attenuation limit moved from the top-level offline denoiser configuration into the nested DPDFNet model configuration. Native processing, C/C++ and language bindings, WASM layouts, examples, CLI guidance, and model documentation were updated accordingly.

Changes

DPDFNet attenuation limit

Layer / File(s) Summary
Native configuration and attenuation processing
sherpa-onnx/csrc/offline-speech-denoiser-dpdfnet-*
Adds, validates, logs, and applies attenuation_limit_db while blending enhanced and noisy STFT data.
API and binding propagation
sherpa-onnx/c-api/*, sherpa-onnx/jni/*, sherpa-onnx/python/*, sherpa-onnx/rust/*, flutter/*, scripts/*, sherpa-onnx/java-api/*, sherpa-onnx/kotlin-api/*, sherpa-onnx/pascal-api/*
Moves the attenuation field into DPDFNet model configuration and updates native, FFI, and language binding propagation.
WASM configuration layout
wasm/speech-enhancement/*
Updates DPDFNet buffer sizing and field serialization, separates online configuration initialization, and updates size checks and logging.
Examples and model guidance
*-api-examples/*, python-api-examples/*, sherpa-onnx/csrc/sherpa-onnx-*-denoiser.cc, sherpa-onnx/c-api/docs/*
Updates examples to use nested attenuation configuration and expands DPDFNet model guidance for 8 kHz, 16 kHz, and 48 kHz variants.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant APIConfig
  participant NativeConfig
  participant DPDFNetImpl
  participant STFT
  APIConfig->>NativeConfig: set model.dpdfnet.attenuation_limit_db
  NativeConfig->>DPDFNetImpl: initialize attenuation_limit_db_
  DPDFNetImpl->>STFT: produce enhanced STFT
  DPDFNetImpl->>STFT: blend enhanced STFT with noisy STFT
Loading

Possibly related PRs

Suggested reviewers: csukuangfj

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main changes: new DPDFNet model support and the offline attenuation-limit feature.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@c-api-examples/speech-enhancement-dpdfnet-c-api.c`:
- Around line 20-30: Add the missing wget command for dpdfnet2_48khz_hr.onnx
alongside the existing 48 kHz model downloads in
c-api-examples/speech-enhancement-dpdfnet-c-api.c (lines 20-30) and
python-api-examples/offline-speech-enhancement-dpdfnet.py (lines 18-26), using
the same Hugging Face model location and preserving the existing download
instructions.

In `@sherpa-onnx/csrc/offline-speech-denoiser-dpdfnet-impl.h`:
- Around line 108-115: Update ApplyAttenuationLimit() to return a failure/broken
result when noisy and enhanced STFT shapes differ instead of calling
SHERPA_ONNX_EXIT(-1). Propagate that result through Run() so denoiser.Run()
reports failure without terminating the host process, while preserving the
existing successful attenuation path.

In `@sherpa-onnx/csrc/offline-speech-denoiser-dpdfnet-model-config.cc`:
- Around line 18-20: Update the CLI help text in the offline denoiser model
configuration to list the actual DPDFNet .onnx filenames, replacing the
shorthand baseline and model names with the filenames used elsewhere and keeping
the supported 16 kHz, 8 kHz, and 48 kHz variants consistent with the online
denoiser help.

In `@wasm/speech-enhancement/sherpa-onnx-speech-enhancement.js`:
- Around line 148-161: Update initSherpaOnnxOnlineSpeechDenoiserConfig to return
the allocation wrapper containing ptr, matching the shape expected by
freeConfig, rather than returning the modelConfig directly. Preserve the
existing model defaults and initialization flow.
- Around line 137-138: Update the Module.setValue call for
config.dpdfnetAttenuationLimitDb to use an undefined/null-only fallback rather
than truthiness, preserving NaN for native validation while still defaulting
missing values to 0.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9e72c305-aa3c-4d5c-bd48-ca09af3f9380

📥 Commits

Reviewing files that changed from the base of the PR and between 88bbc82 and 75546e4.

📒 Files selected for processing (41)
  • c-api-examples/speech-enhancement-dpdfnet-c-api.c
  • cxx-api-examples/speech-enhancement-dpdfnet-cxx-api.cc
  • dart-api-examples/speech-enhancement-dpdfnet/bin/speech_enhancement_dpdfnet.dart
  • dotnet-examples/speech-enhancement-dpdfnet/Program.cs
  • flutter/sherpa_onnx/lib/src/offline_speech_denoiser.dart
  • flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart
  • go-api-examples/speech-enhancement-dpdfnet/main.go
  • harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/non-streaming-speech-denoiser.cc
  • java-api-examples/NonStreamingSpeechEnhancementDpdfNet.java
  • kotlin-api-examples/test_offline_speech_denoiser_dpdfnet.kt
  • nodejs-addon-examples/test_offline_speech_enhancement_dpdfnet.js
  • nodejs-examples/test-offline-speech-enhancement-dpdfnet.js
  • pascal-api-examples/speech-enhancement-dpdfnet/dpdfnet.pas
  • python-api-examples/README.md
  • python-api-examples/offline-speech-enhancement-dpdfnet.py
  • rust-api-examples/examples/offline_speech_enhancement_dpdfnet.rs
  • scripts/dotnet/OfflineSpeechDenoiserConfig.cs
  • scripts/go/sherpa_onnx.go
  • scripts/node-addon-api/lib/types.js
  • sherpa-onnx/c-api/c-api.cc
  • sherpa-onnx/c-api/c-api.h
  • sherpa-onnx/c-api/cxx-api.cc
  • sherpa-onnx/c-api/cxx-api.h
  • sherpa-onnx/c-api/docs/speech-enhancement.dox
  • sherpa-onnx/csrc/offline-speech-denoiser-dpdfnet-impl.h
  • sherpa-onnx/csrc/offline-speech-denoiser-dpdfnet-model-config.cc
  • sherpa-onnx/csrc/offline-speech-denoiser.cc
  • sherpa-onnx/csrc/offline-speech-denoiser.h
  • sherpa-onnx/csrc/online-speech-denoiser-dpdfnet-impl.h
  • sherpa-onnx/csrc/sherpa-onnx-offline-denoiser.cc
  • sherpa-onnx/csrc/sherpa-onnx-online-denoiser.cc
  • sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineSpeechDenoiserConfig.java
  • sherpa-onnx/jni/speech-denoiser.cc
  • sherpa-onnx/kotlin-api/OfflineSpeechDenoiser.kt
  • sherpa-onnx/pascal-api/sherpa_onnx.pas
  • sherpa-onnx/python/csrc/offline-speech-denoiser.cc
  • sherpa-onnx/rust/sherpa-onnx-sys/src/speech_denoiser.rs
  • sherpa-onnx/rust/sherpa-onnx/src/offline_speech_denoiser.rs
  • swift-api-examples/speech-enhancement-dpdfnet.swift
  • wasm/speech-enhancement/sherpa-onnx-speech-enhancement.js
  • wasm/speech-enhancement/sherpa-onnx-wasm-main-speech-enhancement.cc

Comment thread c-api-examples/speech-enhancement-dpdfnet-c-api.c
Comment thread sherpa-onnx/csrc/offline-speech-denoiser-dpdfnet-impl.h
Comment thread sherpa-onnx/csrc/offline-speech-denoiser-dpdfnet-model-config.cc
Comment on lines +137 to +138
Module.setValue(
ptr + offset, config.dpdfnetAttenuationLimitDb || 0, 'float');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve NaN so native validation can reject it.

config.dpdfnetAttenuationLimitDb || 0 converts NaN to 0, silently bypassing native std::isnan rejection. Use an undefined/null fallback instead of truthiness for this numeric field.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@wasm/speech-enhancement/sherpa-onnx-speech-enhancement.js` around lines 137 -
138, Update the Module.setValue call for config.dpdfnetAttenuationLimitDb to use
an undefined/null-only fallback rather than truthiness, preserving NaN for
native validation while still defaulting missing values to 0.

Comment thread wasm/speech-enhancement/sherpa-onnx-speech-enhancement.js
Comment thread sherpa-onnx/c-api/c-api.cc Outdated
}

auto sd_config = GetOfflineSpeechDenoiserConfig(config);
if (!sd_config.Validate()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For harmonyOS, we don't validate it since model files can be in a sandbox. Please keep the original code.

return false;
}

if (dpdfnet_attenuation_limit_db > 0.0f &&

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reasonable range for it?
E.g., < 10? < 100? < 1000?

In C API, this value may be unintialized and the garbage value may be super large. We need to catch it here.

struct OfflineSpeechDenoiserConfig {
OfflineSpeechDenoiserModelConfig model;
// DPDFNet-only offline attenuation limit in dB. A value of 0 disables it.
float dpdfnet_attenuation_limit_db = 0.0f;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter is specific to dpdfnet. Can you move it to the struct OfflineSpeechDenoiserDpdfNetModelConfig?

I suggest that you use AI coding to do the change.

@danielr-ceva

Copy link
Copy Markdown
Contributor Author

@csukuangfj Addressed the comments: moved the attenuation limit into the DPDFNet-specific model config across all bindings, added validation for finite values above 100 dB, and preserved HarmonyOS sandbox behavior by skipping file validation there.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
c-api-examples/speech-enhancement-dpdfnet-c-api.c (1)

20-30: 📐 Maintainability & Code Quality | 🟡 Minor

Complete the 48 kHz model download instructions in both examples.

The documentation names dpdfnet2_48khz_hr.onnx without downloading it, while downloading only the dpdfnet8 48 kHz variant.

  • c-api-examples/speech-enhancement-dpdfnet-c-api.c#L20-L30: add the missing dpdfnet2_48khz_hr.onnx download command.
  • python-api-examples/offline-speech-enhancement-dpdfnet.py#L18-L26: add the same missing download command.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@c-api-examples/speech-enhancement-dpdfnet-c-api.c` around lines 20 - 30, Add
the missing dpdfnet2_48khz_hr.onnx download command beside the existing 48 kHz
dpdfnet8 download in c-api-examples/speech-enhancement-dpdfnet-c-api.c (lines
20-30) and python-api-examples/offline-speech-enhancement-dpdfnet.py (lines
18-26), matching each example’s existing download style.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@c-api-examples/speech-enhancement-dpdfnet-c-api.c`:
- Around line 20-30: Add the missing dpdfnet2_48khz_hr.onnx download command
beside the existing 48 kHz dpdfnet8 download in
c-api-examples/speech-enhancement-dpdfnet-c-api.c (lines 20-30) and
python-api-examples/offline-speech-enhancement-dpdfnet.py (lines 18-26),
matching each example’s existing download style.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fbc3e7ed-8ff3-44a0-9c92-564c0af54183

📥 Commits

Reviewing files that changed from the base of the PR and between fed9ee4 and 9f780b1.

📒 Files selected for processing (38)
  • c-api-examples/speech-enhancement-dpdfnet-c-api.c
  • cxx-api-examples/speech-enhancement-dpdfnet-cxx-api.cc
  • dart-api-examples/speech-enhancement-dpdfnet/bin/speech_enhancement_dpdfnet.dart
  • dotnet-examples/speech-enhancement-dpdfnet/Program.cs
  • flutter/sherpa_onnx/lib/src/offline_speech_denoiser.dart
  • flutter/sherpa_onnx/lib/src/sherpa_onnx_bindings.dart
  • go-api-examples/speech-enhancement-dpdfnet/main.go
  • harmony-os/SherpaOnnxHar/sherpa_onnx/src/main/cpp/speech-denoiser.h
  • java-api-examples/NonStreamingSpeechEnhancementDpdfNet.java
  • kotlin-api-examples/test_offline_speech_denoiser_dpdfnet.kt
  • nodejs-addon-examples/test_offline_speech_enhancement_dpdfnet.js
  • nodejs-examples/test-offline-speech-enhancement-dpdfnet.js
  • pascal-api-examples/speech-enhancement-dpdfnet/dpdfnet.pas
  • python-api-examples/offline-speech-enhancement-dpdfnet.py
  • rust-api-examples/examples/offline_speech_enhancement_dpdfnet.rs
  • rust-api-examples/examples/streaming_speech_enhancement_dpdfnet.rs
  • scripts/dotnet/OfflineSpeechDenoiserDpdfNetModelConfig.cs
  • scripts/go/sherpa_onnx.go
  • scripts/node-addon-api/lib/types.js
  • sherpa-onnx/c-api/c-api.cc
  • sherpa-onnx/c-api/c-api.h
  • sherpa-onnx/c-api/cxx-api.cc
  • sherpa-onnx/c-api/cxx-api.h
  • sherpa-onnx/c-api/docs/speech-enhancement.dox
  • sherpa-onnx/csrc/offline-speech-denoiser-dpdfnet-impl.h
  • sherpa-onnx/csrc/offline-speech-denoiser-dpdfnet-model-config.cc
  • sherpa-onnx/csrc/offline-speech-denoiser-dpdfnet-model-config.h
  • sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/OfflineSpeechDenoiserDpdfNetModelConfig.java
  • sherpa-onnx/jni/speech-denoiser.cc
  • sherpa-onnx/kotlin-api/OfflineSpeechDenoiser.kt
  • sherpa-onnx/pascal-api/sherpa_onnx.pas
  • sherpa-onnx/python/csrc/offline-speech-denoiser-dpdfnet-model-config.cc
  • sherpa-onnx/python/csrc/offline-speech-denoiser.cc
  • sherpa-onnx/rust/sherpa-onnx-sys/src/speech_denoiser.rs
  • sherpa-onnx/rust/sherpa-onnx/src/offline_speech_denoiser.rs
  • swift-api-examples/speech-enhancement-dpdfnet.swift
  • wasm/speech-enhancement/sherpa-onnx-speech-enhancement.js
  • wasm/speech-enhancement/sherpa-onnx-wasm-main-speech-enhancement.cc
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/node-addon-api/lib/types.js

@csukuangfj

Copy link
Copy Markdown
Collaborator

Can you fix the CI errors for swift?

@danielr-ceva

Copy link
Copy Markdown
Contributor Author

@csukuangfj, the errors have been fixed.

@csukuangfj csukuangfj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you first rebase or merge the master branch into your current branch dpdfnet_2 to make it easier for review the changes?

@csukuangfj

Copy link
Copy Markdown
Collaborator

By the way, you can ignore CI errors not related to your PR.

@csukuangfj csukuangfj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

@csukuangfj
csukuangfj merged commit 42a2b68 into k2-fsa:master Aug 10, 2026
48 of 50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants