Spaces:
Running
Running
Joas Dev
commited on
bindings.java : update java example (#3281)
Browse filesThis commit updates the example in the README.md file as the current Java example code is not working.
Resolves: https://github.com/ggml-org/whisper.cpp/issues/2860
- bindings/java/README.md +31 -15
bindings/java/README.md
CHANGED
|
@@ -23,26 +23,42 @@ import io.github.ggerganov.whispercpp.WhisperCpp;
|
|
| 23 |
public class Example {
|
| 24 |
|
| 25 |
public static void main(String[] args) {
|
|
|
|
| 26 |
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 |
try {
|
| 31 |
-
|
| 32 |
-
//
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
}
|
|
|
|
|
|
|
|
|
|
| 43 |
} finally {
|
| 44 |
-
|
| 45 |
}
|
|
|
|
| 46 |
}
|
| 47 |
}
|
| 48 |
```
|
|
|
|
| 23 |
public class Example {
|
| 24 |
|
| 25 |
public static void main(String[] args) {
|
| 26 |
+
|
| 27 |
WhisperCpp whisper = new WhisperCpp();
|
|
|
|
|
|
|
|
|
|
| 28 |
try {
|
| 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 |
+
|
| 54 |
}
|
| 55 |
+
|
| 56 |
+
} catch (IOException e) {
|
| 57 |
+
e.printStackTrace();
|
| 58 |
} finally {
|
| 59 |
+
whisper.close();
|
| 60 |
}
|
| 61 |
+
|
| 62 |
}
|
| 63 |
}
|
| 64 |
```
|