GiviMAD / whisper-jni

A JNI wrapper for using whisper.cpp, allows to transcribe speech to text in Java.
Apache License 2.0
90 stars 13 forks source link

No segments from result #22

Open AmogusAzul opened 5 months ago

AmogusAzul commented 5 months ago

Hello! I'm new in java, however I've used the og python's whisper. I'm trying to create a simple transcription program, but whenever i try to, i'm not getting any Segments, here's my code, anything wrong with it? ` public static String transcribe(short[] decodedSamples) throws IOException{

    float[] whisperSamples = reSample(decodedSamples);

    WhisperJNI.loadLibrary(); // load platform binaries
    WhisperJNI.setLibraryLogger(null); // capture/disable whisper.cpp log
    var whisper = new WhisperJNI();

    var ctx = whisper.init(Path.of(String.valueOf(QuiltLoader.getGameDir()), VoiceChatSubtitlesConfig.INSTANCE.model.value()));

    var params = new WhisperFullParams();
    params.detectLanguage = true;
    int result = whisper.full(ctx, params, whisperSamples, whisperSamples.length);
    if(result != 0) {
        throw new RuntimeException("Transcription failed with code " + result);
    }
    int numSegments = whisper.fullNSegments(ctx);
    String text = (numSegments > 0) ? whisper.fullGetSegmentText(ctx,0) : "No segments to display"; // I'm always getting the "No segments to display" response
    ctx.close(); // free native memory, should be called when we don't need the context anymore.
    return text;

}

`