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

How to hide the output of the model load? #11

Closed elloza closed 10 months ago

elloza commented 10 months ago

I am using the library and have set the parameters it offers to false:

params.printTimestamps = false;
params.language = "es";
params.printProgress = false;
params.printTimestamps = false;

However, at the end of the program, I get the model load by the output:

Thanks in advance,

whisper_init_from_file_no_state: loading model from 'C:\ggml-small.bin'
whisper_model_load: loading model
whisper_model_load: n_vocab       = 51865
whisper_model_load: n_audio_ctx   = 1500
whisper_model_load: n_audio_state = 768
whisper_model_load: n_audio_head  = 12
whisper_model_load: n_audio_layer = 12
whisper_model_load: n_text_ctx    = 448
whisper_model_load: n_text_state  = 768
whisper_model_load: n_text_head   = 12
whisper_model_load: n_text_layer  = 12
whisper_model_load: n_mels        = 80
whisper_model_load: ftype         = 1
whisper_model_load: qntvr         = 0
whisper_model_load: type          = 3
whisper_model_load: mem required  =  743.00 MB (+   16.00 MB per decoder)
whisper_model_load: adding 1608 extra tokens
whisper_model_load: model ctx     =  464.68 MB
whisper_model_load: model size    =  464.44 MB
whisper_init_state: kv self size  =   15.75 MB
whisper_init_state: kv cross size =   52.73 MB

Would it be possible to hide this in some way?

Thank you very much in advance.

GiviMAD commented 10 months ago

The library send those logs by default to the stderr, but looking at it seems it is prepared to overwrite the logger, so it should be possible to send those to the Java code instead, so those can be ignored or printed as a debug log.

Thank you for raising the issue. Is it urgent? If not I'll add the change on the next whisper.cpp release.

elloza commented 10 months ago

Thank you very much for your quick reply!

Yes... I was afraid of that, I didn't want to have to hide the output in cpp, that's why I was asking.

It's not urgent, I wanted to use it for my Java students in an exercise and that's why I wanted to hide any output they might find strange.

In any case it would be perfect if there was an option to mute it in future versions.

Congratulations for the work done.

GiviMAD commented 10 months ago

In the end I did it during the morning. I need to check if I'm missing anything else but it will be available tonight or tomorrow.

// after the loadLibrary call
WhisperJNI.setLibraryLogger(null);
elloza commented 10 months ago

Thank you very much! You have saved me so much time! I'll try it as soon as you have it!

Thanks again!

elloza commented 10 months ago

Thank you for the build!!

I'm getting this error, maybe there is other initialiation now.. or just a little bug.

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.util.function.Consumer.accept(Object)" because "options.logger" is null
    at io.github.givimad.whisperjni.internal.LibraryUtils.loadLibrary(LibraryUtils.java:116)
    at io.github.givimad.whisperjni.WhisperJNI.loadLibrary(WhisperJNI.java:317)
    at io.github.givimad.whisperjni.WhisperJNI.loadLibrary(WhisperJNI.java:301)
    at javaapplication5.JavaApplication5.main(JavaApplication5.java:108)

Thanks!

GiviMAD commented 10 months ago

Thank you! It's a bug. You can set it to a noop as a workaround.

var options = new LoadOptions();
options.logger = (String ignored) -> { };
WhisperJNI.loadLibrary(options);

But I'll deploy a fix in a moment.

Edit: That logger only output the binary load process (which binary is extracted and used).

GiviMAD commented 10 months ago

Should be fixed in the 1.4.3-1 version. If you can give me a thumbs up it will be nice, I've been testing these latest changes on macOS and Linux but the null pointer exception was on the windows part of the library registration method.

elloza commented 10 months ago

I just tried the latest one you uploaded whisper-jni-1.4.3-2.jar and it works like a charm.

I'll try it this afternoon on macOS and on Ubuntu.

Thanks a lot!