GiviMAD / whisper-jni

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

NoSuchMethodError: No static method readString in Android Studio with Java #19

Open jejj1206 opened 9 months ago

jejj1206 commented 9 months ago

When I try to use the bindings in Android Studio with Java, I get the following error:

java.lang.NoSuchMethodError: No static method readString(Ljava/nio/file/Path;)Ljava/lang/String; in class Ljava/nio/file/Files; or its super classes (declaration of 'java.nio.file.Files' appears in /apex/com.android.art/javalib/core-oj.jar)
                                                                                                        at io.github.givimad.whisperjni.internal.LibraryUtils.loadLibrary(LibraryUtils.java:136)
                                                                                                        at io.github.givimad.whisperjni.WhisperJNI.loadLibrary(WhisperJNI.java:384)
                                                                                                        at com.example.myapplication.MainActivity.onCreate(MainActivity.java:235)
                                                                                                        at android.app.Activity.performCreate(Activity.java:8595)
                                                                                                        at android.app.Activity.performCreate(Activity.java:8573)
                                                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1456)
                                                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3764)
                                                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3922)
                                                                                                        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
                                                                                                        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
                                                                                                        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:205)
                                                                                                        at android.os.Looper.loop(Looper.java:294)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:8177)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

Does anyone know how to solve this issue?

Below is my code:

WhisperJNI.LoadOptions loadOptions = new WhisperJNI.LoadOptions();
// Provide path to libwhisper so/dylib file.
loadOptions.whisperLib = libsDir.resolve("libwhisper.so");
// register the library
WhisperJNI.loadLibrary(loadOptions);
WhisperJNI.setLibraryLogger(null); // capture/disable whisper.cpp log
WhisperJNI whisper = new WhisperJNI();
WhisperContext ctx = whisper.init(modelsDir.resolve("ggml-tiny.bin"));
WhisperFullParams params = new WhisperFullParams();
float[] samples = decodeWaveFile(outputPath.resolve("out.wav").toFile());
int result = whisper.full(ctx, params, samples, samples.length);
purgeme commented 3 months ago

Hey, did you resolve this issue or find a workaround ? I am facing the same problem