From f9754f6e359438df9f02c318b529de723e09f4f4 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Tue, 7 May 2024 12:28:42 +0800 Subject: [PATCH 1/7] Add links to pre-built APKs and pre-trained models to README. (#840) --- .github/workflows/apk-asr-2pass.yaml | 174 ++++++++++ .github/workflows/apk-asr.yaml | 4 +- .github/workflows/apk-kws.yaml | 23 +- .github/workflows/apk-vad-asr.yaml | 174 ++++++++++ .github/workflows/apk-vad.yaml | 171 +++++++++ .github/workflows/apk.yaml | 73 ---- .../workflows/npm-addon-linux-aarch64.yaml | 117 +++++++ .github/workflows/test-nodejs-addon-api.yaml | 2 +- README.md | 31 +- .../app/src/main/res/values/strings.xml | 2 +- .../com/k2fsa/sherpa/onnx/MainActivity.kt | 7 +- .../app/src/main/res/values/strings.xml | 2 +- build-apk-two-pass.sh | 222 ------------ build-apk.sh | 291 ---------------- scripts/apk/build-apk-asr-2pass.sh.in | 109 ++++++ .../apk/build-apk-kws.sh | 37 +- scripts/apk/build-apk-vad-asr.sh.in | 93 +++++ .../apk/build-apk-vad.sh | 8 +- scripts/apk/generate-asr-2pass-apk-script.py | 326 ++++++++++++++++++ scripts/apk/generate-asr-apk-script.py | 104 ++++++ scripts/apk/generate-vad-asr-apk-script.py | 156 +++++++++ 21 files changed, 1512 insertions(+), 614 deletions(-) create mode 100644 .github/workflows/apk-asr-2pass.yaml create mode 100644 .github/workflows/apk-vad-asr.yaml create mode 100644 .github/workflows/apk-vad.yaml delete mode 100644 .github/workflows/apk.yaml create mode 100644 .github/workflows/npm-addon-linux-aarch64.yaml delete mode 100755 build-apk-two-pass.sh delete mode 100755 build-apk.sh create mode 100644 scripts/apk/build-apk-asr-2pass.sh.in rename build-kws-apk.sh => scripts/apk/build-apk-kws.sh (73%) create mode 100644 scripts/apk/build-apk-vad-asr.sh.in rename build-apk-vad.sh => scripts/apk/build-apk-vad.sh (86%) create mode 100755 scripts/apk/generate-asr-2pass-apk-script.py create mode 100755 scripts/apk/generate-vad-asr-apk-script.py diff --git a/.github/workflows/apk-asr-2pass.yaml b/.github/workflows/apk-asr-2pass.yaml new file mode 100644 index 000000000..36272cc38 --- /dev/null +++ b/.github/workflows/apk-asr-2pass.yaml @@ -0,0 +1,174 @@ +name: apk-asr-2pass + +on: + push: + tags: + - '*' + + workflow_dispatch: + +concurrency: + group: apk-asr-2pass-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: write + +jobs: + apk_asr_2pass: + if: github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa' + runs-on: ${{ matrix.os }} + name: apk for asr ${{ matrix.index }}/${{ matrix.total }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + total: ["2"] + index: ["0", "1"] + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # https://github.com/actions/setup-java + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' # See 'Supported distributions' for available options + java-version: '21' + + - name: ccache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: ${{ matrix.os }}-android + + - name: Display NDK HOME + shell: bash + run: | + echo "ANDROID_NDK_LATEST_HOME: ${ANDROID_NDK_LATEST_HOME}" + ls -lh ${ANDROID_NDK_LATEST_HOME} + + - name: Install Python dependencies + shell: bash + run: | + python3 -m pip install --upgrade pip jinja2 + + - name: Setup build tool version variable + shell: bash + run: | + echo "---" + ls -lh /usr/local/lib/android/ + echo "---" + + ls -lh /usr/local/lib/android/sdk + echo "---" + + ls -lh /usr/local/lib/android/sdk/build-tools + echo "---" + + BUILD_TOOL_VERSION=$(ls /usr/local/lib/android/sdk/build-tools/ | tail -n 1) + echo "BUILD_TOOL_VERSION=$BUILD_TOOL_VERSION" >> $GITHUB_ENV + echo "Last build tool version is: $BUILD_TOOL_VERSION" + + - name: Generate build script + shell: bash + run: | + cd scripts/apk + + total=${{ matrix.total }} + index=${{ matrix.index }} + + ./generate-asr-2pass-apk-script.py --total $total --index $index + + chmod +x build-apk-asr-2pass.sh + mv -v ./build-apk-asr-2pass.sh ../.. + + - name: build APK + shell: bash + run: | + export CMAKE_CXX_COMPILER_LAUNCHER=ccache + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" + cmake --version + + export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME + ./build-apk-asr-2pass.sh + + - name: Display APK + shell: bash + run: | + ls -lh ./apks/ + du -h -d1 . + + # https://github.com/marketplace/actions/sign-android-release + - uses: r0adkll/sign-android-release@v1 + name: Sign app APK + with: + releaseDirectory: ./apks + signingKeyBase64: ${{ secrets.ANDROID_SIGNING_KEY }} + alias: ${{ secrets.ANDROID_SIGNING_KEY_ALIAS }} + keyStorePassword: ${{ secrets.ANDROID_SIGNING_KEY_STORE_PASSWORD }} + env: + BUILD_TOOLS_VERSION: ${{ env.BUILD_TOOL_VERSION }} + + - name: Display APK after signing + shell: bash + run: | + ls -lh ./apks/ + du -h -d1 . + + - name: Rename APK after signing + shell: bash + run: | + cd apks + rm -fv signingKey.jks + rm -fv *.apk.idsig + rm -fv *-aligned.apk + + all_apks=$(ls -1 *-signed.apk) + echo "----" + echo $all_apks + echo "----" + for apk in ${all_apks[@]}; do + n=$(echo $apk | sed -e s/-signed//) + mv -v $apk $n + done + + cd .. + + ls -lh ./apks/ + du -h -d1 . + + - name: Display APK after rename + shell: bash + run: | + ls -lh ./apks/ + du -h -d1 . + + - name: Publish to huggingface + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + uses: nick-fields/retry@v3 + with: + max_attempts: 20 + timeout_seconds: 200 + shell: bash + command: | + git config --global user.email "csukuangfj@gmail.com" + git config --global user.name "Fangjun Kuang" + + rm -rf huggingface + export GIT_LFS_SKIP_SMUDGE=1 + + git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface + cd huggingface + git fetch + git pull + git merge -m "merge remote" --ff origin main + + mkdir -p asr-2pass + cp -v ../apks/*.apk ./asr-2pass/ + git status + git lfs track "*.apk" + git add . + git commit -m "add more apks" + git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk main diff --git a/.github/workflows/apk-asr.yaml b/.github/workflows/apk-asr.yaml index 3fdb2baac..c822c0ec8 100644 --- a/.github/workflows/apk-asr.yaml +++ b/.github/workflows/apk-asr.yaml @@ -23,8 +23,8 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - total: ["1"] - index: ["0"] + total: ["3"] + index: ["0", "1", "2"] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/apk-kws.yaml b/.github/workflows/apk-kws.yaml index e5be8f7f1..30a284f2a 100644 --- a/.github/workflows/apk-kws.yaml +++ b/.github/workflows/apk-kws.yaml @@ -16,11 +16,15 @@ permissions: jobs: apk_kws: + if: github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa' runs-on: ${{ matrix.os }} + name: apk for kws ${{ matrix.index }}/${{ matrix.total }} strategy: fail-fast: false matrix: os: [ubuntu-latest] + total: ["1"] + index: ["0"] steps: - uses: actions/checkout@v4 @@ -44,6 +48,11 @@ jobs: echo "ANDROID_NDK_LATEST_HOME: ${ANDROID_NDK_LATEST_HOME}" ls -lh ${ANDROID_NDK_LATEST_HOME} + - name: Install Python dependencies + shell: bash + run: | + python3 -m pip install --upgrade pip jinja2 + - name: Setup build tool version variable shell: bash run: | @@ -61,6 +70,16 @@ jobs: echo "BUILD_TOOL_VERSION=$BUILD_TOOL_VERSION" >> $GITHUB_ENV echo "Last build tool version is: $BUILD_TOOL_VERSION" + - name: Generate build script + shell: bash + run: | + cd scripts/apk + + total=${{ matrix.total }} + index=${{ matrix.index }} + + mv -v ./build-apk-kws.sh ../.. + - name: build APK shell: bash run: | @@ -69,13 +88,13 @@ jobs: cmake --version export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME - ./build-kws-apk.sh + ./build-apk-kws.sh - name: Display APK shell: bash run: | ls -lh ./apks/ - + du -h -d1 . # https://github.com/marketplace/actions/sign-android-release - uses: r0adkll/sign-android-release@v1 diff --git a/.github/workflows/apk-vad-asr.yaml b/.github/workflows/apk-vad-asr.yaml new file mode 100644 index 000000000..dc4d97e42 --- /dev/null +++ b/.github/workflows/apk-vad-asr.yaml @@ -0,0 +1,174 @@ +name: apk-vad-asr + +on: + push: + tags: + - '*' + + workflow_dispatch: + +concurrency: + group: apk-vad-asr-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: write + +jobs: + apk_vad_asr: + if: github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa' + runs-on: ${{ matrix.os }} + name: apk for asr ${{ matrix.index }}/${{ matrix.total }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + total: ["3"] + index: ["0", "1", "2"] + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # https://github.com/actions/setup-java + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' # See 'Supported distributions' for available options + java-version: '21' + + - name: ccache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: ${{ matrix.os }}-android + + - name: Display NDK HOME + shell: bash + run: | + echo "ANDROID_NDK_LATEST_HOME: ${ANDROID_NDK_LATEST_HOME}" + ls -lh ${ANDROID_NDK_LATEST_HOME} + + - name: Install Python dependencies + shell: bash + run: | + python3 -m pip install --upgrade pip jinja2 + + - name: Setup build tool version variable + shell: bash + run: | + echo "---" + ls -lh /usr/local/lib/android/ + echo "---" + + ls -lh /usr/local/lib/android/sdk + echo "---" + + ls -lh /usr/local/lib/android/sdk/build-tools + echo "---" + + BUILD_TOOL_VERSION=$(ls /usr/local/lib/android/sdk/build-tools/ | tail -n 1) + echo "BUILD_TOOL_VERSION=$BUILD_TOOL_VERSION" >> $GITHUB_ENV + echo "Last build tool version is: $BUILD_TOOL_VERSION" + + - name: Generate build script + shell: bash + run: | + cd scripts/apk + + total=${{ matrix.total }} + index=${{ matrix.index }} + + ./generate-vad-asr-apk-script.py --total $total --index $index + + chmod +x build-apk-vad-asr.sh + mv -v ./build-apk-vad-asr.sh ../.. + + - name: build APK + shell: bash + run: | + export CMAKE_CXX_COMPILER_LAUNCHER=ccache + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" + cmake --version + + export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME + ./build-apk-vad-asr.sh + + - name: Display APK + shell: bash + run: | + ls -lh ./apks/ + du -h -d1 . + + # https://github.com/marketplace/actions/sign-android-release + - uses: r0adkll/sign-android-release@v1 + name: Sign app APK + with: + releaseDirectory: ./apks + signingKeyBase64: ${{ secrets.ANDROID_SIGNING_KEY }} + alias: ${{ secrets.ANDROID_SIGNING_KEY_ALIAS }} + keyStorePassword: ${{ secrets.ANDROID_SIGNING_KEY_STORE_PASSWORD }} + env: + BUILD_TOOLS_VERSION: ${{ env.BUILD_TOOL_VERSION }} + + - name: Display APK after signing + shell: bash + run: | + ls -lh ./apks/ + du -h -d1 . + + - name: Rename APK after signing + shell: bash + run: | + cd apks + rm -fv signingKey.jks + rm -fv *.apk.idsig + rm -fv *-aligned.apk + + all_apks=$(ls -1 *-signed.apk) + echo "----" + echo $all_apks + echo "----" + for apk in ${all_apks[@]}; do + n=$(echo $apk | sed -e s/-signed//) + mv -v $apk $n + done + + cd .. + + ls -lh ./apks/ + du -h -d1 . + + - name: Display APK after rename + shell: bash + run: | + ls -lh ./apks/ + du -h -d1 . + + - name: Publish to huggingface + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + uses: nick-fields/retry@v3 + with: + max_attempts: 20 + timeout_seconds: 200 + shell: bash + command: | + git config --global user.email "csukuangfj@gmail.com" + git config --global user.name "Fangjun Kuang" + + rm -rf huggingface + export GIT_LFS_SKIP_SMUDGE=1 + + git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface + cd huggingface + git fetch + git pull + git merge -m "merge remote" --ff origin main + + mkdir -p vad-asr + cp -v ../apks/*.apk ./vad-asr/ + git status + git lfs track "*.apk" + git add . + git commit -m "add more apks" + git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk main diff --git a/.github/workflows/apk-vad.yaml b/.github/workflows/apk-vad.yaml new file mode 100644 index 000000000..e11edadfd --- /dev/null +++ b/.github/workflows/apk-vad.yaml @@ -0,0 +1,171 @@ +name: apk-vad + +on: + push: + tags: + - '*' + + workflow_dispatch: + +concurrency: + group: apk-vad-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: write + +jobs: + apk_vad: + if: github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa' + runs-on: ${{ matrix.os }} + name: apk for vad ${{ matrix.index }}/${{ matrix.total }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + total: ["1"] + index: ["0"] + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # https://github.com/actions/setup-java + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' # See 'Supported distributions' for available options + java-version: '21' + + - name: ccache + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: ${{ matrix.os }}-android + + - name: Display NDK HOME + shell: bash + run: | + echo "ANDROID_NDK_LATEST_HOME: ${ANDROID_NDK_LATEST_HOME}" + ls -lh ${ANDROID_NDK_LATEST_HOME} + + - name: Install Python dependencies + shell: bash + run: | + python3 -m pip install --upgrade pip jinja2 + + - name: Setup build tool version variable + shell: bash + run: | + echo "---" + ls -lh /usr/local/lib/android/ + echo "---" + + ls -lh /usr/local/lib/android/sdk + echo "---" + + ls -lh /usr/local/lib/android/sdk/build-tools + echo "---" + + BUILD_TOOL_VERSION=$(ls /usr/local/lib/android/sdk/build-tools/ | tail -n 1) + echo "BUILD_TOOL_VERSION=$BUILD_TOOL_VERSION" >> $GITHUB_ENV + echo "Last build tool version is: $BUILD_TOOL_VERSION" + + - name: Generate build script + shell: bash + run: | + cd scripts/apk + + total=${{ matrix.total }} + index=${{ matrix.index }} + + mv -v ./build-apk-vad.sh ../.. + + - name: build APK + shell: bash + run: | + export CMAKE_CXX_COMPILER_LAUNCHER=ccache + export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" + cmake --version + + export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME + ./build-apk-vad.sh + + - name: Display APK + shell: bash + run: | + ls -lh ./apks/ + du -h -d1 . + + # https://github.com/marketplace/actions/sign-android-release + - uses: r0adkll/sign-android-release@v1 + name: Sign app APK + with: + releaseDirectory: ./apks + signingKeyBase64: ${{ secrets.ANDROID_SIGNING_KEY }} + alias: ${{ secrets.ANDROID_SIGNING_KEY_ALIAS }} + keyStorePassword: ${{ secrets.ANDROID_SIGNING_KEY_STORE_PASSWORD }} + env: + BUILD_TOOLS_VERSION: ${{ env.BUILD_TOOL_VERSION }} + + - name: Display APK after signing + shell: bash + run: | + ls -lh ./apks/ + du -h -d1 . + + - name: Rename APK after signing + shell: bash + run: | + cd apks + rm -fv signingKey.jks + rm -fv *.apk.idsig + rm -fv *-aligned.apk + + all_apks=$(ls -1 *-signed.apk) + echo "----" + echo $all_apks + echo "----" + for apk in ${all_apks[@]}; do + n=$(echo $apk | sed -e s/-signed//) + mv -v $apk $n + done + + cd .. + + ls -lh ./apks/ + du -h -d1 . + + - name: Display APK after rename + shell: bash + run: | + ls -lh ./apks/ + du -h -d1 . + + - name: Publish to huggingface + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + uses: nick-fields/retry@v3 + with: + max_attempts: 20 + timeout_seconds: 200 + shell: bash + command: | + git config --global user.email "csukuangfj@gmail.com" + git config --global user.name "Fangjun Kuang" + + rm -rf huggingface + export GIT_LFS_SKIP_SMUDGE=1 + + git clone https://huggingface.co/csukuangfj/sherpa-onnx-apk huggingface + cd huggingface + git fetch + git pull + git merge -m "merge remote" --ff origin main + + mkdir -p vad + cp -v ../apks/*.apk ./vad/ + git status + git lfs track "*.apk" + git add . + git commit -m "add more apks" + git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-apk main diff --git a/.github/workflows/apk.yaml b/.github/workflows/apk.yaml deleted file mode 100644 index 6c4d9f817..000000000 --- a/.github/workflows/apk.yaml +++ /dev/null @@ -1,73 +0,0 @@ -name: apk - -on: - push: - tags: - - '*' - - workflow_dispatch: - -concurrency: - group: apk-${{ github.ref }} - cancel-in-progress: true - -permissions: - contents: write - -jobs: - apk: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - # https://github.com/actions/setup-java - - uses: actions/setup-java@v4 - with: - distribution: 'temurin' # See 'Supported distributions' for available options - java-version: '21' - - - name: ccache - uses: hendrikmuhs/ccache-action@v1.2 - with: - key: ${{ matrix.os }}-android - - - name: Display NDK HOME - shell: bash - run: | - echo "ANDROID_NDK_LATEST_HOME: ${ANDROID_NDK_LATEST_HOME}" - ls -lh ${ANDROID_NDK_LATEST_HOME} - - - name: build APK - shell: bash - run: | - export CMAKE_CXX_COMPILER_LAUNCHER=ccache - export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" - cmake --version - - export ANDROID_NDK=$ANDROID_NDK_LATEST_HOME - ./build-apk-vad.sh - ./build-apk-two-pass.sh - ./build-apk.sh - - - name: Display APK - shell: bash - run: | - ls -lh ./apks/ - - - uses: actions/upload-artifact@v4 - with: - path: ./apks/*.apk - - - name: Release APK - uses: svenstaro/upload-release-action@v2 - with: - file_glob: true - file: apks/*.apk - overwrite: true diff --git a/.github/workflows/npm-addon-linux-aarch64.yaml b/.github/workflows/npm-addon-linux-aarch64.yaml new file mode 100644 index 000000000..72aec002b --- /dev/null +++ b/.github/workflows/npm-addon-linux-aarch64.yaml @@ -0,0 +1,117 @@ +name: npm-addon-linux-aarch64 + +on: + push: + branches: + - node-addon-arm + workflow_dispatch: + +concurrency: + group: npm-addon-linux-aarch64-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + id-token: write + +jobs: + npm-addon-linux-aarch64: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + python-version: ["3.8"] + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: arm64 + + - name: Build sherpa-onnx + uses: addnab/docker-run-action@v3 + with: + image: quay.io/pypa/manylinux2014_aarch64 + options: | + --volume ${{ github.workspace }}/:/shared/ + shell: bash + run: | + uname -a + cat /etc/*release + gcc --version + cmake --version + cd /shared + + # mkdir build + # cd build + # cmake \ + # -DCMAKE_INSTALL_PREFIX=./install \ + # -DBUILD_SHARED_LIBS=ON \ + # -DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ + # -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ + # -DSHERPA_ONNX_ENABLE_BINARY=OFF \ + # .. + # make -j install + + - name: Build sherpa-onnx node-addon + if: false + shell: bash + run: | + d=$PWD + export SHERPA_ONNX_INSTALL_DIR=$d/build/install + + sudo mkdir /shared + sudo ln -s $PWD/build /shared/ + + ls -lh /shared/build + + cd scripts/node-addon-api/ + + npm i + + ./node_modules/.bin/cmake-js compile --log-level verbose + + - name: Prepare for publish + if: false + shell: bash + run: | + owner=${{ github.repository_owner }} + export owner + + echo "---" + ls -lh build/install/lib/ + sudo chown -R runner ./build + echo "---" + ls -lh build/install/lib/ + echo "---" + + # find build/install/lib/ -maxdepth 1 -type l + # find build/install/lib/ -maxdepth 1 -type l -delete + # + # echo "---" + # ls -lh build/install/lib/ + + .github/scripts/node-addon/run.sh + + - name: Display files to be published + if: false + shell: bash + run: | + ls -lh ./sherpa-onnx-node + + - name: Publish + if: false + shell: bash + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + cd ./sherpa-onnx-node + npm install + npm ci + # see https://docs.npmjs.com/generating-provenance-statements + npm publish --provenance --access public diff --git a/.github/workflows/test-nodejs-addon-api.yaml b/.github/workflows/test-nodejs-addon-api.yaml index 67eced551..5a6649846 100644 --- a/.github/workflows/test-nodejs-addon-api.yaml +++ b/.github/workflows/test-nodejs-addon-api.yaml @@ -39,7 +39,7 @@ jobs: strategy: fail-fast: false matrix: - os: [macos-11, macos-14, ubuntu-20.04, ubuntu-22.04, windows-latest] + os: [macos-11, macos-14, ubuntu-20.04, ubuntu-22.04] #, windows-latest] node-version: ["16", "17", "18", "19", "21", "22"] python-version: ["3.8"] diff --git a/README.md b/README.md index 4f4246ebb..d8cb1df1f 100644 --- a/README.md +++ b/README.md @@ -37,12 +37,37 @@ with the following APIs - Kotlin - Swift +# Links for pre-built Android APKs + +| Description | URL | 中国用户 | +|--------------------------------|-----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------| +| Streaming speech recognition | [Address](https://k2-fsa.github.io/sherpa/onnx/android/apk.html) | [点此](https://k2-fsa.github.io/sherpa/onnx/android/apk-cn.html) | +| Text-to-speech | [Address](https://k2-fsa.github.io/sherpa/onnx/tts/apk-engine.html) | [点此](https://k2-fsa.github.io/sherpa/onnx/tts/apk-engine-cn.html) | +|Voice activity detection (VAD) | [Address](https://k2-fsa.github.io/sherpa/onnx/vad/apk.html) | [点此](https://k2-fsa.github.io/sherpa/onnx/vad/apk-cn.html)| +|VAD + non-streaming speech recognition| [Address](https://k2-fsa.github.io/sherpa/onnx/vad/apk-asr.html)| [点此](https://k2-fsa.github.io/sherpa/onnx/vad/apk-asr-cn.html)| +|Two-pass speech recognition| [Address](https://k2-fsa.github.io/sherpa/onnx/android/apk-2pass.html)| [点此](https://k2-fsa.github.io/sherpa/onnx/android/apk-2pass-cn.html)| +| Audio tagging | [Address](https://k2-fsa.github.io/sherpa/onnx/audio-tagging/apk.html) | [点此](https://k2-fsa.github.io/sherpa/onnx/audio-tagging/apk-cn.html) | +| Audio tagging (WearOS) | [Address](https://k2-fsa.github.io/sherpa/onnx/audio-tagging/apk-wearos.html) | [点此](https://k2-fsa.github.io/sherpa/onnx/audio-tagging/apk-wearos-cn.html) | +| Speaker identification | [Address](https://k2-fsa.github.io/sherpa/onnx/speaker-identification/apk.html) | [点此](https://k2-fsa.github.io/sherpa/onnx/speaker-identification/apk-cn.html) | +| Spoken language identification | [Address](https://k2-fsa.github.io/sherpa/onnx/spoken-language-identification/apk.html) | [点此](https://k2-fsa.github.io/sherpa/onnx/spoken-language-identification/apk-cn.html) | +|Keyword spotting| [Address](https://k2-fsa.github.io/sherpa/onnx/kws/apk.html)| [点此](https://k2-fsa.github.io/sherpa/onnx/kws/apk-cn.html)| + +# Links for pre-trained models + +| Description | URL | +|--------------------------------|--------------------------------------------------------------------------------------------------------------------------------| +| Speech recognition (speech to text, ASR) | [Address](https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models) | +| Text-to-speech (TTS) | [Address](https://github.com/k2-fsa/sherpa-onnx/releases/tag/tts-models) | +| VAD | [Address](https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/silero_vad.onnx)| +| Keyword spotting |[Address](https://github.com/k2-fsa/sherpa-onnx/releases/tag/kws-models)| +| Audio tagging | [Address](https://github.com/k2-fsa/sherpa-onnx/releases/tag/audio-tagging-models)| +| Speaker identification (Speaker ID) | [Address](https://github.com/k2-fsa/sherpa-onnx/releases/tag/speaker-recongition-models)| +| Spoken language identification (Language ID) | See multi-lingual Whisper ASR models from [Speech recognition](https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models) | +| Punctuation| [Address](https://github.com/k2-fsa/sherpa-onnx/releases/tag/punctuation-models)| + # Useful links - Documentation: https://k2-fsa.github.io/sherpa/onnx/ -- APK for the text-to-speech engine: https://k2-fsa.github.io/sherpa/onnx/tts/apk-engine.html -- APK for speaker identification: https://k2-fsa.github.io/sherpa/onnx/speaker-identification/apk.html -- APK for speech recognition: https://github.com/k2-fsa/sherpa-onnx/releases/ - Bilibili 演示视频: https://search.bilibili.com/all?keyword=%E6%96%B0%E4%B8%80%E4%BB%A3Kaldi # How to reach us diff --git a/android/SherpaOnnxVad/app/src/main/res/values/strings.xml b/android/SherpaOnnxVad/app/src/main/res/values/strings.xml index 8f8d0e5a1..c087845a9 100644 --- a/android/SherpaOnnxVad/app/src/main/res/values/strings.xml +++ b/android/SherpaOnnxVad/app/src/main/res/values/strings.xml @@ -1,5 +1,5 @@ - VAD + VAD: Next-gen Kaldi Click the Start button to play Silero VAD with Next-gen Kaldi. Start diff --git a/android/SherpaOnnxVadAsr/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt b/android/SherpaOnnxVadAsr/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt index a7d051853..e221553c2 100644 --- a/android/SherpaOnnxVadAsr/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt +++ b/android/SherpaOnnxVadAsr/app/src/main/java/com/k2fsa/sherpa/onnx/MainActivity.kt @@ -8,7 +8,6 @@ import android.media.MediaRecorder import android.os.Bundle import android.text.method.ScrollingMovementMethod import android.util.Log -import android.view.View import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity @@ -200,12 +199,12 @@ class MainActivity : AppCompatActivity() { // Please change getOfflineModelConfig() to add new models // See https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html // for a list of available models - val secondType = 0 - Log.i(TAG, "Select model type ${secondType} for the second pass") + val asrModelType = 0 + Log.i(TAG, "Select model type ${asrModelType} for ASR") val config = OfflineRecognizerConfig( featConfig = getFeatureConfig(sampleRate = sampleRateInHz, featureDim = 80), - modelConfig = getOfflineModelConfig(type = secondType)!!, + modelConfig = getOfflineModelConfig(type = asrModelType)!!, ) offlineRecognizer = OfflineRecognizer( diff --git a/android/SherpaOnnxVadAsr/app/src/main/res/values/strings.xml b/android/SherpaOnnxVadAsr/app/src/main/res/values/strings.xml index e356681bf..736536807 100644 --- a/android/SherpaOnnxVadAsr/app/src/main/res/values/strings.xml +++ b/android/SherpaOnnxVadAsr/app/src/main/res/values/strings.xml @@ -1,5 +1,5 @@ - VAD+ASR + VAD+ASR: Next-gen Kaldi Click the Start button to play speech-to-text with Next-gen Kaldi. \n \n\n\n diff --git a/build-apk-two-pass.sh b/build-apk-two-pass.sh deleted file mode 100755 index 20bd6d435..000000000 --- a/build-apk-two-pass.sh +++ /dev/null @@ -1,222 +0,0 @@ -#!/usr/bin/env bash - -# Please set the environment variable ANDROID_NDK -# before running this script - -# Inside the $ANDROID_NDK directory, you can find a binary ndk-build -# and some other files like the file "build/cmake/android.toolchain.cmake" - -set -e - -log() { - # This function is from espnet - local fname=${BASH_SOURCE[1]##*/} - echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*" -} - -SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) - -log "Building two-pass APK for sherpa-onnx v${SHERPA_ONNX_VERSION}" - -log "====================arm64-v8a=================" -./build-android-arm64-v8a.sh -log "====================armv7-eabi================" -./build-android-armv7-eabi.sh -log "====================x86-64====================" -./build-android-x86-64.sh -log "====================x86====================" -./build-android-x86.sh - -mkdir -p apks - -log "Download 1st pass streaming model (English)" - -# Download the model -# 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 -repo_url=https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-20M-2023-02-17 -log "$repo_url" - -log "Start downloading ${repo_url}" -repo=$(basename $repo_url) -log "Download pretrained model from $repo_url" -GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url -pushd $repo -git lfs pull --include "*.onnx" - -# remove .git to save spaces -rm -rf .git -rm README.md -rm -rf test_wavs -rm .gitattributes -rm export-onnx*.sh - -rm encoder-epoch-99-avg-1.onnx -rm decoder-epoch-99-avg-1.int8.onnx -rm joiner-epoch-99-avg-1.onnx - -ls -lh -popd - -mv -v $repo ./android/SherpaOnnx2Pass/app/src/main/assets/ -tree ./android/SherpaOnnx2Pass/app/src/main/assets/ -repo_1st=$repo - -# https://k2-fsa.github.io/sherpa/onnx/pretrained_models/whisper/tiny.en.html -repo_url=https://huggingface.co/csukuangfj/sherpa-onnx-whisper-tiny.en -log "$repo_url" - -log "Start downloading ${repo_url}" -repo=$(basename $repo_url) -log "Download pretrained model from $repo_url" -GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url -pushd $repo -git lfs pull --include "*.onnx" - -# remove .git to save spaces -rm -rf .git -rm -fv README.md -rm -rf test_wavs -rm .gitattributes - -rm -fv *.ort -rm tiny.en-encoder.onnx -rm tiny.en-decoder.onnx - -ls -lh -popd - -mv -v $repo ./android/SherpaOnnx2Pass/app/src/main/assets/ -tree ./android/SherpaOnnx2Pass/app/src/main/assets/ -repo_2nd=$repo - -pushd android/SherpaOnnx2Pass/app/src/main/java/com/k2fsa/sherpa/onnx -# sed -i.bak s/"firstType = 1"/"firstType = 1"/ ./MainActivity.kt -sed -i.bak s/"secondType = 1"/"secondType = 2"/ ./MainActivity.kt -git diff -popd - -for arch in arm64-v8a armeabi-v7a x86_64 x86; do - log "------------------------------------------------------------" - log "build apk for $arch" - log "------------------------------------------------------------" - src_arch=$arch - if [ $arch == "armeabi-v7a" ]; then - src_arch=armv7-eabi - elif [ $arch == "x86_64" ]; then - src_arch=x86-64 - fi - - ls -lh ./build-android-$src_arch/install/lib/*.so - - cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnx2Pass/app/src/main/jniLibs/$arch/ - - pushd ./android/SherpaOnnx2Pass - ./gradlew build - popd - - mv android/SherpaOnnx2Pass/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-en-2pass-whisper-tiny.en.apk - ls -lh apks - rm -v ./android/SherpaOnnx2Pass/app/src/main/jniLibs/$arch/*.so -done - -git checkout . - -rm -rf ./android/SherpaOnnx2Pass/app/src/main/assets/$repo_1st -rm -rf ./android/SherpaOnnx2Pass/app/src/main/assets/$repo_2nd - -log "==================================================" -log " two-pass Chinese " -log "==================================================" - -log "Download 1st pass streaming model (Chinese)" -# https://k2-fsa.github.io/sherpa/onnx/pretrained_models/online-transducer/zipformer-transducer-models.html#sherpa-onnx-streaming-zipformer-zh-14m-2023-02-23 -repo_url=https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-zh-14M-2023-02-23 -log "$repo_url" - -log "Start downloading ${repo_url}" -repo=$(basename $repo_url) -log "Download pretrained model from $repo_url" -GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url -pushd $repo -git lfs pull --include "*.onnx" - -# remove .git to save spaces -rm -rf .git -rm README.md -rm -rf test_wavs -rm .gitattributes -rm export-onnx*.sh - -rm encoder-epoch-99-avg-1.onnx -rm decoder-epoch-99-avg-1.int8.onnx -rm joiner-epoch-99-avg-1.onnx - -ls -lh -popd - -mv -v $repo ./android/SherpaOnnx2Pass/app/src/main/assets/ -tree ./android/SherpaOnnx2Pass/app/src/main/assets/ -repo_1st=$repo - -# https://k2-fsa.github.io/sherpa/onnx/pretrained_models/offline-paraformer/paraformer-models.html#csukuangfj-sherpa-onnx-paraformer-zh-2023-03-28-chinese -repo_url=https://huggingface.co/csukuangfj/sherpa-onnx-paraformer-zh-2023-03-28 -log "$repo_url" - -log "Start downloading ${repo_url}" -repo=$(basename $repo_url) -log "Download pretrained model from $repo_url" -GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url -pushd $repo -git lfs pull --include "*.onnx" - -# remove .git to save spaces -rm -rf .git -rm README.md -rm -rf test_wavs -rm .gitattributes - -rm model.onnx - -ls -lh -popd - -mv -v $repo ./android/SherpaOnnx2Pass/app/src/main/assets/ -tree ./android/SherpaOnnx2Pass/app/src/main/assets/ -repo_2nd=$repo - -pushd android/SherpaOnnx2Pass/app/src/main/java/com/k2fsa/sherpa/onnx -sed -i.bak s/"firstType = 1"/"firstType = 0"/ ./MainActivity.kt -sed -i.bak s/"secondType = 1"/"secondType = 0"/ ./MainActivity.kt -git diff -popd - -for arch in arm64-v8a armeabi-v7a x86_64 x86; do - log "------------------------------------------------------------" - log "build apk for $arch" - log "------------------------------------------------------------" - src_arch=$arch - if [ $arch == "armeabi-v7a" ]; then - src_arch=armv7-eabi - elif [ $arch == "x86_64" ]; then - src_arch=x86-64 - fi - - ls -lh ./build-android-$src_arch/install/lib/*.so - - cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnx2Pass/app/src/main/jniLibs/$arch/ - - pushd ./android/SherpaOnnx2Pass - ./gradlew build - popd - - mv android/SherpaOnnx2Pass/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-zh-2pass-paraformer.apk - ls -lh apks - rm -v ./android/SherpaOnnx2Pass/app/src/main/jniLibs/$arch/*.so -done - -git checkout . - -rm -rf ./android/SherpaOnnx2Pass/app/src/main/assets/$repo_1st -rm -rf ./android/SherpaOnnx2Pass/app/src/main/assets/$repo_2nd - -ls -lh apks/ diff --git a/build-apk.sh b/build-apk.sh deleted file mode 100755 index 28fd9a68f..000000000 --- a/build-apk.sh +++ /dev/null @@ -1,291 +0,0 @@ -#!/usr/bin/env bash - -# Please set the environment variable ANDROID_NDK -# before running this script - -# Inside the $ANDROID_NDK directory, you can find a binary ndk-build -# and some other files like the file "build/cmake/android.toolchain.cmake" - -set -e - -log() { - # This function is from espnet - local fname=${BASH_SOURCE[1]##*/} - echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*" -} - -SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) - -log "Building APK for sherpa-onnx v${SHERPA_ONNX_VERSION}" - -log "====================arm64-v8a=================" -./build-android-arm64-v8a.sh -log "====================armv7-eabi================" -./build-android-armv7-eabi.sh -log "====================x86-64====================" -./build-android-x86-64.sh -log "====================x86====================" -./build-android-x86.sh - - -mkdir -p apks - -log "https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-06-26" - -# Download the model -# 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 -repo_url=https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-06-26 -log "Start testing ${repo_url}" -repo=$(basename $repo_url) -log "Download pretrained model and test-data from $repo_url" -GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url -pushd $repo -git lfs pull --include "*.onnx" - -# remove .git to save spaces -rm -rf .git -rm README.md -rm -v *64* -rm -v encoder-epoch-99-avg-1-chunk-16-left-128.onnx -rm -v decoder-epoch-99-avg-1-chunk-16-left-128.int8.onnx -rm -v joiner-epoch-99-avg-1-chunk-16-left-128.int8.onnx -rm -rfv test_wavs -rm -v *.sh -ls -lh -popd - -mv -v $repo ./android/SherpaOnnx/app/src/main/assets/ -tree ./android/SherpaOnnx/app/src/main/assets/ - -pushd android/SherpaOnnx/app/src/main/java/com/k2fsa/sherpa/onnx -sed -i.bak s/"type = 0"/"type = 6"/ ./MainActivity.kt -git diff -popd - -for arch in arm64-v8a armeabi-v7a x86_64 x86; do - log "------------------------------------------------------------" - log "build apk for $arch" - log "------------------------------------------------------------" - src_arch=$arch - if [ $arch == "armeabi-v7a" ]; then - src_arch=armv7-eabi - elif [ $arch == "x86_64" ]; then - src_arch=x86-64 - fi - - ls -lh ./build-android-$src_arch/install/lib/*.so - - cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnx/app/src/main/jniLibs/$arch/ - - pushd ./android/SherpaOnnx - ./gradlew build - popd - - mv android/SherpaOnnx/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-en.apk - ls -lh apks - rm -v ./android/SherpaOnnx/app/src/main/jniLibs/$arch/*.so -done - -git checkout . - -rm -rf ./android/SherpaOnnx/app/src/main/assets/$repo - -# type 3, encoder int8, zh -log "https://huggingface.co/pkufool/icefall-asr-zipformer-streaming-wenetspeech-20230615" -# see -# https://k2-fsa.github.io/sherpa/onnx/pretrained_models/online-transducer/zipformer-transducer-models.html#pkufool-icefall-asr-zipformer-streaming-wenetspeech-20230615-chinese - -# Download the model -repo_url=https://huggingface.co/pkufool/icefall-asr-zipformer-streaming-wenetspeech-20230615 -log "Start testing ${repo_url}" -repo=$(basename $repo_url) -log "Download pretrained model and test-data from $repo_url" -GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url -pushd $repo -git lfs pull --include "*.onnx" - -# remove .git to save spaces -rm -rf .git -rm README.md -rm -rf logs -rm -rf scripts -rm -rf test_wavs -rm -rf data/.DS_Store -rm data/lang_char/*.pt -rm data/lang_char/lexicon.txt -rm data/lang_char/words.txt -rm -v exp/*.pt -rm -v exp/*32* -rm -v exp/*256* -rm -v exp/encoder-epoch-12-avg-4-chunk-16-left-128.onnx -rm -v exp/decoder-epoch-12-avg-4-chunk-16-left-128.int8.onnx -rm -v exp/joiner-epoch-12-avg-4-chunk-16-left-128.int8.onnx -rm -rf exp/tensorboard - -popd - -mv -v $repo ./android/SherpaOnnx/app/src/main/assets/ -tree ./android/SherpaOnnx/app/src/main/assets/ -git checkout . - -pushd android/SherpaOnnx/app/src/main/java/com/k2fsa/sherpa/onnx -sed -i.bak s/"type = 0"/"type = 3"/ ./MainActivity.kt -git diff -popd - -for arch in arm64-v8a armeabi-v7a x86_64 x86; do - log "------------------------------------------------------------" - log "build apk for $arch" - log "------------------------------------------------------------" - src_arch=$arch - if [ $arch == "armeabi-v7a" ]; then - src_arch=armv7-eabi - elif [ $arch == "x86_64" ]; then - src_arch=x86-64 - fi - - ls -lh ./build-android-$src_arch/install/lib/*.so - - cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnx/app/src/main/jniLibs/$arch/ - - pushd ./android/SherpaOnnx - ./gradlew build - popd - - mv android/SherpaOnnx/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-zh.apk - ls -lh apks - rm -v ./android/SherpaOnnx/app/src/main/jniLibs/$arch/*.so -done - -git checkout . - -rm -rf ./android/SherpaOnnx/app/src/main/assets/$repo - -# type 7, encoder int8, french -log "https://huggingface.co/shaojieli/sherpa-onnx-streaming-zipformer-fr-2023-04-14" -# see -# 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 - -# Download the model -repo_url=https://huggingface.co/shaojieli/sherpa-onnx-streaming-zipformer-fr-2023-04-14 -log "Start testing ${repo_url}" -repo=$(basename $repo_url) -log "Download pretrained model and test-data from $repo_url" -GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url -pushd $repo -git lfs pull --include "*.onnx" - -# remove .git to save spaces -rm -rf .git -rm -v .gitattributes -rm -rf test_wavs -rm -v README.md -rm -v encoder-epoch-29-avg-9-with-averaged-model.onnx -rm -v decoder-epoch-29-avg-9-with-averaged-model.int8.onnx -rm -v joiner-epoch-29-avg-9-with-averaged-model.int8.onnx -rm -v export*.sh - -popd - -mv -v $repo ./android/SherpaOnnx/app/src/main/assets/ -tree ./android/SherpaOnnx/app/src/main/assets/ -git checkout . - -pushd android/SherpaOnnx/app/src/main/java/com/k2fsa/sherpa/onnx -sed -i.bak s/"type = 0"/"type = 7"/ ./MainActivity.kt -git diff -popd - -for arch in arm64-v8a armeabi-v7a x86_64 x86; do - log "------------------------------------------------------------" - log "build apk for $arch" - log "------------------------------------------------------------" - src_arch=$arch - if [ $arch == "armeabi-v7a" ]; then - src_arch=armv7-eabi - elif [ $arch == "x86_64" ]; then - src_arch=x86-64 - fi - - ls -lh ./build-android-$src_arch/install/lib/*.so - - cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnx/app/src/main/jniLibs/$arch/ - - pushd ./android/SherpaOnnx - ./gradlew build - popd - - mv android/SherpaOnnx/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-fr.apk - ls -lh apks - rm -v ./android/SherpaOnnx/app/src/main/jniLibs/$arch/*.so -done - -git checkout . - -rm -rf ./android/SherpaOnnx/app/src/main/assets/$repo - -# type 8, encoder int8, Binglual English + Chinese -log "https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20" -# see -# 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 - -# Download the model -repo_url=https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20 -log "Start testing ${repo_url}" -repo=$(basename $repo_url) -log "Download pretrained model and test-data from $repo_url" -GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url -pushd $repo -git lfs pull --include "*.onnx" - -# remove .git to save spaces -rm -rf .git -rm -v .gitattributes -rm -rf test_wavs -rm -v README.md -rm -v export*.sh -rm -v *state* -rm -v encoder-epoch-99-avg-1.onnx -rm -v decoder-epoch-99-avg-1.int8.onnx -rm -v joiner-epoch-99-avg-1.int8.onnx - -popd - -mv -v $repo ./android/SherpaOnnx/app/src/main/assets/ -tree ./android/SherpaOnnx/app/src/main/assets/ -git checkout . - -pushd android/SherpaOnnx/app/src/main/java/com/k2fsa/sherpa/onnx -sed -i.bak s/"type = 0"/"type = 8"/ ./MainActivity.kt -git diff -popd - -for arch in arm64-v8a armeabi-v7a x86_64 x86; do - log "------------------------------------------------------------" - log "build apk for $arch" - log "------------------------------------------------------------" - src_arch=$arch - if [ $arch == "armeabi-v7a" ]; then - src_arch=armv7-eabi - elif [ $arch == "x86_64" ]; then - src_arch=x86-64 - fi - - ls -lh ./build-android-$src_arch/install/lib/*.so - - cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnx/app/src/main/jniLibs/$arch/ - - pushd ./android/SherpaOnnx - ./gradlew build - popd - - mv android/SherpaOnnx/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-bilingual-en-zh.apk - ls -lh apks - rm -v ./android/SherpaOnnx/app/src/main/jniLibs/$arch/*.so -done - -git checkout . - -rm -rf ./android/SherpaOnnx/app/src/main/assets/$repo - -ls -lh apks/ diff --git a/scripts/apk/build-apk-asr-2pass.sh.in b/scripts/apk/build-apk-asr-2pass.sh.in new file mode 100644 index 000000000..24c2cd3ea --- /dev/null +++ b/scripts/apk/build-apk-asr-2pass.sh.in @@ -0,0 +1,109 @@ +#!/usr/bin/env bash +# +# Auto generated! Please DO NOT EDIT! + +# Please set the environment variable ANDROID_NDK +# before running this script + +# Inside the $ANDROID_NDK directory, you can find a binary ndk-build +# and some other files like the file "build/cmake/android.toolchain.cmake" + +set -ex + +log() { + # This function is from espnet + local fname=${BASH_SOURCE[1]##*/} + echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*" +} + +SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) + +log "Building streaming ASR two-pass APK for sherpa-onnx v${SHERPA_ONNX_VERSION}" + +export SHERPA_ONNX_ENABLE_TTS=OFF + +log "====================arm64-v8a=================" +./build-android-arm64-v8a.sh +log "====================armv7-eabi================" +./build-android-armv7-eabi.sh +log "====================x86-64====================" +./build-android-x86-64.sh +log "====================x86====================" +./build-android-x86.sh + +mkdir -p apks + +{% for first, second in model_list %} +pushd ./android/SherpaOnnx2Pass/app/src/main/assets/ + +model_name1={{ first.model_name }} +model_name=$model_name1 +type1={{ first.idx }} +lang1={{ first.lang }} +short_name1={{ first.short_name }} + +curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/${model_name1}.tar.bz2 +tar xvf ${model_name1}.tar.bz2 + +{{ first.cmd }} + +rm -rf *.tar.bz2 +ls -lh $model_name1 + +model_name2={{ second.model_name }} +model_name=$model_name2 +type2={{ second.idx }} +lang2={{ second.lang }} +short_name2={{ second.short_name }} + +curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/${model_name2}.tar.bz2 +tar xvf ${model_name2}.tar.bz2 + +{{ second.cmd }} + +rm -rf *.tar.bz2 +ls -lh $model_name2 + +popd +# Now we are at the project root directory + +git checkout . +pushd android/SherpaOnnx2Pass/app/src/main/java/com/k2fsa/sherpa/onnx +sed -i.bak s/"firstType = 9/firstType = $type1/" ./MainActivity.kt +sed -i.bak s/"secondType = 0/secondType = $type2/" ./MainActivity.kt +git diff +popd + +for arch in arm64-v8a armeabi-v7a x86_64 x86; do + log "------------------------------------------------------------" + log "build ASR apk for $arch" + log "------------------------------------------------------------" + src_arch=$arch + if [ $arch == "armeabi-v7a" ]; then + src_arch=armv7-eabi + elif [ $arch == "x86_64" ]; then + src_arch=x86-64 + fi + + ls -lh ./build-android-$src_arch/install/lib/*.so + + cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnx2Pass/app/src/main/jniLibs/$arch/ + + pushd ./android/SherpaOnnx2Pass + sed -i.bak s/2048/9012/g ./gradle.properties + git diff ./gradle.properties + ./gradlew assembleRelease + popd + + mv android/SherpaOnnx2Pass/app/build/outputs/apk/release/app-release-unsigned.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-asr_2pass-$lang1-${short_name1}_${short_name2}.apk + ls -lh apks + rm -v ./android/SherpaOnnx2Pass/app/src/main/jniLibs/$arch/*.so +done + +rm -rf ./android/SherpaOnnx2Pass/app/src/main/assets/$model_name1 +rm -rf ./android/SherpaOnnx2Pass/app/src/main/assets/$model_name2 +{% endfor %} + +git checkout . + +ls -lh apks/ diff --git a/build-kws-apk.sh b/scripts/apk/build-apk-kws.sh similarity index 73% rename from build-kws-apk.sh rename to scripts/apk/build-apk-kws.sh index 8a59f6f61..a87e9b0eb 100755 --- a/build-kws-apk.sh +++ b/scripts/apk/build-apk-kws.sh @@ -18,6 +18,8 @@ SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " log "Building keyword spotting APK for sherpa-onnx v${SHERPA_ONNX_VERSION}" +export SHERPA_ONNX_ENABLE_TTS=OFF + log "====================arm64-v8a=================" ./build-android-arm64-v8a.sh log "====================armv7-eabi================" @@ -34,14 +36,17 @@ repo=sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01 if [ ! -d ./android/SherpaOnnxKws/app/src/main/assets/$repo ]; then - repo_url=https://github.com/pkufool/keyword-spotting-models/releases/download/v0.1/sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01.tar.bz + repo_url=https://github.com/k2-fsa/sherpa-onnx/releases/download/kws-models/sherpa-onnx-kws-zipformer-wenetspeech-3.3M-2024-01-01.tar.bz2 log "Start testing ${repo_url}" - log "Download pretrained model and test-data from $repo_url" - wget -c -qq $repo_url - tar jxvf ${repo}.tar.bz + log "Download pretrained model from $repo_url" + curl -SL -O $repo_url + tar jxvf ${repo}.tar.bz2 + rm ${repo}.tar.bz2 pushd $repo + rm configuration.json + rm keywords_raw.txt rm *.int8.onnx rm README.md rm -rfv test_wavs @@ -69,10 +74,13 @@ for arch in arm64-v8a armeabi-v7a x86_64 x86; do cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnxKws/app/src/main/jniLibs/$arch/ pushd ./android/SherpaOnnxKws - ./gradlew build + sed -i.bak s/2048/9012/g ./gradle.properties + git diff ./gradle.properties + ./gradlew assembleRelease popd - mv android/SherpaOnnxKws/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-kws-wenetspeech-zh-${SHERPA_ONNX_VERSION}-$arch.apk + mv android/SherpaOnnxKws/app/build/outputs/apk/release/app-release-unsigned.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-kws-zh-wenetspeech-zipformer.apk + ls -lh apks rm -v ./android/SherpaOnnxKws/app/src/main/jniLibs/$arch/*.so done @@ -85,13 +93,16 @@ rm -rf ./android/SherpaOnnxKws/app/src/main/assets/$repo repo=sherpa-onnx-kws-zipformer-gigaspeech-3.3M-2024-01-01 if [ ! -d ./android/SherpaOnnxKws/app/src/main/assets/$repo ]; then - repo_url=https://github.com/pkufool/keyword-spotting-models/releases/download/v0.1/sherpa-onnx-kws-zipformer-gigaspeech-3.3M-2024-01-01.tar.bz + repo_url=https://github.com/k2-fsa/sherpa-onnx/releases/download/kws-models/sherpa-onnx-kws-zipformer-gigaspeech-3.3M-2024-01-01.tar.bz2 log "Start testing ${repo_url}" - log "Download pretrained model and test-data from $repo_url" - wget -qq $repo_url - tar jxvf ${repo}.tar.bz + log "Download pretrained model from $repo_url" + curl -SL -O $repo_url + tar jxvf ${repo}.tar.bz2 + rm ${repo}.tar.bz2 pushd $repo + rm bpe.model + rm keywords_raw.txt rm *.int8.onnx rm README.md rm -rfv test_wavs @@ -124,10 +135,12 @@ for arch in arm64-v8a armeabi-v7a x86_64 x86; do cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnxKws/app/src/main/jniLibs/$arch/ pushd ./android/SherpaOnnxKws - ./gradlew build + sed -i.bak s/2048/9012/g ./gradle.properties + git diff ./gradle.properties + ./gradlew assembleRelease popd - mv android/SherpaOnnxKws/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-kws-gigaspeech-en-${SHERPA_ONNX_VERSION}-$arch.apk + mv android/SherpaOnnxKws/app/build/outputs/apk/release/app-release-unsigned.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-kws-en-gigaspeech-zipformer.apk ls -lh apks rm -v ./android/SherpaOnnxKws/app/src/main/jniLibs/$arch/*.so done diff --git a/scripts/apk/build-apk-vad-asr.sh.in b/scripts/apk/build-apk-vad-asr.sh.in new file mode 100644 index 000000000..eb79eab5e --- /dev/null +++ b/scripts/apk/build-apk-vad-asr.sh.in @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +# +# Auto generated! Please DO NOT EDIT! + +# Please set the environment variable ANDROID_NDK +# before running this script + +# Inside the $ANDROID_NDK directory, you can find a binary ndk-build +# and some other files like the file "build/cmake/android.toolchain.cmake" + +set -ex + +log() { + # This function is from espnet + local fname=${BASH_SOURCE[1]##*/} + echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*" +} + +SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) + +log "Building streaming VAD + ASR APK for sherpa-onnx v${SHERPA_ONNX_VERSION}" + +export SHERPA_ONNX_ENABLE_TTS=OFF + +log "====================arm64-v8a=================" +./build-android-arm64-v8a.sh +log "====================armv7-eabi================" +./build-android-armv7-eabi.sh +log "====================x86-64====================" +./build-android-x86-64.sh +log "====================x86====================" +./build-android-x86.sh + +mkdir -p apks + +{% for model in model_list %} +pushd ./android/SherpaOnnxVadAsr/app/src/main/assets/ +model_name={{ model.model_name }} +type={{ model.idx }} +lang={{ model.lang }} +short_name={{ model.short_name }} + +curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/${model_name}.tar.bz2 +tar xvf ${model_name}.tar.bz2 + +{{ model.cmd }} + +rm -rf *.tar.bz2 +ls -lh $model_name + +curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/silero_vad.onnx + +popd +# Now we are at the project root directory + +git checkout . +pushd android/SherpaOnnxVadAsr/app/src/main/java/com/k2fsa/sherpa/onnx +sed -i.bak s/"asrModelType = 0/asrModelType = $type/" ./MainActivity.kt +git diff +popd + +for arch in arm64-v8a armeabi-v7a x86_64 x86; do + log "------------------------------------------------------------" + log "build ASR apk for $arch" + log "------------------------------------------------------------" + src_arch=$arch + if [ $arch == "armeabi-v7a" ]; then + src_arch=armv7-eabi + elif [ $arch == "x86_64" ]; then + src_arch=x86-64 + fi + + ls -lh ./build-android-$src_arch/install/lib/*.so + + cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnxVadAsr/app/src/main/jniLibs/$arch/ + + pushd ./android/SherpaOnnxVadAsr + sed -i.bak s/2048/9012/g ./gradle.properties + git diff ./gradle.properties + ./gradlew assembleRelease + popd + + mv android/SherpaOnnxVadAsr/app/build/outputs/apk/release/app-release-unsigned.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-vad_asr-$lang-$short_name.apk + ls -lh apks + rm -v ./android/SherpaOnnxVadAsr/app/src/main/jniLibs/$arch/*.so +done + +rm -rf ./android/SherpaOnnxVadAsr/app/src/main/assets/$model_name +{% endfor %} + +git checkout . + +ls -lh apks/ diff --git a/build-apk-vad.sh b/scripts/apk/build-apk-vad.sh similarity index 86% rename from build-apk-vad.sh rename to scripts/apk/build-apk-vad.sh index aa45f5724..8a2f05615 100755 --- a/build-apk-vad.sh +++ b/scripts/apk/build-apk-vad.sh @@ -18,6 +18,8 @@ SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " log "Building APK for sherpa-onnx v${SHERPA_ONNX_VERSION}" +export SHERPA_ONNX_ENABLE_TTS=OFF + log "====================arm64-v8a=================" ./build-android-arm64-v8a.sh log "====================armv7-eabi================" @@ -53,10 +55,12 @@ for arch in arm64-v8a armeabi-v7a x86_64 x86; do cp -v ./build-android-$src_arch/install/lib/*.so ./android/SherpaOnnxVad/app/src/main/jniLibs/$arch/ pushd ./android/SherpaOnnxVad - ./gradlew build + sed -i.bak s/2048/9012/g ./gradle.properties + git diff ./gradle.properties + ./gradlew assembleRelease popd - mv android/SherpaOnnxVad/app/build/outputs/apk/debug/app-debug.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-silero-vad.apk + mv android/SherpaOnnxVad/app/build/outputs/apk/release/app-release-unsigned.apk ./apks/sherpa-onnx-${SHERPA_ONNX_VERSION}-$arch-silero_vad.apk ls -lh apks rm -v ./android/SherpaOnnxVad/app/src/main/jniLibs/$arch/*.so done diff --git a/scripts/apk/generate-asr-2pass-apk-script.py b/scripts/apk/generate-asr-2pass-apk-script.py new file mode 100755 index 000000000..8b0948a96 --- /dev/null +++ b/scripts/apk/generate-asr-2pass-apk-script.py @@ -0,0 +1,326 @@ +#!/usr/bin/env python3 + +import argparse +from dataclasses import dataclass +from typing import List, Optional + +import jinja2 + + +def get_args(): + parser = argparse.ArgumentParser() + parser.add_argument( + "--total", + type=int, + default=1, + help="Number of runners", + ) + parser.add_argument( + "--index", + type=int, + default=0, + help="Index of the current runner", + ) + return parser.parse_args() + + +@dataclass +class Model: + # We will download + # https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/{model_name}.tar.bz2 + model_name: str + + # The type of the model, e..g, 0, 1, 2. It is hardcoded in the kotlin code + idx: int + + # e.g., zh, en, zh_en + lang: str + + # e.g., whisper, paraformer, zipformer + short_name: str = "" + + # cmd is used to remove extra file from the model directory + cmd: str = "" + + +def get_2nd_models(): + models = [ + Model( + model_name="sherpa-onnx-whisper-tiny.en", + idx=2, + lang="en", + short_name="whisper_tiny", + cmd=""" + pushd $model_name + rm -v tiny.en-encoder.onnx + rm -v tiny.en-decoder.onnx + rm -rf test_wavs + rm -v *.py + rm -v requirements.txt + rm -v .gitignore + rm -v README.md + + ls -lh + + popd + """, + ), + Model( + model_name="sherpa-onnx-paraformer-zh-2023-03-28", + idx=0, + lang="zh", + short_name="paraformer", + cmd=""" + pushd $model_name + + rm -v README.md + rm -rfv test_wavs + rm model.onnx + + ls -lh + + popd + """, + ), + Model( + model_name="icefall-asr-zipformer-wenetspeech-20230615", + idx=4, + lang="zh", + short_name="zipformer", + cmd=""" + pushd $model_name + + rm -rfv test_wavs + rm -v README.md + mv -v data/lang_char/tokens.txt ./ + rm -rfv data/lang_char + + mv -v exp/encoder-epoch-12-avg-4.int8.onnx ./ + mv -v exp/decoder-epoch-12-avg-4.onnx ./ + mv -v exp/joiner-epoch-12-avg-4.int8.onnx ./ + rm -rfv exp + + ls -lh + + popd + """, + ), + ] + return models + + +def get_1st_models(): + # See as ./generate-asr-apk-script.py + models = [ + Model( + model_name="sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20", + idx=8, + lang="bilingual_zh_en", + short_name="zipformer", + cmd=""" + pushd $model_name + rm -v decoder-epoch-99-avg-1.int8.onnx + rm -v encoder-epoch-99-avg-1.onnx + rm -v joiner-epoch-99-avg-1.onnx + + rm -v *.sh + rm -v bpe.model + rm -v README.md + rm -v .gitattributes + rm -v *state* + rm -rfv test_wavs + + ls -lh + + popd + """, + ), + Model( + model_name="sherpa-onnx-streaming-zipformer-en-2023-06-26", + idx=6, + lang="en", + short_name="zipformer2", + cmd=""" + pushd $model_name + rm -v encoder-epoch-99-avg-1-chunk-16-left-128.onnx + rm -v decoder-epoch-99-avg-1-chunk-16-left-128.int8.onnx + rm -v joiner-epoch-99-avg-1-chunk-16-left-128.int8.onnx + + rm -v README.md + rm -v bpe.model + rm -rfv test_wavs + + ls -lh + + popd + """, + ), + Model( + model_name="icefall-asr-zipformer-streaming-wenetspeech-20230615", + idx=3, + lang="zh", + short_name="zipformer2", + cmd=""" + pushd $model_name + rm -v exp/encoder-epoch-12-avg-4-chunk-16-left-128.onnx + rm -v exp/decoder-epoch-12-avg-4-chunk-16-left-128.int8.onnx + rm -v exp/joiner-epoch-12-avg-4-chunk-16-left-128.int8.onnx + + rm -v data/lang_char/lexicon.txt + rm -v data/lang_char/words.txt + rm -rfv test_wavs + rm -v README.md + + ls -lh exp/ + ls -lh data/lang_char + + popd + """, + ), + Model( + model_name="sherpa-onnx-streaming-zipformer-fr-2023-04-14", + idx=7, + lang="fr", + short_name="zipformer", + cmd=""" + pushd $model_name + rm -v encoder-epoch-29-avg-9-with-averaged-model.onnx + rm -v decoder-epoch-29-avg-9-with-averaged-model.int8.onnx + rm -v joiner-epoch-29-avg-9-with-averaged-model.int8.onnx + + rm -v *.sh + rm -rf test_wavs + rm README.md + + ls -lh + + popd + """, + ), + Model( + model_name="sherpa-onnx-streaming-zipformer-zh-14M-2023-02-23", + idx=9, + lang="zh", + short_name="small_zipformer", + cmd=""" + pushd $model_name + rm -v encoder-epoch-99-avg-1.onnx + rm -v decoder-epoch-99-avg-1.int8.onnx + rm -v joiner-epoch-99-avg-1.onnx + + rm -v *.sh + rm -rf test_wavs + rm README.md + + ls -lh + + popd + """, + ), + Model( + model_name="sherpa-onnx-streaming-zipformer-en-20M-2023-02-17", + idx=10, + lang="en", + short_name="small_zipformer", + cmd=""" + pushd $model_name + rm -v encoder-epoch-99-avg-1.onnx + rm -v decoder-epoch-99-avg-1.int8.onnx + rm -v joiner-epoch-99-avg-1.onnx + + rm -v *.sh + rm -rf test_wavs + rm README.md + + ls -lh + + popd + """, + ), + ] + + return models + + +def get_models(): + first = get_1st_models() + second = get_2nd_models() + + combinations = [ + ( + "sherpa-onnx-streaming-zipformer-zh-14M-2023-02-23", + "sherpa-onnx-paraformer-zh-2023-03-28", + ), + ( + "sherpa-onnx-streaming-zipformer-zh-14M-2023-02-23", + "icefall-asr-zipformer-wenetspeech-20230615", + ), + ( + "sherpa-onnx-streaming-zipformer-en-20M-2023-02-17", + "sherpa-onnx-whisper-tiny.en", + ), + ] + models = [] + for f, s in combinations: + t = [] + for m in first: + if m.model_name == f: + t.append(m) + break + assert len(t) == 1, (f, s, first, second) + + for m in second: + if m.model_name == s: + t.append(m) + break + assert len(t) == 2, (f, s, first, second) + + models.append(t) + + return models + + +def main(): + args = get_args() + index = args.index + total = args.total + assert 0 <= index < total, (index, total) + + all_model_list = get_models() + + num_models = len(all_model_list) + + num_per_runner = num_models // total + if num_per_runner <= 0: + raise ValueError(f"num_models: {num_models}, num_runners: {total}") + + start = index * num_per_runner + end = start + num_per_runner + + remaining = num_models - args.total * num_per_runner + + print(f"{index}/{total}: {start}-{end}/{num_models}") + + d = dict() + d["model_list"] = all_model_list[start:end] + if index < remaining: + s = args.total * num_per_runner + index + d["model_list"].append(all_model_list[s]) + print(f"{s}/{num_models}") + + filename_list = [ + "./build-apk-asr-2pass.sh", + ] + for filename in filename_list: + environment = jinja2.Environment() + with open(f"{filename}.in") as f: + s = f.read() + template = environment.from_string(s) + + s = template.render(**d) + with open(filename, "w") as f: + print(s, file=f) + + +if __name__ == "__main__": + main() diff --git a/scripts/apk/generate-asr-apk-script.py b/scripts/apk/generate-asr-apk-script.py index 77cad1250..f53239edf 100755 --- a/scripts/apk/generate-asr-apk-script.py +++ b/scripts/apk/generate-asr-apk-script.py @@ -57,12 +57,116 @@ def get_models(): rm -v joiner-epoch-99-avg-1.onnx rm -v *.sh + rm -v bpe.model + rm -v README.md rm -v .gitattributes rm -v *state* rm -rfv test_wavs ls -lh + popd + """, + ), + Model( + model_name="sherpa-onnx-streaming-zipformer-en-2023-06-26", + idx=6, + lang="en", + short_name="zipformer2", + cmd=""" + pushd $model_name + rm -v encoder-epoch-99-avg-1-chunk-16-left-128.onnx + rm -v decoder-epoch-99-avg-1-chunk-16-left-128.int8.onnx + rm -v joiner-epoch-99-avg-1-chunk-16-left-128.int8.onnx + + rm -v README.md + rm -v bpe.model + rm -rfv test_wavs + + ls -lh + + popd + """, + ), + Model( + model_name="icefall-asr-zipformer-streaming-wenetspeech-20230615", + idx=3, + lang="zh", + short_name="zipformer2", + cmd=""" + pushd $model_name + rm -v exp/encoder-epoch-12-avg-4-chunk-16-left-128.onnx + rm -v exp/decoder-epoch-12-avg-4-chunk-16-left-128.int8.onnx + rm -v exp/joiner-epoch-12-avg-4-chunk-16-left-128.int8.onnx + + rm -v data/lang_char/lexicon.txt + rm -v data/lang_char/words.txt + rm -rfv test_wavs + rm -v README.md + + ls -lh exp/ + ls -lh data/lang_char + + popd + """, + ), + Model( + model_name="sherpa-onnx-streaming-zipformer-fr-2023-04-14", + idx=7, + lang="fr", + short_name="zipformer", + cmd=""" + pushd $model_name + rm -v encoder-epoch-29-avg-9-with-averaged-model.onnx + rm -v decoder-epoch-29-avg-9-with-averaged-model.int8.onnx + rm -v joiner-epoch-29-avg-9-with-averaged-model.int8.onnx + + rm -v *.sh + rm -rf test_wavs + rm README.md + + ls -lh + + popd + """, + ), + Model( + model_name="sherpa-onnx-streaming-zipformer-zh-14M-2023-02-23", + idx=9, + lang="zh", + short_name="small_zipformer", + cmd=""" + pushd $model_name + rm -v encoder-epoch-99-avg-1.onnx + rm -v decoder-epoch-99-avg-1.int8.onnx + rm -v joiner-epoch-99-avg-1.onnx + + rm -v *.sh + rm -rf test_wavs + rm README.md + + ls -lh + + popd + """, + ), + Model( + model_name="sherpa-onnx-streaming-zipformer-en-20M-2023-02-17", + idx=10, + lang="en", + short_name="small_zipformer", + cmd=""" + pushd $model_name + rm -v encoder-epoch-99-avg-1.onnx + rm -v decoder-epoch-99-avg-1.int8.onnx + rm -v joiner-epoch-99-avg-1.onnx + + rm -v *.sh + rm -rf test_wavs + rm README.md + + ls -lh + popd """, ), diff --git a/scripts/apk/generate-vad-asr-apk-script.py b/scripts/apk/generate-vad-asr-apk-script.py new file mode 100755 index 000000000..95409b9a7 --- /dev/null +++ b/scripts/apk/generate-vad-asr-apk-script.py @@ -0,0 +1,156 @@ +#!/usr/bin/env python3 + +import argparse +from dataclasses import dataclass +from typing import List, Optional + +import jinja2 + + +def get_args(): + parser = argparse.ArgumentParser() + parser.add_argument( + "--total", + type=int, + default=1, + help="Number of runners", + ) + parser.add_argument( + "--index", + type=int, + default=0, + help="Index of the current runner", + ) + return parser.parse_args() + + +@dataclass +class Model: + # We will download + # https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/{model_name}.tar.bz2 + model_name: str + + # The type of the model, e..g, 0, 1, 2. It is hardcoded in the kotlin code + idx: int + + # e.g., zh, en, zh_en + lang: str + + # e.g., whisper, paraformer, zipformer + short_name: str = "" + + # cmd is used to remove extra file from the model directory + cmd: str = "" + + +# See get_2nd_models() in ./generate-asr-2pass-apk-script.py +def get_models(): + models = [ + Model( + model_name="sherpa-onnx-whisper-tiny.en", + idx=2, + lang="en", + short_name="whisper_tiny", + cmd=""" + pushd $model_name + rm -v tiny.en-encoder.onnx + rm -v tiny.en-decoder.onnx + rm -rf test_wavs + rm -v *.py + rm -v requirements.txt + rm -v .gitignore + rm -v README.md + + ls -lh + + popd + """, + ), + Model( + model_name="sherpa-onnx-paraformer-zh-2023-03-28", + idx=0, + lang="zh", + short_name="paraformer", + cmd=""" + pushd $model_name + + rm -v README.md + rm -rfv test_wavs + rm model.onnx + + ls -lh + + popd + """, + ), + Model( + model_name="icefall-asr-zipformer-wenetspeech-20230615", + idx=4, + lang="zh", + short_name="zipformer", + cmd=""" + pushd $model_name + + rm -rfv test_wavs + rm -v README.md + mv -v data/lang_char/tokens.txt ./ + rm -rfv data/lang_char + + mv -v exp/encoder-epoch-12-avg-4.int8.onnx ./ + mv -v exp/decoder-epoch-12-avg-4.onnx ./ + mv -v exp/joiner-epoch-12-avg-4.int8.onnx ./ + rm -rfv exp + + ls -lh + + popd + """, + ), + ] + return models + + +def main(): + args = get_args() + index = args.index + total = args.total + assert 0 <= index < total, (index, total) + + all_model_list = get_models() + + num_models = len(all_model_list) + + num_per_runner = num_models // total + if num_per_runner <= 0: + raise ValueError(f"num_models: {num_models}, num_runners: {total}") + + start = index * num_per_runner + end = start + num_per_runner + + remaining = num_models - args.total * num_per_runner + + print(f"{index}/{total}: {start}-{end}/{num_models}") + + d = dict() + d["model_list"] = all_model_list[start:end] + if index < remaining: + s = args.total * num_per_runner + index + d["model_list"].append(all_model_list[s]) + print(f"{s}/{num_models}") + + filename_list = [ + "./build-apk-vad-asr.sh", + ] + for filename in filename_list: + environment = jinja2.Environment() + with open(f"{filename}.in") as f: + s = f.read() + template = environment.from_string(s) + + s = template.render(**d) + with open(filename, "w") as f: + print(s, file=f) + + +if __name__ == "__main__": + main() From e5a57c6fb3676a72094bd86a2324561c20eaa2df Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Tue, 7 May 2024 13:31:04 +0800 Subject: [PATCH 2/7] install node --- .../workflows/npm-addon-linux-aarch64.yaml | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/.github/workflows/npm-addon-linux-aarch64.yaml b/.github/workflows/npm-addon-linux-aarch64.yaml index 72aec002b..8b48efdc5 100644 --- a/.github/workflows/npm-addon-linux-aarch64.yaml +++ b/.github/workflows/npm-addon-linux-aarch64.yaml @@ -45,21 +45,27 @@ jobs: cat /etc/*release gcc --version cmake --version + + curl -sL https://rpm.nodesource.com/setup_16.x | bash - + yum install -y nodejs + + node --version + cd /shared - # mkdir build - # cd build - # cmake \ - # -DCMAKE_INSTALL_PREFIX=./install \ - # -DBUILD_SHARED_LIBS=ON \ - # -DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ - # -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ - # -DSHERPA_ONNX_ENABLE_BINARY=OFF \ - # .. - # make -j install + mkdir build + cd build + cmake \ + -DCMAKE_INSTALL_PREFIX=./install \ + -DBUILD_SHARED_LIBS=ON \ + -DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ + -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ + -DSHERPA_ONNX_ENABLE_BINARY=OFF \ + .. + make -j install - name: Build sherpa-onnx node-addon - if: false + if: true shell: bash run: | d=$PWD From d15b7d792264d497c93246966f4593414f4e32f9 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Tue, 7 May 2024 14:27:18 +0800 Subject: [PATCH 3/7] set node_arch --- .github/scripts/node-addon/run.sh | 4 +++ .../workflows/npm-addon-linux-aarch64.yaml | 25 ++++++------------- README.md | 19 ++++++-------- 3 files changed, 19 insertions(+), 29 deletions(-) diff --git a/.github/scripts/node-addon/run.sh b/.github/scripts/node-addon/run.sh index c33ceeb12..28b6fe9da 100755 --- a/.github/scripts/node-addon/run.sh +++ b/.github/scripts/node-addon/run.sh @@ -7,6 +7,7 @@ src_dir=$sherpa_onnx_dir/.github/scripts/node-addon platform=$(node -p "require('os').platform()") arch=$(node -p "require('os').arch()") + platform2=$platform if [[ $platform == win32 ]]; then @@ -16,6 +17,9 @@ fi SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" +SHERPA_ONNX_VERSION=1.0.14 +echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" + if [ -z $owner ]; then owner=k2-fsa fi diff --git a/.github/workflows/npm-addon-linux-aarch64.yaml b/.github/workflows/npm-addon-linux-aarch64.yaml index 8b48efdc5..a2313c645 100644 --- a/.github/workflows/npm-addon-linux-aarch64.yaml +++ b/.github/workflows/npm-addon-linux-aarch64.yaml @@ -38,6 +38,7 @@ jobs: with: image: quay.io/pypa/manylinux2014_aarch64 options: | + --platform linux/arm64 --volume ${{ github.workspace }}/:/shared/ shell: bash run: | @@ -63,27 +64,19 @@ jobs: -DSHERPA_ONNX_ENABLE_BINARY=OFF \ .. make -j install + cd .. - - name: Build sherpa-onnx node-addon - if: true - shell: bash - run: | - d=$PWD - export SHERPA_ONNX_INSTALL_DIR=$d/build/install - - sudo mkdir /shared - sudo ln -s $PWD/build /shared/ - - ls -lh /shared/build + d=$PWD + export SHERPA_ONNX_INSTALL_DIR=$d/build/install - cd scripts/node-addon-api/ + ls -lh /shared/build - npm i + cd scripts/node-addon-api/ + npm i - ./node_modules/.bin/cmake-js compile --log-level verbose + ./node_modules/.bin/cmake-js compile --log-level verbose - name: Prepare for publish - if: false shell: bash run: | owner=${{ github.repository_owner }} @@ -105,13 +98,11 @@ jobs: .github/scripts/node-addon/run.sh - name: Display files to be published - if: false shell: bash run: | ls -lh ./sherpa-onnx-node - name: Publish - if: false shell: bash env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/README.md b/README.md index d8cb1df1f..c80ade988 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ This repository supports running the following functions **locally** - Spoken language identification - Audio tagging - VAD (e.g., [silero-vad](https://github.com/snakers4/silero-vad)) + - Keyword spotting on the following platforms and operating systems: @@ -27,17 +28,11 @@ on the following platforms and operating systems: with the following APIs - - C++ - - C - - Python - - Go - - ``C#`` - - Javascript - - Java - - Kotlin + - C++, C, Python, Go, ``C#`` + - Java, Kotlin, JavaScript - Swift -# Links for pre-built Android APKs +## Links for pre-built Android APKs | Description | URL | 中国用户 | |--------------------------------|-----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------| @@ -52,7 +47,7 @@ with the following APIs | Spoken language identification | [Address](https://k2-fsa.github.io/sherpa/onnx/spoken-language-identification/apk.html) | [点此](https://k2-fsa.github.io/sherpa/onnx/spoken-language-identification/apk-cn.html) | |Keyword spotting| [Address](https://k2-fsa.github.io/sherpa/onnx/kws/apk.html)| [点此](https://k2-fsa.github.io/sherpa/onnx/kws/apk-cn.html)| -# Links for pre-trained models +## Links for pre-trained models | Description | URL | |--------------------------------|--------------------------------------------------------------------------------------------------------------------------------| @@ -65,12 +60,12 @@ with the following APIs | Spoken language identification (Language ID) | See multi-lingual Whisper ASR models from [Speech recognition](https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models) | | Punctuation| [Address](https://github.com/k2-fsa/sherpa-onnx/releases/tag/punctuation-models)| -# Useful links +## Useful links - Documentation: https://k2-fsa.github.io/sherpa/onnx/ - Bilibili 演示视频: https://search.bilibili.com/all?keyword=%E6%96%B0%E4%B8%80%E4%BB%A3Kaldi -# How to reach us +## How to reach us Please see https://k2-fsa.github.io/sherpa/social-groups.html From 2106d9e83979c6857a6cb5dbe39426ca1deb0c61 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Tue, 7 May 2024 16:10:18 +0800 Subject: [PATCH 4/7] small fixes --- .github/scripts/node-addon/run.sh | 5 +- .../workflows/npm-addon-linux-aarch64.yaml | 60 +++++++------------ 2 files changed, 27 insertions(+), 38 deletions(-) diff --git a/.github/scripts/node-addon/run.sh b/.github/scripts/node-addon/run.sh index 28b6fe9da..1ca165763 100755 --- a/.github/scripts/node-addon/run.sh +++ b/.github/scripts/node-addon/run.sh @@ -6,7 +6,10 @@ echo "sherpa_onnx_dir: $sherpa_onnx_dir" src_dir=$sherpa_onnx_dir/.github/scripts/node-addon platform=$(node -p "require('os').platform()") -arch=$(node -p "require('os').arch()") + +if [[ -z $arch ]]; then + arch=$(node -p "require('os').arch()") +fi platform2=$platform diff --git a/.github/workflows/npm-addon-linux-aarch64.yaml b/.github/workflows/npm-addon-linux-aarch64.yaml index a2313c645..9e7e81c4a 100644 --- a/.github/workflows/npm-addon-linux-aarch64.yaml +++ b/.github/workflows/npm-addon-linux-aarch64.yaml @@ -71,44 +71,30 @@ jobs: ls -lh /shared/build - cd scripts/node-addon-api/ + pushd scripts/node-addon-api/ npm i ./node_modules/.bin/cmake-js compile --log-level verbose + popd - - name: Prepare for publish - shell: bash - run: | - owner=${{ github.repository_owner }} - export owner - - echo "---" - ls -lh build/install/lib/ - sudo chown -R runner ./build - echo "---" - ls -lh build/install/lib/ - echo "---" - - # find build/install/lib/ -maxdepth 1 -type l - # find build/install/lib/ -maxdepth 1 -type l -delete - # - # echo "---" - # ls -lh build/install/lib/ - - .github/scripts/node-addon/run.sh - - - name: Display files to be published - shell: bash - run: | - ls -lh ./sherpa-onnx-node - - - name: Publish - shell: bash - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - run: | - cd ./sherpa-onnx-node - npm install - npm ci - # see https://docs.npmjs.com/generating-provenance-statements - npm publish --provenance --access public + owner=${{ github.repository_owner }} + export owner + + echo "---" + ls -lh build/install/lib/ + sudo chown -R runner ./build + echo "---" + ls -lh build/install/lib/ + echo "---" + + .github/scripts/node-addon/run.sh + + ls -lh ./sherpa-onnx-node + + export NODE_AUTH_TOKEN=${{ secrets.NPM_TOKEN }} + + cd ./sherpa-onnx-node + npm install + npm ci + # see https://docs.npmjs.com/generating-provenance-statements + npm publish --provenance --access public From e879485238829f9ed5d6f0dc663d775d771f3494 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Tue, 7 May 2024 18:38:54 +0800 Subject: [PATCH 5/7] fix publishing --- .../workflows/npm-addon-linux-aarch64.yaml | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/npm-addon-linux-aarch64.yaml b/.github/workflows/npm-addon-linux-aarch64.yaml index 9e7e81c4a..93ed534b8 100644 --- a/.github/workflows/npm-addon-linux-aarch64.yaml +++ b/.github/workflows/npm-addon-linux-aarch64.yaml @@ -91,10 +91,18 @@ jobs: ls -lh ./sherpa-onnx-node - export NODE_AUTH_TOKEN=${{ secrets.NPM_TOKEN }} - - cd ./sherpa-onnx-node - npm install - npm ci - # see https://docs.npmjs.com/generating-provenance-statements - npm publish --provenance --access public + - uses: actions/setup-node@v4 + with: + registry-url: 'https://registry.npmjs.org' + + - name: Publish + shell: bash + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + git diff + cd ./sherpa-onnx-node + npm install + npm ci + # see https://docs.npmjs.com/generating-provenance-statements + npm publish --provenance --access public From ee7cc79b73841ec1f0dcc0cf3bd18449b9dbcf07 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Tue, 7 May 2024 19:56:49 +0800 Subject: [PATCH 6/7] fix registry --- .github/scripts/node-addon/package.json | 1 + .github/scripts/node-addon/run.sh | 7 +-- .../workflows/npm-addon-linux-aarch64.yaml | 62 +++++++++++++------ 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/.github/scripts/node-addon/package.json b/.github/scripts/node-addon/package.json index e1d4ded92..8980320de 100644 --- a/.github/scripts/node-addon/package.json +++ b/.github/scripts/node-addon/package.json @@ -48,6 +48,7 @@ "sherpa-onnx-darwin-arm64": "^SHERPA_ONNX_VERSION", "sherpa-onnx-darwin-x64": "^SHERPA_ONNX_VERSION", "sherpa-onnx-linux-x64": "^SHERPA_ONNX_VERSION", + "sherpa-onnx-linux-arm64": "^SHERPA_ONNX_VERSION", "sherpa-onnx-win-x64": "^SHERPA_ONNX_VERSION" } } diff --git a/.github/scripts/node-addon/run.sh b/.github/scripts/node-addon/run.sh index 1ca165763..5569dd609 100755 --- a/.github/scripts/node-addon/run.sh +++ b/.github/scripts/node-addon/run.sh @@ -7,9 +7,7 @@ src_dir=$sherpa_onnx_dir/.github/scripts/node-addon platform=$(node -p "require('os').platform()") -if [[ -z $arch ]]; then - arch=$(node -p "require('os').arch()") -fi +arch=$(node -p "require('os').arch()") platform2=$platform @@ -20,9 +18,6 @@ fi SHERPA_ONNX_VERSION=$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2) echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" -SHERPA_ONNX_VERSION=1.0.14 -echo "SHERPA_ONNX_VERSION $SHERPA_ONNX_VERSION" - if [ -z $owner ]; then owner=k2-fsa fi diff --git a/.github/workflows/npm-addon-linux-aarch64.yaml b/.github/workflows/npm-addon-linux-aarch64.yaml index 93ed534b8..942023dd8 100644 --- a/.github/workflows/npm-addon-linux-aarch64.yaml +++ b/.github/workflows/npm-addon-linux-aarch64.yaml @@ -1,9 +1,6 @@ name: npm-addon-linux-aarch64 on: - push: - branches: - - node-addon-arm workflow_dispatch: concurrency: @@ -33,6 +30,34 @@ jobs: with: platforms: arm64 + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Show .npmrc + shell: bash + run: | + echo $PWD + echo $HOME + + find $HOME -name .npmrc + + - uses: actions/setup-node@v4 + with: + registry-url: 'https://registry.npmjs.org' + + - name: Show .npmrc + shell: bash + run: | + echo $PWD + echo $HOME + + find $HOME -name .npmrc + + cat /home/runner/work/_temp/.npmrc + cp -v /home/runner/work/_temp/.npmrc ./ + - name: Build sherpa-onnx uses: addnab/docker-run-action@v3 with: @@ -42,6 +67,11 @@ jobs: --volume ${{ github.workspace }}/:/shared/ shell: bash run: | + cp /shared/.npmrc ~/ + + cat ~/.npmrc + + echo $HOME uname -a cat /etc/*release gcc --version @@ -63,7 +93,9 @@ jobs: -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ -DSHERPA_ONNX_ENABLE_BINARY=OFF \ .. - make -j install + + make + make install cd .. d=$PWD @@ -91,18 +123,12 @@ jobs: ls -lh ./sherpa-onnx-node - - uses: actions/setup-node@v4 - with: - registry-url: 'https://registry.npmjs.org' + export NODE_AUTH_TOKEN=${{ secrets.NPM_TOKEN }} - - name: Publish - shell: bash - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - run: | - git diff - cd ./sherpa-onnx-node - npm install - npm ci - # see https://docs.npmjs.com/generating-provenance-statements - npm publish --provenance --access public + cd ./sherpa-onnx-node + cp -v /shared/.npmrc ./ + npm install + npm ci + ls -lh + # see https://docs.npmjs.com/generating-provenance-statements + npm publish --provenance --access public From 9b3fb166ea5f2399f06367737612486b5c85f474 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Tue, 7 May 2024 22:36:08 +0800 Subject: [PATCH 7/7] Add test for aarch64 --- .github/scripts/test-nodejs-addon-npm.sh | 1 + .../workflows/npm-addon-linux-aarch64.yaml | 2 +- .../test-nodejs-addon-npm-aarch64.yaml | 80 +++++++++++++++++++ nodejs-addon-examples/README.md | 4 +- 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test-nodejs-addon-npm-aarch64.yaml diff --git a/.github/scripts/test-nodejs-addon-npm.sh b/.github/scripts/test-nodejs-addon-npm.sh index ab6fd5723..71b83c25a 100755 --- a/.github/scripts/test-nodejs-addon-npm.sh +++ b/.github/scripts/test-nodejs-addon-npm.sh @@ -13,6 +13,7 @@ ls -lh node_modules export DYLD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-darwin-x64:$DYLD_LIBRARY_PATH export DYLD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-darwin-arm64:$DYLD_LIBRARY_PATH export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-linux-x64:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-linux-arm64:$LD_LIBRARY_PATH curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2 tar xvf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2 diff --git a/.github/workflows/npm-addon-linux-aarch64.yaml b/.github/workflows/npm-addon-linux-aarch64.yaml index 942023dd8..bbeb266e3 100644 --- a/.github/workflows/npm-addon-linux-aarch64.yaml +++ b/.github/workflows/npm-addon-linux-aarch64.yaml @@ -94,7 +94,7 @@ jobs: -DSHERPA_ONNX_ENABLE_BINARY=OFF \ .. - make + make -j make install cd .. diff --git a/.github/workflows/test-nodejs-addon-npm-aarch64.yaml b/.github/workflows/test-nodejs-addon-npm-aarch64.yaml new file mode 100644 index 000000000..1dc88ac07 --- /dev/null +++ b/.github/workflows/test-nodejs-addon-npm-aarch64.yaml @@ -0,0 +1,80 @@ +name: test-node-addon-npm-aarch64 + +on: + push: + branches: + - master + paths: + - '.github/workflows/test-nodejs-addon-npm-aarch64.yaml' + - 'CMakeLists.txt' + - 'cmake/**' + - 'sherpa-onnx/csrc/*' + - 'sherpa-onnx/c-api/*' + - 'scripts/node-addon-api/**' + - 'scripts/node-addon-api/*.js' + - 'nodejs-addon-examples/package.json' + + pull_request: + branches: + - master + paths: + - '.github/workflows/test-nodejs-addon-npm-aarch64.yaml' + - 'CMakeLists.txt' + - 'cmake/**' + - 'sherpa-onnx/csrc/*' + - 'sherpa-onnx/c-api/*' + - 'scripts/node-addon-api/*.js' + - 'nodejs-addon-examples/package.json' + + workflow_dispatch: + +concurrency: + group: test-node-addon-npm-aarch64-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + test-node-addon-npm-aarch64: + name: ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: arm64 + + - name: Test sherpa-onnx + uses: addnab/docker-run-action@v3 + with: + image: quay.io/pypa/manylinux2014_aarch64 + options: | + --platform linux/arm64 + --volume ${{ github.workspace }}/:/shared/ + shell: bash + run: | + git config --global --add safe.directory /shared + + echo $HOME + uname -a + cat /etc/*release + cmake --version + + curl -sL https://rpm.nodesource.com/setup_16.x | bash - + yum install -y nodejs + + node --version + + cd /shared + + .github/scripts/test-nodejs-addon-npm.sh diff --git a/nodejs-addon-examples/README.md b/nodejs-addon-examples/README.md index 28dd0ff0b..088961f39 100644 --- a/nodejs-addon-examples/README.md +++ b/nodejs-addon-examples/README.md @@ -22,8 +22,10 @@ export DYLD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-darwin-arm64:$DYLD_LIBRAR # For Linux x64 export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-linux-x64:$LD_LIBRARY_PATH -``` +# For Linux arm64, e.g., Raspberry Pi 4 +export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-linux-arm64:$LD_LIBRARY_PATH +``` ## Streaming speech recognition with zipformer transducer ```bash