Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
snakers4
GitHub Repository: snakers4/silero-vad
Path: blob/master/examples/java-wav-file-example/src/main/java/org/example/App.java
1171 views
1
package org.example;
2
3
import ai.onnxruntime.OrtException;
4
import java.io.File;
5
import java.util.List;
6
7
public class App {
8
9
private static final String MODEL_PATH = "/path/silero_vad.onnx";
10
private static final String EXAMPLE_WAV_FILE = "/path/example.wav";
11
private static final int SAMPLE_RATE = 16000;
12
private static final float THRESHOLD = 0.5f;
13
private static final int MIN_SPEECH_DURATION_MS = 250;
14
private static final float MAX_SPEECH_DURATION_SECONDS = Float.POSITIVE_INFINITY;
15
private static final int MIN_SILENCE_DURATION_MS = 100;
16
private static final int SPEECH_PAD_MS = 30;
17
18
public static void main(String[] args) {
19
// Initialize the Voice Activity Detector
20
SileroVadDetector vadDetector;
21
try {
22
vadDetector = new SileroVadDetector(MODEL_PATH, THRESHOLD, SAMPLE_RATE,
23
MIN_SPEECH_DURATION_MS, MAX_SPEECH_DURATION_SECONDS, MIN_SILENCE_DURATION_MS, SPEECH_PAD_MS);
24
fromWavFile(vadDetector, new File(EXAMPLE_WAV_FILE));
25
} catch (OrtException e) {
26
System.err.println("Error initializing the VAD detector: " + e.getMessage());
27
}
28
}
29
30
public static void fromWavFile(SileroVadDetector vadDetector, File wavFile) {
31
List<SileroSpeechSegment> speechTimeList = vadDetector.getSpeechSegmentList(wavFile);
32
for (SileroSpeechSegment speechSegment : speechTimeList) {
33
System.out.println(String.format("start second: %f, end second: %f",
34
speechSegment.getStartSecond(), speechSegment.getEndSecond()));
35
}
36
}
37
}
38
39