https://github.com/xue-fei/sherpa-onnx-unity
最初測試了PC的Win和Linux平臺,直接從nuget緩存包中拷貝相關文件,按示例寫了語音轉文字和文字轉語音的測試代碼,功能都正常。
然后是Android端,看了示例發現有編譯好的jni.so之類的,裝AndroidStudio建library一頓折騰,發現這種方法怕是要寫很多Java代碼,而且Unity里也要寫很多代碼,挺費勁,翻了翻 Issues 發現有預編譯針對Android的libsherpa-onnx-cxx-api.so和libsherpa-onnx-c-api.so 等,sherpa-onnx-v1.10.46-android.tar.bz2 拷貝進Unity直接使用
對于打包安卓的相關修改,勾選了兩個模板
mainTemplate.gradle 忽略了模型相關文件
apply plugin: 'com.android.library'
**APPLY_PLUGINS**dependencies {implementation fileTree(dir: 'libs', include: ['*.jar'])
**DEPS**}android {compileSdkVersion **APIVERSION**buildToolsVersion '**BUILDTOOLS**'compileOptions {sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8}defaultConfig {minSdkVersion **MINSDKVERSION**targetSdkVersion **TARGETSDKVERSION**ndk {abiFilters **ABIFILTERS**}versionCode **VERSIONCODE**versionName '**VERSIONNAME**'consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD**}lintOptions {abortOnError false}aaptOptions {noCompress = **BUILTIN_NOCOMPRESS** + unityStreamingAssets.tokenize(', ')//ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"ignoreAssetsPattern = 'sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12:sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20:vits-melo-tts-zh_en:!silero_vad.onnx'}**PACKAGING_OPTIONS**
}**REPOSITORIES**
**IL_CPP_BUILD_SETUP**
**SOURCE_BUILD_SETUP**
**EXTERNAL_SOURCES**
gradleTemplate.properties 注釋了android.enableR8
org.gradle.jvmargs=-Xmx**JVM_HEAP_SIZE**M
org.gradle.parallel=true
#android.enableR8=**MINIFY_WITH_R_EIGHT**
unityStreamingAssets=**STREAMING_ASSETS**
**ADDITIONAL_PROPERTIES**