第一章 基于Ubuntu 24.04 搭建wenet语音转文字
第二章 编译运行Android Wenet语音识别
本文继续前一章内容,开始前,请先准备好Wenet源码。
本文目标是使用Android studio 运行Wenet语音识别-Android Demo。
buildscript {
repositories {
google()
// jcenter()
mavenCentral()
gradlePluginPortal()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.4.1'
}
}
allprojects {
repositories {
google()
// jcenter()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
// 增加命名空间
namespace "com.mobvoi.wenet"
官方提供了两种,这里我们下载中文的即可;
下载解压后,将“final.zip”和“units.txt”放入Androidde(“app/src/main/assets”)文件夹中;
在文件wenet/runtime/android/app/build.gradle中点击运行按钮 执行task extractAARForNativeBuild
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/a0c6431095fa44a7957be1391bc1ca7c.png =300)在build下生成pytorch_android*.aar文件;
修改wenet/runtime/android/app/src/main/cpp/cmake/libtorch.cmake,配置版本号
# Change version in runtime/android/app/build.gradle.
file(GLOB PYTORCH_INCLUDE_DIRS "${build_DIR}/pytorch_android-1.13.0.aar/headers")
file(GLOB PYTORCH_LINK_DIRS "${build_DIR}/pytorch_android-1.13.0.aar/jni/${ANDROID_ABI}")
最后构建并运行APK即可。
原因是没有执行第3步:执行task extractAARForNativeBuild;
至此Wenet的Android Demo 已跑通运行。
注意:此方式运行的Android Demo 语音识别过程无需移动网络或Wifi。
参考
https://github.com/wenet-e2e/wenet/blob/main/runtime/android/README.md