mirror of
https://github.com/k2-fsa/sherpa-onnx.git
synced 2026-11-10 21:11:03 +08:00
Add DPDFNet speech denoiser support for offline and streaming (#3276)
This pull request enhances the speech processing capabilities of sherpa-onnx by integrating DPDFNet models for speech enhancement. It introduces both offline and streaming denoising functionalities, supporting various model profiles and sample rates. This expansion provides users with more advanced and flexible options for improving audio quality in diverse applications, from real-time communication to post-processing of recordings.
This commit is contained in:
1 parent
e68746e6ce
commit
807c496f4c
82 files changed
+2933
-85
No files matched your search
@@ -0,0 +1,41 @@
|
||||
// Copyright 2025 Xiaomi Corporation
|
||||
|
||||
// This file shows how to use DPDFNet speech enhancement models in sherpa-onnx
|
||||
//
|
||||
// Download DPDFNet models from the official Hugging Face hub:
|
||||
// https://huggingface.co/Ceva-IP/DPDFNet
|
||||
//
|
||||
// Use baseline.onnx, dpdfnet2.onnx, dpdfnet4.onnx, or dpdfnet8.onnx
|
||||
// for 16 kHz downstream ASR or speech recognition.
|
||||
// Use dpdfnet2_48khz_hr.onnx for 48 kHz enhancement output.
|
||||
|
||||
import com.k2fsa.sherpa.onnx.*;
|
||||
|
||||
public class NonStreamingSpeechEnhancementDpdfNet {
|
||||
public static void main(String[] args) {
|
||||
String model = "./dpdfnet2.onnx";
|
||||
OfflineSpeechDenoiserModelConfig.Builder builder =
|
||||
OfflineSpeechDenoiserModelConfig.builder()
|
||||
.setNumThreads(1)
|
||||
.setDebug(true)
|
||||
.setProvider("cpu")
|
||||
.setDpdfnet(
|
||||
OfflineSpeechDenoiserDpdfNetModelConfig.builder().setModel(model).build());
|
||||
|
||||
OfflineSpeechDenoiserModelConfig modelConfig = builder.build();
|
||||
OfflineSpeechDenoiserConfig config =
|
||||
OfflineSpeechDenoiserConfig.builder().setModel(modelConfig).build();
|
||||
|
||||
OfflineSpeechDenoiser speech_denoiser = new OfflineSpeechDenoiser(config);
|
||||
|
||||
String testWaveFilename = "./inp_16k.wav";
|
||||
WaveReader reader = new WaveReader(testWaveFilename);
|
||||
|
||||
DenoisedAudio denoised = speech_denoiser.run(reader.getSamples(), reader.getSampleRate());
|
||||
String outFilename = "enhanced.wav";
|
||||
WaveWriter.write(outFilename, denoised.getSamples(), denoised.getSampleRate());
|
||||
System.out.printf("Saved to %s\n", outFilename);
|
||||
|
||||
speech_denoiser.release();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
// This file shows how to use speech enhancement models in sherpa-onnx
|
||||
//
|
||||
// please download files in this script from
|
||||
// Download GTCRN models and sample test waves from:
|
||||
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/speech-enhancement-models
|
||||
|
||||
import com.k2fsa.sherpa.onnx.*;
|
||||
@@ -10,16 +10,15 @@ import com.k2fsa.sherpa.onnx.*;
|
||||
public class NonStreamingSpeechEnhancementGtcrn {
|
||||
public static void main(String[] args) {
|
||||
String model = "./gtcrn_simple.onnx";
|
||||
OfflineSpeechDenoiserGtcrnModelConfig gtcrn =
|
||||
OfflineSpeechDenoiserGtcrnModelConfig.builder().setModel(model).build();
|
||||
|
||||
OfflineSpeechDenoiserModelConfig modelConfig =
|
||||
OfflineSpeechDenoiserModelConfig.Builder builder =
|
||||
OfflineSpeechDenoiserModelConfig.builder()
|
||||
.setGtcrn(gtcrn)
|
||||
.setNumThreads(1)
|
||||
.setDebug(true)
|
||||
.setProvider("cpu")
|
||||
.build();
|
||||
.setProvider("cpu");
|
||||
|
||||
builder.setGtcrn(OfflineSpeechDenoiserGtcrnModelConfig.builder().setModel(model).build());
|
||||
|
||||
OfflineSpeechDenoiserModelConfig modelConfig = builder.build();
|
||||
OfflineSpeechDenoiserConfig config =
|
||||
OfflineSpeechDenoiserConfig.builder().setModel(modelConfig).build();
|
||||
|
||||
@@ -28,8 +27,8 @@ public class NonStreamingSpeechEnhancementGtcrn {
|
||||
String testWaveFilename = "./inp_16k.wav";
|
||||
WaveReader reader = new WaveReader(testWaveFilename);
|
||||
|
||||
DenoisedAudio denoised = speechDenoiser.run(reader.getSamples(), reader.getSampleRate());
|
||||
String outFilename = "enhanced-16k.wav";
|
||||
DenoisedAudio denoised = speech_denoiser.run(reader.getSamples(), reader.getSampleRate());
|
||||
String outFilename = "enhanced.wav";
|
||||
WaveWriter.write(outFilename, denoised.getSamples(), denoised.getSampleRate());
|
||||
System.out.printf("Saved to %s\n", outFilename);
|
||||
|
||||
|
||||
@@ -4,6 +4,17 @@ This directory contains examples for the JAVA API of sherpa-onnx.
|
||||
|
||||
# Usage
|
||||
|
||||
## Non-streaming speech enhancement
|
||||
|
||||
```bash
|
||||
./run-non-streaming-speech-enhancement-gtcrn.sh
|
||||
```
|
||||
|
||||
The example file keeps the historical `Gtcrn` name, but the same offline
|
||||
speech denoiser API also supports DPDFNet. Use 16 kHz DPDFNet models such as
|
||||
`baseline.onnx`, `dpdfnet2.onnx`, `dpdfnet4.onnx`, or `dpdfnet8.onnx` for
|
||||
downstream ASR and `dpdfnet2_48khz_hr.onnx` for 48 kHz enhancement output.
|
||||
|
||||
## Non-streaming speaker diarization
|
||||
|
||||
```bash
|
||||
|
||||
Reference in new issue
Block a user