-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Android and IOS #29
Comments
@thewh1teagle As long as you can successfully run iOS and Android after calling sherpa-rs under this framework, then you are basically successful. |
Thanks! I'm wondering how we actually provide a way first to call this library from java / flutter / swift / kotlin. For Android we might need to support:
Plus the For IOS:
|
By the way, sherpa-onnx also supports HarmonyOS from Huawei |
How can we use sherpa C API in Android / IOS? does sherpa-onnx have prebuilt |
yes, we use jni |
sherpa-onnx has always been there, I've run through both android and ios |
Some research I did, since I haven't worked with mobile, reveals that Android and iOS cannot directly use native libraries. Instead, Android requires a JNI wrapper library (which is native but wrapped), and iOS also requires a wrapper, though XCode can generate it automatically from a .dylib or .framework for Swift/ObjC. This means we need to expose a C API from sherpa-rs. However, this seems unnecessary since sherpa-onnx already does this. Instead, I think we should add an option to compile sherpa-rs with the precompiled or source code of sherpa-onnx for Android/iOS. The user can then write their own native wrapper for the specific use case. https://gist.github.com/thewh1teagle/794add8801e7c0923042ff877b179ee5 |
There's no need at all, there's no need to use java ffi and swift ffi to call the C APIs exposed by rust. |
Do you have/know some project that expose Rust to swift/java? Also we don't have currently C API exposed by Rust
There's no way to call Rust directly it needs to be exposed as C API (or maybe with some library that makes it easier) |
See in sherpa-onnx repo, there's complete folder just for JNI exposing |
jni is java's ffi 😅😅 |
I think the essence of making a rust wrapper is to output the ub behavior brought by C++, and provide safe rust code, rather than simply taking the c api and using it directly, so the sub-essence is still unsafe, so the necessity of exposing a c api is questionable. And the security package I wrote hasn't avoided some UB yet, I also need to modify it, add some lifecycle and encapsulation, and put an end to the UB behavior brought by the C API. |
1+ Would be great to compile for Android & IOS... I'm using Tauri to compile for Mac and Android - without sherpa-rs support I suppose I have to take the Webassembly route... ..not ideal |
JNI for Java and other platforms is not planned for sherpa-rs since sherpa-onnx already created JNI, |
By the way that's incorrect. You most have Java FFI / Swift FFI to call C libraries in mobile in most cases. |
Ah ! Excellent ! ..only just now got Tauri to compile with an embedded onnx + VAD processing a file... ..next is trying streaming audio...then try compile for Android... Excited now :) Thanks for the feedback. Much appreciated. |
|
could you post complete logs? |
@csukuangfj See below :) I'm definitely out of my comfort zone here so please just let me know if I missed something ? I use Tauri 2.0 - capturing audio in the webview and send that rust side to VAD process, works fine on Mac... ..but when I compile for Android it's a no go... `> tauri "info" [✔] Environment [-] Packages [-] Plugins [-] App `
warning: sherpa-rs-sys@0.5.1: Failed to download binaries. fallback to manual build. error: failed to run custom build command for Caused by: --- stderr CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool. command did not execute successfully, got: exit status: 1 build script failed, must exit now ` I then tried a bunch of things to make it build - it got messy fast - but I believe I made it use NDK / CMake etc - and I ultimately got this error...
Also tried to make it use the android binaries here ( with no luck )
Out of ideas :) Would be real annoying having to use webassembly in the webview haha painful 🗡️ |
Glad to hear you have managed to do that.
Please do the following to resolve it.
|
Once k2-fsa/sherpa-onnx#1634 resolved it will be easier and fast. |
Please refer to.the bash.scripts mentioned.in the previous comment. Just enable the option to build C API then your issue is fixed! |
The use of precompiled Sherpa C API libraries is helpful, as I'm trying to avoid building them myself or requiring others to do so. |
@csukuangfj All make sense...thanks for the guidance ! ..probably should wait for @thewh1teagle as I'm clearly messing up my build process trying to make it work :) ( need to learn more ) Amazing work on sherpa + rs thanks guys ..can't wait for this to work on Android !! |
I added support for Android and IOS (in main, didn't released yet) |
Is there an Android APK so that users can try it? |
I tested it with adb. Does it possible to load model from the memory? I have issues with the filesystem. |
Released v0.6.0 with Android and IOS support |
Currently, sherpa-rs supports Windows, Linux, and macOS.
It would be beneficial to add support for Android and iOS as well. At first glance, it seems feasible to link to prebuilt sherpa-onnx libraries. However, it's unclear whether we can easily cross-compile from any platform to any other, and whether Android should use jniLibs or if the approach is more similar to how Linux builds are handled.
The text was updated successfully, but these errors were encountered: