From 269dad68a2442295c6b2cc951c8f33b466e39e22 Mon Sep 17 00:00:00 2001 From: Joas Dev <37047923+Jo4sDev@users.noreply.github.com> Date: Mon, 2 Jun 2025 23:15:21 -0500 Subject: [PATCH] bindings.java : apply whisperParams in fullTranscribeWithTime instead of ignoring them (#3201) This 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. --- .../github/ggerganov/whispercpp/WhisperCpp.java | 17 ++++++++++------- .../ggerganov/whispercpp/WhisperCppTest.java | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/bindings/java/src/main/java/io/github/ggerganov/whispercpp/WhisperCpp.java b/bindings/java/src/main/java/io/github/ggerganov/whispercpp/WhisperCpp.java index 621d8c63..cc531482 100644 --- a/bindings/java/src/main/java/io/github/ggerganov/whispercpp/WhisperCpp.java +++ b/bindings/java/src/main/java/io/github/ggerganov/whispercpp/WhisperCpp.java @@ -168,23 +168,26 @@ public class WhisperCpp implements AutoCloseable { return str.toString().trim(); } - public List fullTranscribeWithTime(WhisperFullParams whisperParams, float[] audioData) throws IOException { + /** + * Full transcribe with time list. + * + * @param whisperParams the whisper params + * @param audioData the audio data + * @return the list + * @throws IOException the io exception + */ + public List fullTranscribeWithTime(WhisperFullParams.ByValue whisperParams, float[] audioData) throws IOException { if (ctx == null) { throw new IllegalStateException("Model not initialised"); } - WhisperFullParams.ByValue valueParams = new WhisperFullParams.ByValue( - lib.whisper_full_default_params_by_ref(WhisperSamplingStrategy.WHISPER_SAMPLING_BEAM_SEARCH.ordinal())); - valueParams.read(); - - if (lib.whisper_full(ctx, valueParams, audioData, audioData.length) != 0) { + if (lib.whisper_full(ctx, whisperParams, audioData, audioData.length) != 0) { throw new IOException("Failed to process audio"); } int nSegments = lib.whisper_full_n_segments(ctx); List segments= new ArrayList<>(nSegments); - for (int i = 0; i < nSegments; i++) { long t0 = lib.whisper_full_get_segment_t0(ctx, i); String text = lib.whisper_full_get_segment_text(ctx, i); diff --git a/bindings/java/src/test/java/io/github/ggerganov/whispercpp/WhisperCppTest.java b/bindings/java/src/test/java/io/github/ggerganov/whispercpp/WhisperCppTest.java index 9d63fff3..bf37e519 100644 --- a/bindings/java/src/test/java/io/github/ggerganov/whispercpp/WhisperCppTest.java +++ b/bindings/java/src/test/java/io/github/ggerganov/whispercpp/WhisperCppTest.java @@ -118,7 +118,7 @@ class WhisperCppTest { float[] floats = new float[b.length / 2]; //WhisperFullParams params = whisper.getFullDefaultParams(WhisperSamplingStrategy.WHISPER_SAMPLING_GREEDY); - WhisperFullParams params = whisper.getFullDefaultParams(WhisperSamplingStrategy.WHISPER_SAMPLING_BEAM_SEARCH); + WhisperFullParams.ByValue params = whisper.getFullDefaultParams(WhisperSamplingStrategy.WHISPER_SAMPLING_BEAM_SEARCH); params.setProgressCallback((ctx, state, progress, user_data) -> System.out.println("progress: " + progress)); params.print_progress = CBool.FALSE; //params.initial_prompt = "and so my fellow Americans um, like";