OfflineSpeechDenoiser.java
972 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2025 Xiaomi Corporation
package com.k2fsa.sherpa.onnx;
public class OfflineSpeechDenoiser {
static {
System.loadLibrary("sherpa-onnx-jni");
}
private long ptr = 0;
public OfflineSpeechDenoiser(OfflineSpeechDenoiserConfig config) {
ptr = newFromFile(config);
}
public int getSampleRate() {
return getSampleRate(ptr);
}
public DenoisedAudio run(float[] samples, int sampleRate) {
return run(ptr, samples, sampleRate);
}
protected void finalize() throws Throwable {
release();
}
public void release() {
if (this.ptr == 0) {
return;
}
delete(this.ptr);
this.ptr = 0;
}
private native void delete(long ptr);
private native int getSampleRate(long ptr);
private native DenoisedAudio run(long ptr, float[] samples, int sampleRate);
private native long newFromFile(OfflineSpeechDenoiserConfig config);
}