@@ -23,26 +23,42 @@ import io.github.ggerganov.whispercpp.WhisperCpp;
23
23
public class Example {
24
24
25
25
public static void main (String [] args ) {
26
+
26
27
WhisperCpp whisper = new WhisperCpp ();
27
- // By default, models are loaded from ~/.cache/whisper/ and are usually named "ggml-${name}.bin"
28
- // or you can provide the absolute path to the model file.
29
- long context = whisper. initContext(" base.en" );
30
28
try {
31
- var whisperParams = whisper. getFullDefaultParams(WhisperSamplingStrategy . WHISPER_SAMPLING_GREEDY );
32
- // custom configuration if required
33
- whisperParams. temperature_inc = 0f ;
34
-
35
- var samples = readAudio(); // divide each value by 32767.0f
36
- whisper. fullTranscribe(whisperParams, samples);
37
-
38
- int segmentCount = whisper. getTextSegmentCount(context);
39
- for (int i = 0 ; i < segmentCount; i++ ) {
40
- String text = whisper. getTextSegment(context, i);
41
- System . out. println(segment. getText());
29
+ // By default, models are loaded from ~/.cache/whisper/ and are usually named "ggml-${name}.bin"
30
+ // or you can provide the absolute path to the model file.
31
+ whisper. initContext(" ../ggml-base.en.bin" );
32
+ WhisperFullParams . ByValue whisperParams = whisper. getFullDefaultParams(WhisperSamplingStrategy . WHISPER_SAMPLING_BEAM_SEARCH );
33
+
34
+ // custom configuration if required
35
+ // whisperParams.n_threads = 8;
36
+ whisperParams. temperature = 0.0f ;
37
+ whisperParams. temperature_inc = 0.2f ;
38
+ // whisperParams.language = "en";
39
+
40
+ float [] samples = readAudio(); // divide each value by 32767.0f
41
+ List<WhisperSegment > whisperSegmentList = whisper. fullTranscribeWithTime(whisperParams, samples);
42
+
43
+ for (WhisperSegment whisperSegment : whisperSegmentList) {
44
+
45
+ long start = whisperSegment. getStart();
46
+ long end = whisperSegment. getEnd();
47
+
48
+ String text = whisperSegment. getSentence();
49
+
50
+ System . out. println(" start: " + start);
51
+ System . out. println(" end: " + end);
52
+ System . out. println(" text: " + text);
53
+
42
54
}
55
+
56
+ } catch (IOException e) {
57
+ e. printStackTrace();
43
58
} finally {
44
- whisper. freeContext(context );
59
+ whisper. close( );
45
60
}
61
+
46
62
}
47
63
}
48
64
```
0 commit comments