Writing Java code wrapers

Hello everyone.
I'm going to write my first test Rust project and I would like to use CMU Sphinx that is written in Java, Is there some way to use Java libraries in Rust code?

My quick search didn't give me anything useful, so I don't know the long answer, but the short answer is: if you can find/make a C friendly interface between Sphinx and your Rust program. See the FFI section in The Book. You may find it easier to call Rust from Java instead (example).

1 Like

You're definitely better off starting the program with Java and then using JNI to call into a Rust extern "C" API. Although at that point, you should probably just write the whole thing in Java because JNI is a nightmare.

It looks like PocketSphinx is a slimmed down version of CMUSphinx with a C API. You could call into that directly from Rust and avoid Java altogether.