k2-fsa / sherpa-onnx

Speech-to-text, text-to-speech, speaker recognition, and VAD using next-gen Kaldi with onnxruntime without Internet connection. Support embedded systems, Android, iOS, Raspberry Pi, RISC-V, x86_64 servers, websocket server/client, C/C++, Python, Kotlin, C#, Go, NodeJS, Java, Swift, Dart, JavaScript, Flutter, Object Pascal, Lazarus, Rust
https://k2-fsa.github.io/sherpa/onnx/index.html
Apache License 2.0
3.11k stars 362 forks source link

Is org.k2fsa.sherpa.onnx v1.10.17 supporting Android Xamarin? #1241

Open EvanParallax opened 1 month ago

EvanParallax commented 1 month ago

Hi there!

I'm trying to embed sherpa in an android application using c# xamarin. org.k2fsa.sherpa.onnx v1.10.17 package works well on windows and linux. On Android there is a problem with creating OnlineRecognizer. While importing libsherpa-onnx-c-api.so I am getting DllNotFoundException. Using dlimport and dlerror, I found out that the error was in importing the transitive dependency libpthread.so.0. As far as I know there is no libpthread.so.0 in android, hence this libsherpa-onnx-c-api.so is not android oriented. dlerror output - "dlopen failed: library "libpthread.so.0" not found: needed by /data/app/~~roWPFky3a7zFKDoAAw0VVA==/Dictation.Client-m1pLIjGpo753L8FT3uZF5Q==/lib/x86_64/libsherpa-onnx-c-api .so in namespace clns-6" I tried to write a minimal application in flutter - it works. I took libsherpa-onnx-c-api.so from this build and linked it to my project, but it didn't work. Will org.k2fsa.sherpa.onnx package support xamarin in the future? Can you give instructions on how to link the required libsherpa-onnx-c-api.so assembly when building the nuget-package for xamarin from sources?

csukuangfj commented 1 month ago

please find our sherpa_onnx package on pub.dev for flutter.

csukuangfj commented 3 weeks ago

I tried to write a minimal application in flutter - it works. I took libsherpa-onnx-c-api.so from this build and linked it to my project, but it didn't work.

Please describe this step in detail

Also, please post all of the error logs

EvanParallax commented 3 weeks ago

hello! here steps: 1) Build working flutter example from your repo and extract libsherpa-onnx-c-api.so from the build 2) Link extracted libsherpa-onnx-c-api.so to c# xamarin app 3) Call OnlineRecognizer's constructor in runtime 4) OnlineRecognizer's constructor throws managed c# exception DllNotFoundEception.

But real error examined via dlimport/dlerror is "dlopen failed: library "libpthread.so.0" not found: needed by /data/app/~~roWPFky3a7zFKDoAAw0VVA==/Dictation.Client-m1pLIjGpo753L8FT3uZF5Q==/lib/x86_64/libsherpa-onnx-c-api .so in namespace clns-6". So it can't import libsherpa-onnx-c-api .so because of importing transitive dependency "libpthread.so.0". dlerror output and c# exception stacktrace are all my error logs (: "libpthread.so.0" is not present in android OS. I think step 2 doesn't work and it links "libsherpa-onnx-c-api.so" from nuget package but not from flutter build.

So my main question is how to link "libsherpa-onnx-c-api.so" from flutter build to nuget package for c# if i wanna build package from source via your scripts?

Today I got the idea to link "libsherpa-onnx-c-api.so" from flutter build with a different name and imort via custom import resolver, but dunno if that works.