Skip to content
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

anzhuo编译SherpaOnnxJavaDemo,so库和模型文件均已正确添加,提示报错:java.lang.NoSuchMethodError: No direct method <init>(Landroid/content/res/AssetManager;Lcom/k2fsa/sherpa/onnx/OnlineRecognizerConfig;) #1597

Closed
aceip opened this issue Dec 5, 2024 · 13 comments · Fixed by #1616

Comments

@aceip
Copy link

aceip commented Dec 5, 2024

具体报错提示如下:
image
初步推断是SpeechSherpaRecognitionService.java:100的OnlineRecognizer(getAssets(), config);方法有问题,但不知如何搞起

@aceip
Copy link
Author

aceip commented Dec 5, 2024

    recognizer = new OnlineRecognizer(getAssets(), config);
                 ^

需要: OnlineRecognizerConfig
找到: AssetManager,OnlineRecognizerConfig
原因: 实际参数列表和形式参数列表长度不同

@csukuangfj
Copy link
Collaborator

你有没有改我们代码的包名?

package name,是千万不能改的。除非你知道如何修改jni c++代码

@aceip
Copy link
Author

aceip commented Dec 6, 2024

没有任何改动 有可能是版本问题 你能发下你们正确编译的java版本 gradle版本 还有compileSdk 版本吗

@aceip
Copy link
Author

aceip commented Dec 6, 2024

找到问题了 private long ptr = 1; 这个参数修改到1和以上可以正确跑 但是0就直接退出

@aceip
Copy link
Author

aceip commented Dec 6, 2024

通过测试 发现问题在ptr上 程序运行结束后清理掉缓存后就可以了

@aceip
Copy link
Author

aceip commented Dec 6, 2024

解决思路:在Mainactivity中增加代码:
@OverRide
protected void onDestroy() {
super.onDestroy();

    SpeechSherpaRecognitionService.recognizer.release();
}
重新运行程序 即可解决
新的问题:模型识别度不高,误判率很大

@aceip
Copy link
Author

aceip commented Dec 6, 2024

SpeechSherpaRecognitionService.recognizer.release();目的是在程序结束之后清理掉pr缓存,在onlirecognizer.java中有重写 可以多次引用以解除内存被占用问题(应当是这样)

@csukuangfj
Copy link
Collaborator

新的问题:模型识别度不高,误判率很大

默认用 14M 的模型,这是这个项目中,速度最快,准确率最差的模型。

你想要准确率高的模型,可以试试
https://k2-fsa.github.io/sherpa/onnx/pretrained_models/online-transducer/zipformer-transducer-models.html#csukuangfj-sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20-bilingual-chinese-english

我们 android kotlin 的 demo, 默认就是这个模型.


https://hf-mirror.com/csukuangfj/sherpa-onnx-apk/blob/main/asr/1.10.33/sherpa-onnx-1.10.33-arm64-v8a-asr-bilingual_zh_en-zipformer.apk

这个是编译好的 apk, 你可以提前感受下准确率。

@aceip
Copy link
Author

aceip commented Dec 6, 2024

ok

@aceip aceip closed this as completed Dec 6, 2024
@aceip aceip reopened this Dec 6, 2024
@aceip
Copy link
Author

aceip commented Dec 6, 2024

问题依旧存在:java.lang.NoSuchMethodError: No direct method (Landroid/content/res/AssetManager;Lcom/k2fsa/sherpa/onnx/OnlineRecognizerConfig;)V in class Lcom/k2fsa/sherpa/onnx/OnlineRecognizer; or its super classes (declaration of 'com.k2fsa.sherpa.onnx.OnlineRecognizer'
每次安装app后就是这个报错,但是修改掉ptr值以后第二次运行就没有问题了,感觉问题还是在ptr赋值上

@csukuangfj
Copy link
Collaborator

#1454 的作者 @JameWade 帮忙看下?

@aceip
你可以先用 https://github.com/k2-fsa/sherpa-onnx/tree/master/android/SherpaOnnx

@aceip
Copy link
Author

aceip commented Dec 6, 2024

好的好的

@csukuangfj
Copy link
Collaborator

@aceip
请参考 https://github.com/k2-fsa/sherpa-onnx/blob/master/android/SherpaOnnxJavaDemo/README.md
运行那个 android java demo.

注:

  1. 请使用最新的 master 跑
  2. 你不需要再复制任何的 .so 文件了。最新的代码用了 aar, 自动下载的那种。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants