whisper.cpp: Android端测试 -- Android端手机部署音频大模型

whisper.cpp: Android端测试


1.环境需要

以下是经实验验证可行的环境参考,也可尝试其他版本。

(1)PC:Ubuntu 22.04.4

(2)硬件设备:Android 手机

(3)软件环境:如下表所示

工具 版本 安装
Anaconda 2021.05 参考:Anaconda3安装及使用
cmake 3.26.0 conda install -c conda-forge cmake
make 4.4.1 conda install -c conda-forge make
ndk android-ndk-r26c 官网下载解压,设置环境变量
adb 1.0.41 conda install -c conda-forge adb
git 2.34.1 sudo apt-get update
sudo apt-get install git
git-lfs 3.6.0 sudo apt-get install git-lfs

2.构建项目

(1)克隆项目:

shell 复制代码
git lfs install
git clone https://github.com/ggerganov/whisper.cpp.git
cd whisper.cpp

(2)下载模型:

shell 复制代码
# 修改脚本./models/download-ggml-model.sh:
#      替换huggingface.co为镜像网站hf-mirror.com(因不能访问外网)
#src="https://huggingface.co/ggerganov/whisper.cpp"
src="https://hf-mirror.com/ggerganov/whisper.cpp"
    #src="https://huggingface.co/akashmjn/tinydiarize-whisper.cpp"
    src="https://hf-mirror.com/akashmjn/tinydiarize-whisper.cpp"

# 下载模型:下载其中一个 Whisper 模型 转换为 ggml 格式。例如:
sh ./models/download-ggml-model.sh base.en

(3)Android构建:

shell 复制代码
# 构建适用于 Android 的版本
$ cmake \
  -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
  -DANDROID_ABI=arm64-v8a \
  -DANDROID_PLATFORM=android-28 \
  -DCMAKE_C_FLAGS="-march=armv8.7a" \
  -DCMAKE_CXX_FLAGS="-march=armv8.7a" \
  -DGGML_OPENMP=OFF \
  -DGGML_LLAMAFILE=OFF \
  -B build-android
  
$ cmake --build build-android --config Release -j{n}
$ cmake --install build-android --prefix ${install-dir} --config Release
$ cp build-android/bin ${install-dir}

3.Android测试

(1)设备连接:确认设备连接好了,使用以下命令查看是否有adb设备连接:

shell 复制代码
$ adb devices

(2)push文件到设备:

shell 复制代码
$ adb shell "mkdir /data/local/tmp/whisper.cpp"
$ adb push ${install-dir} /data/local/tmp/whisper.cpp/
$ adb push ./models /data/local/tmp/whisper.cpp/
$ adb push ./samples /data/local/tmp/whisper.cpp/

(3)设备上运行:

shell 复制代码
$ adb shell
$ cd /data/local/tmp/whisper.cpp
$ export LD_LIBRARY_PATH=lib ./bin/main -f ${audio_file_16bit.wav}

注意,main示例仅使用 16 位 WAV 运行,因此请确保音频是此格式文件,如不是请转换格式。例如:

shell 复制代码
# mp3转wav
ffmpeg -i input.mp3 -ar 16000 -ac 1 -c:a pcm_s16le output.wav

声明:资源可能存在第三方来源,若有侵权请联系删除!

相关推荐
openinstall全渠道统计10 分钟前
免填邀请码工具:赋能六大核心场景,重构App增长新模型
android·ios·harmonyos
双鱼大猫32 分钟前
一句话说透Android里面的ServiceManager的注册服务
android
双鱼大猫1 小时前
一句话说透Android里面的Window的内部机制
android
双鱼大猫2 小时前
一句话说透Android里面的为什么要设计Window?
android
双鱼大猫2 小时前
一句话说透Android里面的主线程创建时机,frameworks层面分析
android
苏金标2 小时前
android 快速定位当前页面
android
雾里看山6 小时前
【MySQL】内置函数
android·数据库·mysql
风浅月明6 小时前
[Android]页面间传递model列表
android
法迪6 小时前
Android自带的省电模式主要做什么呢?
android·功耗
风浅月明6 小时前
[Android]AppCompatEditText限制最多只能输入两位小数
android