Spaces:
Running
Running
Joas Dev
commited on
bindings.java : apply whisperParams in fullTranscribeWithTime instead of ignoring them (#3201)
Browse filesThis pull request fixes a bug in the fullTranscribeWithTime method, where the whisperParams argument was declared but never used. As a result, the model did not apply the configuration defined in whisperParams.
bindings/java/src/main/java/io/github/ggerganov/whispercpp/WhisperCpp.java
CHANGED
|
@@ -168,23 +168,26 @@ public class WhisperCpp implements AutoCloseable {
|
|
| 168 |
return str.toString().trim();
|
| 169 |
}
|
| 170 |
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
if (ctx == null) {
|
| 173 |
throw new IllegalStateException("Model not initialised");
|
| 174 |
}
|
| 175 |
|
| 176 |
-
|
| 177 |
-
lib.whisper_full_default_params_by_ref(WhisperSamplingStrategy.WHISPER_SAMPLING_BEAM_SEARCH.ordinal()));
|
| 178 |
-
valueParams.read();
|
| 179 |
-
|
| 180 |
-
if (lib.whisper_full(ctx, valueParams, audioData, audioData.length) != 0) {
|
| 181 |
throw new IOException("Failed to process audio");
|
| 182 |
}
|
| 183 |
|
| 184 |
int nSegments = lib.whisper_full_n_segments(ctx);
|
| 185 |
List<WhisperSegment> segments= new ArrayList<>(nSegments);
|
| 186 |
|
| 187 |
-
|
| 188 |
for (int i = 0; i < nSegments; i++) {
|
| 189 |
long t0 = lib.whisper_full_get_segment_t0(ctx, i);
|
| 190 |
String text = lib.whisper_full_get_segment_text(ctx, i);
|
|
|
|
| 168 |
return str.toString().trim();
|
| 169 |
}
|
| 170 |
|
| 171 |
+
/**
|
| 172 |
+
* Full transcribe with time list.
|
| 173 |
+
*
|
| 174 |
+
* @param whisperParams the whisper params
|
| 175 |
+
* @param audioData the audio data
|
| 176 |
+
* @return the list
|
| 177 |
+
* @throws IOException the io exception
|
| 178 |
+
*/
|
| 179 |
+
public List<WhisperSegment> fullTranscribeWithTime(WhisperFullParams.ByValue whisperParams, float[] audioData) throws IOException {
|
| 180 |
if (ctx == null) {
|
| 181 |
throw new IllegalStateException("Model not initialised");
|
| 182 |
}
|
| 183 |
|
| 184 |
+
if (lib.whisper_full(ctx, whisperParams, audioData, audioData.length) != 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
throw new IOException("Failed to process audio");
|
| 186 |
}
|
| 187 |
|
| 188 |
int nSegments = lib.whisper_full_n_segments(ctx);
|
| 189 |
List<WhisperSegment> segments= new ArrayList<>(nSegments);
|
| 190 |
|
|
|
|
| 191 |
for (int i = 0; i < nSegments; i++) {
|
| 192 |
long t0 = lib.whisper_full_get_segment_t0(ctx, i);
|
| 193 |
String text = lib.whisper_full_get_segment_text(ctx, i);
|
bindings/java/src/test/java/io/github/ggerganov/whispercpp/WhisperCppTest.java
CHANGED
|
@@ -118,7 +118,7 @@ class WhisperCppTest {
|
|
| 118 |
float[] floats = new float[b.length / 2];
|
| 119 |
|
| 120 |
//WhisperFullParams params = whisper.getFullDefaultParams(WhisperSamplingStrategy.WHISPER_SAMPLING_GREEDY);
|
| 121 |
-
WhisperFullParams params = whisper.getFullDefaultParams(WhisperSamplingStrategy.WHISPER_SAMPLING_BEAM_SEARCH);
|
| 122 |
params.setProgressCallback((ctx, state, progress, user_data) -> System.out.println("progress: " + progress));
|
| 123 |
params.print_progress = CBool.FALSE;
|
| 124 |
//params.initial_prompt = "and so my fellow Americans um, like";
|
|
|
|
| 118 |
float[] floats = new float[b.length / 2];
|
| 119 |
|
| 120 |
//WhisperFullParams params = whisper.getFullDefaultParams(WhisperSamplingStrategy.WHISPER_SAMPLING_GREEDY);
|
| 121 |
+
WhisperFullParams.ByValue params = whisper.getFullDefaultParams(WhisperSamplingStrategy.WHISPER_SAMPLING_BEAM_SEARCH);
|
| 122 |
params.setProgressCallback((ctx, state, progress, user_data) -> System.out.println("progress: " + progress));
|
| 123 |
params.print_progress = CBool.FALSE;
|
| 124 |
//params.initial_prompt = "and so my fellow Americans um, like";
|