-
Notifications
You must be signed in to change notification settings - Fork 579
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
求大神指导一下unity编译安卓手机apk如何调用sheerpa-onnx #1892
Comments
感谢大佬回复。
看着感觉像是加载插件libsherpa-onnx-c-api.so失败了,搜索了网上,然后以为是路径存放不对,又换了几种存放路径,还是加载失败。现在的插件路径存放是:
麻烦帮我看看,请问还有什么地方需要我提供的?非常感谢! |
hello @newkitty i tried translating what you said (i don't speak chinese), i hope i understood the problem correctly. |
Okay, thank you for your attention, respected experts. |
@newkitty I did a few changes based on your project and its works on Android mobile
![]()
Thanks for your project, it help me a lot, hope above suggestion help you also |
Also I updated the packages ( .dll or others ) from nuget, since I am using MacOS, I have to install osx package |
@mtsangcl102
Additionally, I would like to ask which version of sherpa-onnx you are using? I often experience crashes with the latest version. |
@newkitty that copy directory used for copy the tts models from streamAsset to a readable destination as I understand, in your code, it is doing copy from A folder to A folder I do not sure if update to latest version is necessary, since I am using MacOS so I have to install lastest version to confirm editor works, I believe that you are not have to do that Thanks for the invitation but I think I could not put much time into it, but i love to share my experience to help your project done |
Okey,@mtsangcl102 1.Take a look at the code here please, This is how I wrote it: 2.And what is the exact version of sherpa-onnx that you are using? I would like to try using your version. 3.Thank you for your help. Since I'm not very skilled in coding, I will try my best. |
@newkitty back to the path, checked the code you uploaded, I think that is okay, but I got an error about read-only directory, I did not find out the reason, may be not about the code so my suggestion is keep AndroidManifest and mainTemplate.gradle in Plugins/Android first, |
我是新手小白,想自己练练手,所以想用unity直接编译个手机app看看,我按照一位前辈的issue里面的操作步骤做了,但是刚开始提示找不到sherpa-onnx,我放了sherpa-onnx.dll到plugin下面,其他的都和前辈发文截图里面的差不多一样,然后在文件拷贝完成后就闪退,请大神指导一下unity编译安卓手机apk如何调用sheerpa-onnx,感谢! Good Morning,
i will be sharing the code needed to make sherpa-onnx tts work on unity specifically on android builds!
the problem is that unity merges the model files that we need for the tts in that jar file, making it not possible to pass the path directly to the sherpa-onnx plugin, and if you do the app will crash/quit!
there are work arounds for this, the simplest is using UnityWebRequest (similar to www of .net) to copy the files from the archive location in streamingAssets into a readable location and pass the new location to the sherpa-onnx plugin,
to do this, i created StreamingAssetsApi scripts which take care of such operations.
first on the unity editor side we have a script that records the hierarchy of the streamingAssets folder and writes it in a text file in the streaming assets (think of it as an index page of a book):
with this we will have a unity function that shows in the editor like this:



so obviously to use it we click BuildsTools > Generate StreamingAssets Hierarchy.
this creates the following file that contains the streamingAssets Hierarchy:
and it contains something like this:
Optionally we can make unity call this function automatically each time we do a build:
now on the android side, the StreamingAssetsApi script contains functions to copy a file or a directory recursively from the streaming assets to different directory, along with function that use the hierarchy file to get a list of files in a certain directory or sub directory.
the StreamingAssetsApi uses coroutines to handle the copy operations, which you can call using the StartCoroutine function in a MonoBehaviour script, but also has an async await wrapper functions for this to run the coroutines using an awaitable RunCoroutine Function, for example:
await this.RunCoroutine( StreamingAssetsAPI.CopyDirectory( modelsDir, // subfolder in StreamingAssets BuildPath( modelsDir ), () => { Debug.Log( modelsDir+ ": Directory copied!"); } ) );
now that we have the streamingAssetsApi implemented, we can test the sherpa-onnx tts at runtime using the following script:
now you need to fill the inspector values:

the important ones are the paths, make sure to provide the paths relative to the streamingAssets Folder. and make sure that those files actually exist.
this way you have a function unity android build!
drawback:
if you have a different work around for the streaming assets issue, i'd be happy to hear it :)
Enjoy!
Originally posted by @adem-rguez in #1635 (comment)
The text was updated successfully, but these errors were encountered: