Committed by
GitHub
Build APKs for two-pass speech recognition (#308)
正在显示
4 个修改的文件
包含
224 行增加
和
1 行删除
| @@ -38,6 +38,7 @@ jobs: | @@ -38,6 +38,7 @@ jobs: | ||
| 38 | shell: bash | 38 | shell: bash |
| 39 | run: | | 39 | run: | |
| 40 | export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME | 40 | export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME |
| 41 | + ./build-apk-two-pass.sh | ||
| 41 | ./build-apk.sh | 42 | ./build-apk.sh |
| 42 | 43 | ||
| 43 | - name: Display APK | 44 | - name: Display APK |
不能预览此文件类型
build-apk-two-pass.sh
0 → 100755
| 1 | +#!/usr/bin/env bash | ||
| 2 | + | ||
| 3 | +# Please set the environment variable ANDROID_NDK | ||
| 4 | +# before running this script | ||
| 5 | + | ||
| 6 | +# Inside the $ANDROID_NDK directory, you can find a binary ndk-build | ||
| 7 | +# and some other files like the file "build/cmake/android.toolchain.cmake" | ||
| 8 | + | ||
| 9 | +set -e | ||
| 10 | + | ||
| 11 | +log() { | ||
| 12 | + # This function is from espnet | ||
| 13 | + local fname=${BASH_SOURCE[1]##*/} | ||
| 14 | + echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*" | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) | ||
| 18 | + | ||
| 19 | +log "Building two-pass APK for sherpa-onnx v${SHERPA_ONNX_VERSION}" | ||
| 20 | + | ||
| 21 | +log "====================arm64-v8a=================" | ||
| 22 | +./build-android-arm64-v8a.sh | ||
| 23 | +log "====================armv7-eabi================" | ||
| 24 | +./build-android-armv7-eabi.sh | ||
| 25 | +log "====================x86-64====================" | ||
| 26 | +./build-android-x86-64.sh | ||
| 27 | +log "====================x86====================" | ||
| 28 | +./build-android-x86.sh | ||
| 29 | + | ||
| 30 | +mkdir -p apks | ||
| 31 | + | ||
| 32 | +log "Download 1st pass streaming model (English)" | ||
| 33 | + | ||
| 34 | +# Download the model | ||
| 35 | +# see https://k2-fsa.github.io/sherpa/onnx/pretrained_models/online-transducer/zipformer-transducer-models.html#csukuangfj-sherpa-onnx-streaming-zipformer-en-20m-2023-02-17-english | ||
| 36 | +repo_url=https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-20M-2023-02-17 | ||
| 37 | +log "$repo_url" | ||
| 38 | + | ||
| 39 | +log "Start downloading ${repo_url}" | ||
| 40 | +repo=$(basename $repo_url) | ||
| 41 | +log "Download pretrained model from $repo_url" | ||
| 42 | +GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url | ||
| 43 | +pushd $repo | ||
| 44 | +git lfs pull --include "*.onnx" | ||
| 45 | + | ||
| 46 | +# remove .git to save spaces | ||
| 47 | +rm -rf .git | ||
| 48 | +rm README.md | ||
| 49 | +rm -rf test_wavs | ||
| 50 | +rm .gitattributes | ||
| 51 | +rm export-onnx*.sh | ||
| 52 | + | ||
| 53 | +rm encoder-epoch-99-avg-1.onnx | ||
| 54 | +rm decoder-epoch-99-avg-1.int8.onnx | ||
| 55 | +rm joiner-epoch-99-avg-1.onnx | ||
| 56 | + | ||
| 57 | +ls -lh | ||
| 58 | +popd | ||
| 59 | + | ||
| 60 | +mv -v $repo ./android/SherpaOnnx2Pass/app/src/main/assets/ | ||
| 61 | +tree ./android/SherpaOnnx2Pass/app/src/main/assets/ | ||
| 62 | +repo_1st=$repo | ||
| 63 | + | ||
| 64 | +# https://k2-fsa.github.io/sherpa/onnx/pretrained_models/whisper/tiny.en.html | ||
| 65 | +repo_url=https://huggingface.co/csukuangfj/sherpa-onnx-whisper-tiny.en | ||
| 66 | +log "$repo_url" | ||
| 67 | + | ||
| 68 | +log "Start downloading ${repo_url}" | ||
| 69 | +repo=$(basename $repo_url) | ||
| 70 | +log "Download pretrained model from $repo_url" | ||
| 71 | +GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url | ||
| 72 | +pushd $repo | ||
| 73 | +git lfs pull --include "*.onnx" | ||
| 74 | + | ||
| 75 | +# remove .git to save spaces | ||
| 76 | +rm -rf .git | ||
| 77 | +rm README.md | ||
| 78 | +rm -rf test_wavs | ||
| 79 | +rm .gitattributes | ||
| 80 | + | ||
| 81 | +rm *.ort | ||
| 82 | +rm tiny.en-encoder.onnx | ||
| 83 | +rm tiny.en-decoder.onnx | ||
| 84 | + | ||
| 85 | +ls -lh | ||
| 86 | +popd | ||
| 87 | + | ||
| 88 | +mv -v $repo ./android/SherpaOnnx2Pass/app/src/main/assets/ | ||
| 89 | +tree ./android/SherpaOnnx2Pass/app/src/main/assets/ | ||
| 90 | +repo_2nd=$repo | ||
| 91 | + | ||
| 92 | +pushd android/SherpaOnnx2Pass/app/src/main/java/com/k2fsa/sherpa/onnx | ||
| 93 | +# sed -i.bak s/"firstType = 1"/"firstType = 1"/ ./MainActivity.kt | ||
| 94 | +sed -i.bak s/"secondType = 1"/"secondType = 2"/ ./MainActivity.kt | ||
| 95 | +git diff | ||
| 96 | +popd | ||
| 97 | + | ||
| 98 | +for arch in arm64-v8a armeabi-v7a x86_64 x86; do | ||
| 99 | + log "------------------------------------------------------------" | ||
| 100 | + log "build apk for $arch" | ||
| 101 | + log "------------------------------------------------------------" | ||
| 102 | + src_arch=$arch | ||
| 103 | + if [ $arch == "armeabi-v7a" ]; then | ||
| 104 | + src_arch=armv7-eabi | ||
| 105 | + elif [ $arch == "x86_64" ]; then | ||
| 106 | + src_arch=x86-64 | ||
| 107 | + fi | ||
| 108 | + | ||
| 109 | + ls -lh ./build-android-$src_arch/install/lib/*.so | ||
| 110 | + | ||
| 111 | + cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnx2Pass/app/src/main/jniLibs/$arch/ | ||
| 112 | + | ||
| 113 | + pushd ./android/SherpaOnnx2Pass | ||
| 114 | + ./gradlew build | ||
| 115 | + popd | ||
| 116 | + | ||
| 117 | + mv android/SherpaOnnx2Pass/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-en-2pass-whisper-tiny.en.apk | ||
| 118 | + ls -lh apks | ||
| 119 | + rm -v ./android/SherpaOnnx2Pass/app/src/main/jniLibs/$arch/*.so | ||
| 120 | +done | ||
| 121 | + | ||
| 122 | +git checkout . | ||
| 123 | + | ||
| 124 | +rm -rf ./android/SherpaOnnx2Pass/app/src/main/assets/$repo_1st | ||
| 125 | +rm -rf ./android/SherpaOnnx2Pass/app/src/main/assets/$repo_2nd | ||
| 126 | + | ||
| 127 | +log "==================================================" | ||
| 128 | +log " two-pass Chinese " | ||
| 129 | +log "==================================================" | ||
| 130 | + | ||
| 131 | +log "Download 1st pass streaming model (Chinese)" | ||
| 132 | +# https://k2-fsa.github.io/sherpa/onnx/pretrained_models/online-transducer/zipformer-transducer-models.html#sherpa-onnx-streaming-zipformer-zh-14m-2023-02-23 | ||
| 133 | +repo_url=https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-zh-14M-2023-02-23 | ||
| 134 | +log "$repo_url" | ||
| 135 | + | ||
| 136 | +log "Start downloading ${repo_url}" | ||
| 137 | +repo=$(basename $repo_url) | ||
| 138 | +log "Download pretrained model from $repo_url" | ||
| 139 | +GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url | ||
| 140 | +pushd $repo | ||
| 141 | +git lfs pull --include "*.onnx" | ||
| 142 | + | ||
| 143 | +# remove .git to save spaces | ||
| 144 | +rm -rf .git | ||
| 145 | +rm README.md | ||
| 146 | +rm -rf test_wavs | ||
| 147 | +rm .gitattributes | ||
| 148 | +rm export-onnx*.sh | ||
| 149 | + | ||
| 150 | +rm encoder-epoch-99-avg-1.onnx | ||
| 151 | +rm decoder-epoch-99-avg-1.int8.onnx | ||
| 152 | +rm joiner-epoch-99-avg-1.onnx | ||
| 153 | + | ||
| 154 | +ls -lh | ||
| 155 | +popd | ||
| 156 | + | ||
| 157 | +mv -v $repo ./android/SherpaOnnx2Pass/app/src/main/assets/ | ||
| 158 | +tree ./android/SherpaOnnx2Pass/app/src/main/assets/ | ||
| 159 | +repo_1st=$repo | ||
| 160 | + | ||
| 161 | +# https://k2-fsa.github.io/sherpa/onnx/pretrained_models/offline-paraformer/paraformer-models.html#csukuangfj-sherpa-onnx-paraformer-zh-2023-03-28-chinese | ||
| 162 | +repo_url=https://huggingface.co/csukuangfj/sherpa-onnx-paraformer-zh-2023-03-28 | ||
| 163 | +log "$repo_url" | ||
| 164 | + | ||
| 165 | +log "Start downloading ${repo_url}" | ||
| 166 | +repo=$(basename $repo_url) | ||
| 167 | +log "Download pretrained model from $repo_url" | ||
| 168 | +GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url | ||
| 169 | +pushd $repo | ||
| 170 | +git lfs pull --include "*.onnx" | ||
| 171 | + | ||
| 172 | +# remove .git to save spaces | ||
| 173 | +rm -rf .git | ||
| 174 | +rm README.md | ||
| 175 | +rm -rf test_wavs | ||
| 176 | +rm .gitattributes | ||
| 177 | + | ||
| 178 | +rm model.onnx | ||
| 179 | + | ||
| 180 | +ls -lh | ||
| 181 | +popd | ||
| 182 | + | ||
| 183 | +mv -v $repo ./android/SherpaOnnx2Pass/app/src/main/assets/ | ||
| 184 | +tree ./android/SherpaOnnx2Pass/app/src/main/assets/ | ||
| 185 | +repo_2nd=$repo | ||
| 186 | + | ||
| 187 | +pushd android/SherpaOnnx2Pass/app/src/main/java/com/k2fsa/sherpa/onnx | ||
| 188 | +sed -i.bak s/"firstType = 1"/"firstType = 0"/ ./MainActivity.kt | ||
| 189 | +sed -i.bak s/"secondType = 1"/"secondType = 0"/ ./MainActivity.kt | ||
| 190 | +git diff | ||
| 191 | +popd | ||
| 192 | + | ||
| 193 | +for arch in arm64-v8a armeabi-v7a x86_64 x86; do | ||
| 194 | + log "------------------------------------------------------------" | ||
| 195 | + log "build apk for $arch" | ||
| 196 | + log "------------------------------------------------------------" | ||
| 197 | + src_arch=$arch | ||
| 198 | + if [ $arch == "armeabi-v7a" ]; then | ||
| 199 | + src_arch=armv7-eabi | ||
| 200 | + elif [ $arch == "x86_64" ]; then | ||
| 201 | + src_arch=x86-64 | ||
| 202 | + fi | ||
| 203 | + | ||
| 204 | + ls -lh ./build-android-$src_arch/install/lib/*.so | ||
| 205 | + | ||
| 206 | + cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnx2Pass/app/src/main/jniLibs/$arch/ | ||
| 207 | + | ||
| 208 | + pushd ./android/SherpaOnnx2Pass | ||
| 209 | + ./gradlew build | ||
| 210 | + popd | ||
| 211 | + | ||
| 212 | + mv android/SherpaOnnx2Pass/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-zh-2pass-paraformer.apk | ||
| 213 | + ls -lh apks | ||
| 214 | + rm -v ./android/SherpaOnnx2Pass/app/src/main/jniLibs/$arch/*.so | ||
| 215 | +done | ||
| 216 | + | ||
| 217 | +git checkout . | ||
| 218 | + | ||
| 219 | +rm -rf ./android/SherpaOnnx2Pass/app/src/main/assets/$repo_1st | ||
| 220 | +rm -rf ./android/SherpaOnnx2Pass/app/src/main/assets/$repo_2nd | ||
| 221 | + | ||
| 222 | +ls -lh apks/ |
-
请 注册 或 登录 后发表评论