Fangjun Kuang
Committed by GitHub

Release pre-built APKs (#285)

  1 +name: apk
  2 +
  3 +on:
  4 + push:
  5 + branches:
  6 + - apk
  7 + tags:
  8 + - '*'
  9 +
  10 + workflow_dispatch:
  11 +
  12 +concurrency:
  13 + group: apk-${{ github.ref }}
  14 + cancel-in-progress: true
  15 +
  16 +permissions:
  17 + contents: write
  18 +
  19 +jobs:
  20 + apk:
  21 + runs-on: ${{ matrix.os }}
  22 + strategy:
  23 + fail-fast: false
  24 + matrix:
  25 + os: [ubuntu-latest]
  26 +
  27 + steps:
  28 + - uses: actions/checkout@v2
  29 + with:
  30 + fetch-depth: 0
  31 + - name: Display NDK HOME
  32 + shell: bash
  33 + run: |
  34 + echo "ANDROID_NDK_LATEST_HOME: ${ANDROID_NDK_LATEST_HOME}"
  35 + ls -lh ${ANDROID_NDK_LATEST_HOME}
  36 +
  37 + - name: build APK
  38 + shell: bash
  39 + run: |
  40 + export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME
  41 + ./build-apk.sh
  42 +
  43 + - name: Display APK
  44 + shell: bash
  45 + run: |
  46 + ls -lh ./apks/
  47 +
  48 + - uses: actions/upload-artifact@v2
  49 + with:
  50 + path: ./apks/*.apk
  51 +
  52 + - name: Release APK
  53 + uses: svenstaro/upload-release-action@v2
  54 + with:
  55 + file_glob: true
  56 + file: apks/*.apk
1 cmake_minimum_required(VERSION 3.13 FATAL_ERROR) 1 cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
2 project(sherpa-onnx) 2 project(sherpa-onnx)
3 3
4 -set(SHERPA_ONNX_VERSION "1.7.9") 4 +set(SHERPA_ONNX_VERSION "1.7.10")
5 5
6 # Disable warning about 6 # Disable warning about
7 # 7 #
@@ -143,6 +143,16 @@ by following the code) @@ -143,6 +143,16 @@ by following the code)
143 5 - csukuangfj/sherpa-onnx-streaming-paraformer-bilingual-zh-en 143 5 - csukuangfj/sherpa-onnx-streaming-paraformer-bilingual-zh-en
144 https://huggingface.co/csukuangfj/sherpa-onnx-streaming-paraformer-bilingual-zh-en 144 https://huggingface.co/csukuangfj/sherpa-onnx-streaming-paraformer-bilingual-zh-en
145 145
  146 +6 - sherpa-onnx-streaming-zipformer-en-2023-06-26
  147 + https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-06-26
  148 +
  149 +7 - shaojieli/sherpa-onnx-streaming-zipformer-fr-2023-04-14 (French)
  150 + https://huggingface.co/shaojieli/sherpa-onnx-streaming-zipformer-fr-2023-04-14
  151 +
  152 +8 - csukuangfj/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20 (Bilingual, Chinese + English)
  153 + https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20
  154 + encoder int8, decoder/joiner float32
  155 +
146 */ 156 */
147 fun getModelConfig(type: Int): OnlineModelConfig? { 157 fun getModelConfig(type: Int): OnlineModelConfig? {
148 when (type) { 158 when (type) {
@@ -158,6 +168,7 @@ fun getModelConfig(type: Int): OnlineModelConfig? { @@ -158,6 +168,7 @@ fun getModelConfig(type: Int): OnlineModelConfig? {
158 modelType = "zipformer", 168 modelType = "zipformer",
159 ) 169 )
160 } 170 }
  171 +
161 1 -> { 172 1 -> {
162 val modelDir = "sherpa-onnx-lstm-zh-2023-02-20" 173 val modelDir = "sherpa-onnx-lstm-zh-2023-02-20"
163 return OnlineModelConfig( 174 return OnlineModelConfig(
@@ -221,6 +232,45 @@ fun getModelConfig(type: Int): OnlineModelConfig? { @@ -221,6 +232,45 @@ fun getModelConfig(type: Int): OnlineModelConfig? {
221 modelType = "paraformer", 232 modelType = "paraformer",
222 ) 233 )
223 } 234 }
  235 +
  236 + 6 -> {
  237 + val modelDir = "sherpa-onnx-streaming-zipformer-en-2023-06-26"
  238 + return OnlineModelConfig(
  239 + transducer = OnlineTransducerModelConfig(
  240 + encoder = "$modelDir/encoder-epoch-99-avg-1-chunk-16-left-128.int8.onnx",
  241 + decoder = "$modelDir/decoder-epoch-99-avg-1-chunk-16-left-128.onnx",
  242 + joiner = "$modelDir/joiner-epoch-99-avg-1-chunk-16-left-128.onnx",
  243 + ),
  244 + tokens = "$modelDir/tokens.txt",
  245 + modelType = "zipformer2",
  246 + )
  247 + }
  248 +
  249 + 7 -> {
  250 + val modelDir = "sherpa-onnx-streaming-zipformer-fr-2023-04-14"
  251 + return OnlineModelConfig(
  252 + transducer = OnlineTransducerModelConfig(
  253 + encoder = "$modelDir/encoder-epoch-29-avg-9-with-averaged-model.int8.onnx",
  254 + decoder = "$modelDir/decoder-epoch-29-avg-9-with-averaged-model.onnx",
  255 + joiner = "$modelDir/joiner-epoch-29-avg-9-with-averaged-model.onnx",
  256 + ),
  257 + tokens = "$modelDir/tokens.txt",
  258 + modelType = "zipformer",
  259 + )
  260 + }
  261 +
  262 + 8 -> {
  263 + val modelDir = "sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20"
  264 + return OnlineModelConfig(
  265 + transducer = OnlineTransducerModelConfig(
  266 + encoder = "$modelDir/encoder-epoch-99-avg-1.int8.onnx",
  267 + decoder = "$modelDir/decoder-epoch-99-avg-1.onnx",
  268 + joiner = "$modelDir/joiner-epoch-99-avg-1.onnx",
  269 + ),
  270 + tokens = "$modelDir/tokens.txt",
  271 + modelType = "zipformer",
  272 + )
  273 + }
224 } 274 }
225 return null; 275 return null;
226 } 276 }
  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 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 +
  31 +mkdir -p apks
  32 +
  33 +log "https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-06-26"
  34 +
  35 +# Download the model
  36 +# see https://k2-fsa.github.io/sherpa/onnx/pretrained_models/online-transducer/zipformer-transducer-models.html#csukuangfj-sherpa-onnx-streaming-zipformer-en-2023-06-26-english
  37 +repo_url=https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-06-26
  38 +log "Start testing ${repo_url}"
  39 +repo=$(basename $repo_url)
  40 +log "Download pretrained model and test-data from $repo_url"
  41 +GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url
  42 +pushd $repo
  43 +git lfs pull --include "*.onnx"
  44 +
  45 +# remove .git to save spaces
  46 +rm -rf .git
  47 +rm README.md
  48 +rm -v *64*
  49 +rm -v encoder-epoch-99-avg-1-chunk-16-left-128.onnx
  50 +rm -v decoder-epoch-99-avg-1-chunk-16-left-128.int8.onnx
  51 +rm -v joiner-epoch-99-avg-1-chunk-16-left-128.int8.onnx
  52 +rm -rfv test_wavs
  53 +rm -v *.sh
  54 +ls -lh
  55 +popd
  56 +
  57 +mv -v $repo ./android/SherpaOnnx/app/src/main/assets/
  58 +tree ./android/SherpaOnnx/app/src/main/assets/
  59 +
  60 +pushd android/SherpaOnnx/app/src/main/java/com/k2fsa/sherpa/onnx
  61 +sed -i.bak s/"type = 0"/"type = 6"/ ./MainActivity.kt
  62 +git diff
  63 +popd
  64 +
  65 +for arch in arm64-v8a armeabi-v7a x86_64 x86; do
  66 + log "------------------------------------------------------------"
  67 + log "build apk for $arch"
  68 + log "------------------------------------------------------------"
  69 + src_arch=$arch
  70 + if [ $arch == "armeabi-v7a" ]; then
  71 + src_arch=armv7-eabi
  72 + elif [ $arch == "x86_64" ]; then
  73 + src_arch=x86-64
  74 + fi
  75 +
  76 + ls -lh ./build-android-$src_arch/install/lib/*.so
  77 +
  78 + cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnx/app/src/main/jniLibs/$arch/
  79 +
  80 + pushd ./android/SherpaOnnx
  81 + ./gradlew build
  82 + popd
  83 +
  84 + mv android/SherpaOnnx/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-en.apk
  85 + ls -lh apks
  86 + rm -v ./android/SherpaOnnx/app/src/main/jniLibs/$arch/*.so
  87 +done
  88 +
  89 +git checkout .
  90 +
  91 +rm -rf ./android/SherpaOnnx/app/src/main/assets/$repo
  92 +
  93 +# type 3, encoder int8, zh
  94 +log "https://huggingface.co/pkufool/icefall-asr-zipformer-streaming-wenetspeech-20230615"
  95 +# see
  96 +# https://k2-fsa.github.io/sherpa/onnx/pretrained_models/online-transducer/zipformer-transducer-models.html#pkufool-icefall-asr-zipformer-streaming-wenetspeech-20230615-chinese
  97 +
  98 +# Download the model
  99 +repo_url=https://huggingface.co/pkufool/icefall-asr-zipformer-streaming-wenetspeech-20230615
  100 +log "Start testing ${repo_url}"
  101 +repo=$(basename $repo_url)
  102 +log "Download pretrained model and test-data from $repo_url"
  103 +GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url
  104 +pushd $repo
  105 +git lfs pull --include "*.onnx"
  106 +
  107 +# remove .git to save spaces
  108 +rm -rf .git
  109 +rm README.md
  110 +rm -rf logs
  111 +rm -rf scripts
  112 +rm -rf test_wavs
  113 +rm -rf data/.DS_Store
  114 +rm data/lang_char/*.pt
  115 +rm data/lang_char/lexicon.txt
  116 +rm data/lang_char/words.txt
  117 +rm -v exp/*.pt
  118 +rm -v exp/*32*
  119 +rm -v exp/*256*
  120 +rm -v exp/encoder-epoch-12-avg-4-chunk-16-left-128.onnx
  121 +rm -v exp/decoder-epoch-12-avg-4-chunk-16-left-128.int8.onnx
  122 +rm -v exp/joiner-epoch-12-avg-4-chunk-16-left-128.int8.onnx
  123 +rm -rf exp/tensorboard
  124 +
  125 +popd
  126 +
  127 +mv -v $repo ./android/SherpaOnnx/app/src/main/assets/
  128 +tree ./android/SherpaOnnx/app/src/main/assets/
  129 +git checkout .
  130 +
  131 +pushd android/SherpaOnnx/app/src/main/java/com/k2fsa/sherpa/onnx
  132 +sed -i.bak s/"type = 0"/"type = 3"/ ./MainActivity.kt
  133 +git diff
  134 +popd
  135 +
  136 +for arch in arm64-v8a armeabi-v7a x86_64 x86; do
  137 + log "------------------------------------------------------------"
  138 + log "build apk for $arch"
  139 + log "------------------------------------------------------------"
  140 + src_arch=$arch
  141 + if [ $arch == "armeabi-v7a" ]; then
  142 + src_arch=armv7-eabi
  143 + elif [ $arch == "x86_64" ]; then
  144 + src_arch=x86-64
  145 + fi
  146 +
  147 + ls -lh ./build-android-$src_arch/install/lib/*.so
  148 +
  149 + cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnx/app/src/main/jniLibs/$arch/
  150 +
  151 + pushd ./android/SherpaOnnx
  152 + ./gradlew build
  153 + popd
  154 +
  155 + mv android/SherpaOnnx/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-zh.apk
  156 + ls -lh apks
  157 + rm -v ./android/SherpaOnnx/app/src/main/jniLibs/$arch/*.so
  158 +done
  159 +
  160 +git checkout .
  161 +
  162 +rm -rf ./android/SherpaOnnx/app/src/main/assets/$repo
  163 +
  164 +# type 7, encoder int8, french
  165 +log "https://huggingface.co/shaojieli/sherpa-onnx-streaming-zipformer-fr-2023-04-14"
  166 +# see
  167 +# https://k2-fsa.github.io/sherpa/onnx/pretrained_models/online-transducer/zipformer-transducer-models.html#shaojieli-sherpa-onnx-streaming-zipformer-fr-2023-04-14-french
  168 +
  169 +# Download the model
  170 +repo_url=https://huggingface.co/shaojieli/sherpa-onnx-streaming-zipformer-fr-2023-04-14
  171 +log "Start testing ${repo_url}"
  172 +repo=$(basename $repo_url)
  173 +log "Download pretrained model and test-data from $repo_url"
  174 +GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url
  175 +pushd $repo
  176 +git lfs pull --include "*.onnx"
  177 +
  178 +# remove .git to save spaces
  179 +rm -rf .git
  180 +rm -v .gitattributes
  181 +rm -rf test_wavs
  182 +rm -v README.md
  183 +rm -v encoder-epoch-29-avg-9-with-averaged-model.onnx
  184 +rm -v decoder-epoch-29-avg-9-with-averaged-model.int8.onnx
  185 +rm -v joiner-epoch-29-avg-9-with-averaged-model.int8.onnx
  186 +rm -v export*.sh
  187 +
  188 +popd
  189 +
  190 +mv -v $repo ./android/SherpaOnnx/app/src/main/assets/
  191 +tree ./android/SherpaOnnx/app/src/main/assets/
  192 +git checkout .
  193 +
  194 +pushd android/SherpaOnnx/app/src/main/java/com/k2fsa/sherpa/onnx
  195 +sed -i.bak s/"type = 0"/"type = 7"/ ./MainActivity.kt
  196 +git diff
  197 +popd
  198 +
  199 +for arch in arm64-v8a armeabi-v7a x86_64 x86; do
  200 + log "------------------------------------------------------------"
  201 + log "build apk for $arch"
  202 + log "------------------------------------------------------------"
  203 + src_arch=$arch
  204 + if [ $arch == "armeabi-v7a" ]; then
  205 + src_arch=armv7-eabi
  206 + elif [ $arch == "x86_64" ]; then
  207 + src_arch=x86-64
  208 + fi
  209 +
  210 + ls -lh ./build-android-$src_arch/install/lib/*.so
  211 +
  212 + cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnx/app/src/main/jniLibs/$arch/
  213 +
  214 + pushd ./android/SherpaOnnx
  215 + ./gradlew build
  216 + popd
  217 +
  218 + mv android/SherpaOnnx/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-fr.apk
  219 + ls -lh apks
  220 + rm -v ./android/SherpaOnnx/app/src/main/jniLibs/$arch/*.so
  221 +done
  222 +
  223 +git checkout .
  224 +
  225 +rm -rf ./android/SherpaOnnx/app/src/main/assets/$repo
  226 +
  227 +# type 8, encoder int8, Binglual English + Chinese
  228 +log "https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20"
  229 +# see
  230 +# https://k2-fsa.github.io/sherpa/onnx/pretrained_models/online-transducer/zipformer-transducer-models.html#csukuangfj-sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20-bilingual-chinese-english
  231 +
  232 +# Download the model
  233 +repo_url=https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20
  234 +log "Start testing ${repo_url}"
  235 +repo=$(basename $repo_url)
  236 +log "Download pretrained model and test-data from $repo_url"
  237 +GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url
  238 +pushd $repo
  239 +git lfs pull --include "*.onnx"
  240 +
  241 +# remove .git to save spaces
  242 +rm -rf .git
  243 +rm -v .gitattributes
  244 +rm -rf test_wavs
  245 +rm -v README.md
  246 +rm -v export*.sh
  247 +rm -v *state*
  248 +rm -v encoder-epoch-99-avg-1.onnx
  249 +rm -v decoder-epoch-99-avg-1.int8.onnx
  250 +rm -v joiner-epoch-99-avg-1.int8.onnx
  251 +
  252 +popd
  253 +
  254 +mv -v $repo ./android/SherpaOnnx/app/src/main/assets/
  255 +tree ./android/SherpaOnnx/app/src/main/assets/
  256 +git checkout .
  257 +
  258 +pushd android/SherpaOnnx/app/src/main/java/com/k2fsa/sherpa/onnx
  259 +sed -i.bak s/"type = 0"/"type = 8"/ ./MainActivity.kt
  260 +git diff
  261 +popd
  262 +
  263 +for arch in arm64-v8a armeabi-v7a x86_64 x86; do
  264 + log "------------------------------------------------------------"
  265 + log "build apk for $arch"
  266 + log "------------------------------------------------------------"
  267 + src_arch=$arch
  268 + if [ $arch == "armeabi-v7a" ]; then
  269 + src_arch=armv7-eabi
  270 + elif [ $arch == "x86_64" ]; then
  271 + src_arch=x86-64
  272 + fi
  273 +
  274 + ls -lh ./build-android-$src_arch/install/lib/*.so
  275 +
  276 + cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnx/app/src/main/jniLibs/$arch/
  277 +
  278 + pushd ./android/SherpaOnnx
  279 + ./gradlew build
  280 + popd
  281 +
  282 + mv android/SherpaOnnx/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-bilingual-en-zh.apk
  283 + ls -lh apks
  284 + rm -v ./android/SherpaOnnx/app/src/main/jniLibs/$arch/*.so
  285 +done
  286 +
  287 +git checkout .
  288 +
  289 +rm -rf ./android/SherpaOnnx/app/src/main/assets/$repo
  290 +
  291 +ls -lh apks/