Skip to content

Commit

Permalink
Add WebAssembly for VAD (#1281)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Aug 23, 2024
1 parent fb09f8f commit 1ef8a7a
Show file tree
Hide file tree
Showing 20 changed files with 1,056 additions and 20 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/wasm-simd-hf-space-de-tts.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: wasm-simd-hf-space-de-tts

on:
release:
types:
- published
push:
branches:
- wasm
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

workflow_dispatch:

Expand Down Expand Up @@ -71,6 +73,14 @@ jobs:
name: sherpa-onnx-wasm-simd-de-tts
path: ./sherpa-onnx-wasm-simd-*.tar.bz2

- name: Release
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v2
with:
file_glob: true
overwrite: true
file: ./*.tar.bz2

- name: Publish to ModelScope
# if: false
env:
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/wasm-simd-hf-space-en-asr-zipformer.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: wasm-simd-hf-space-en-asr-zipformer

on:
release:
types:
- published
push:
branches:
- wasm
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

workflow_dispatch:

Expand Down Expand Up @@ -73,6 +75,14 @@ jobs:
name: sherpa-onnx-wasm-simd-en-asr-zipformer
path: ./sherpa-onnx-wasm-simd-*.tar.bz2

- name: Release
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v2
with:
file_glob: true
overwrite: true
file: ./*.tar.bz2

- name: Publish to ModelScope
# if: false
env:
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/wasm-simd-hf-space-en-tts.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: wasm-simd-hf-space-en-tts

on:
release:
types:
- published
push:
branches:
- wasm
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

workflow_dispatch:

Expand Down Expand Up @@ -69,6 +71,14 @@ jobs:
name: sherpa-onnx-wasm-simd-en-tts
path: ./sherpa-onnx-wasm-simd-*.tar.bz2

- name: Release
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v2
with:
file_glob: true
overwrite: true
file: ./*.tar.bz2

- name: Publish to ModelScope
# if: false
env:
Expand Down
152 changes: 152 additions & 0 deletions .github/workflows/wasm-simd-hf-space-silero-vad.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: wasm-simd-hf-space-silero-vad

on:
push:
branches:
- wasm
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

workflow_dispatch:

concurrency:
group: wasm-simd-hf-space-silero-vad-${{ github.ref }}
cancel-in-progress: true

jobs:
wasm-simd-hf-space-silero-vad:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install emsdk
uses: mymindstorm/setup-emsdk@v14
with:
version: 3.1.51
actions-cache-folder: 'emsdk-cache'

- name: View emsdk version
shell: bash
run: |
emcc -v
echo "--------------------"
emcc --check
- name: Download model files
shell: bash
run: |
cd wasm/vad/assets
ls -lh
echo "----------"
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/silero_vad.onnx
ls -lh
- name: Build sherpa-onnx for WebAssembly
shell: bash
run: |
./build-wasm-simd-vad.sh
- name: collect files
shell: bash
run: |
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
dst=sherpa-onnx-wasm-simd-${SHERPA_ONNX_VERSION}-vad
mv build-wasm-simd-vad/install/bin/wasm/vad $dst
ls -lh $dst
tar cjfv $dst.tar.bz2 ./$dst
- name: Upload wasm files
uses: actions/upload-artifact@v4
with:
name: sherpa-onnx-wasm-simd-vad
path: ./sherpa-onnx-wasm-simd-*.tar.bz2

- name: Release
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v2
with:
file_glob: true
overwrite: true
file: ./*.tar.bz2

- name: Publish to ModelScope
# if: false
env:
MS_TOKEN: ${{ secrets.MODEL_SCOPE_GIT_TOKEN }}
uses: nick-fields/retry@v2
with:
max_attempts: 20
timeout_seconds: 200
shell: bash
command: |
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
git config --global user.email "[email protected]"
git config --global user.name "Fangjun Kuang"
rm -rf ms
export GIT_LFS_SKIP_SMUDGE=1
export GIT_CLONE_PROTECTION_ACTIVE=false
git clone https://www.modelscope.cn/studios/csukuangfj/web-assembly-vad-sherpa-onnx.git ms
cd ms
rm -fv *.js
rm -fv *.data
git fetch
git pull
git merge -m "merge remote" --ff origin main
cp -v ../sherpa-onnx-wasm-simd-${SHERPA_ONNX_VERSION}-vad/* .
git status
git lfs track "*.data"
git lfs track "*.wasm"
ls -lh
git add .
git commit -m "update model"
git push https://oauth2:${MS_TOKEN}@www.modelscope.cn/studios/csukuangfj/web-assembly-vad-sherpa-onnx.git
- name: Publish to huggingface
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
uses: nick-fields/retry@v2
with:
max_attempts: 20
timeout_seconds: 200
shell: bash
command: |
SHERPA_ONNX_VERSION=v$(grep "SHERPA_ONNX_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
git config --global user.email "[email protected]"
git config --global user.name "Fangjun Kuang"
rm -rf huggingface
export GIT_LFS_SKIP_SMUDGE=1
export GIT_CLONE_PROTECTION_ACTIVE=false
git clone https://huggingface.co/spaces/k2-fsa/web-assembly-vad-sherpa-onnx huggingface
cd huggingface
rm -fv *.js
rm -fv *.data
git fetch
git pull
git merge -m "merge remote" --ff origin main
cp -v ../sherpa-onnx-wasm-simd-${SHERPA_ONNX_VERSION}-vad/* .
git status
git lfs track "*.data"
git lfs track "*.wasm"
ls -lh
git add .
git commit -m "update model"
git push https://csukuangfj:[email protected]/spaces/k2-fsa/web-assembly-vad-sherpa-onnx main
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: wasm-simd-hf-space-zh-cantonese-en-asr-paraformer

on:
release:
types:
- published
push:
branches:
- wasm
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

workflow_dispatch:

Expand Down Expand Up @@ -80,6 +82,14 @@ jobs:
name: sherpa-onnx-wasm-simd-zh-cantonese-en-asr-paraformer
path: ./sherpa-onnx-wasm-simd-*.tar.bz2

- name: Release
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v2
with:
file_glob: true
overwrite: true
file: ./*.tar.bz2

- name: Publish to huggingface
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/wasm-simd-hf-space-zh-en-asr-paraformer.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: wasm-simd-hf-space-zh-en-asr-paraformer

on:
release:
types:
- published
push:
branches:
- wasm
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

workflow_dispatch:

Expand Down Expand Up @@ -80,6 +82,14 @@ jobs:
name: sherpa-onnx-wasm-simd-zh-en-asr-paraformer
path: ./sherpa-onnx-wasm-simd-*.tar.bz2

- name: Release
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v2
with:
file_glob: true
overwrite: true
file: ./*.tar.bz2

- name: Publish to ModelScope
# if: false
env:
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/wasm-simd-hf-space-zh-en-asr-zipformer.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: wasm-simd-hf-space-zh-en-asr-zipformer

on:
release:
types:
- published
push:
branches:
- wasm
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'

workflow_dispatch:

Expand Down Expand Up @@ -71,6 +73,14 @@ jobs:
name: sherpa-onnx-wasm-simd-zh-en-asr-zipformer
path: ./sherpa-onnx-wasm-simd-*.tar.bz2

- name: Release
if: (github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa') && github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v2
with:
file_glob: true
overwrite: true
file: ./*.tar.bz2

- name: Publish to ModelScope
# if: false
env:
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ option(SHERPA_ONNX_ENABLE_WASM "Whether to enable WASM" OFF)
option(SHERPA_ONNX_ENABLE_WASM_TTS "Whether to enable WASM for TTS" OFF)
option(SHERPA_ONNX_ENABLE_WASM_ASR "Whether to enable WASM for ASR" OFF)
option(SHERPA_ONNX_ENABLE_WASM_KWS "Whether to enable WASM for KWS" OFF)
option(SHERPA_ONNX_ENABLE_WASM_VAD "Whether to enable WASM for VAD" OFF)
option(SHERPA_ONNX_ENABLE_WASM_NODEJS "Whether to enable WASM for NodeJS" OFF)
option(SHERPA_ONNX_ENABLE_BINARY "Whether to build binaries" ON)
option(SHERPA_ONNX_ENABLE_TTS "Whether to build TTS related code" ON)
Expand Down Expand Up @@ -135,6 +136,7 @@ message(STATUS "SHERPA_ONNX_ENABLE_WASM ${SHERPA_ONNX_ENABLE_WASM}")
message(STATUS "SHERPA_ONNX_ENABLE_WASM_TTS ${SHERPA_ONNX_ENABLE_WASM_TTS}")
message(STATUS "SHERPA_ONNX_ENABLE_WASM_ASR ${SHERPA_ONNX_ENABLE_WASM_ASR}")
message(STATUS "SHERPA_ONNX_ENABLE_WASM_KWS ${SHERPA_ONNX_ENABLE_WASM_KWS}")
message(STATUS "SHERPA_ONNX_ENABLE_WASM_VAD ${SHERPA_ONNX_ENABLE_WASM_VAD}")
message(STATUS "SHERPA_ONNX_ENABLE_WASM_NODEJS ${SHERPA_ONNX_ENABLE_WASM_NODEJS}")
message(STATUS "SHERPA_ONNX_ENABLE_BINARY ${SHERPA_ONNX_ENABLE_BINARY}")
message(STATUS "SHERPA_ONNX_ENABLE_TTS ${SHERPA_ONNX_ENABLE_TTS}")
Expand Down Expand Up @@ -212,6 +214,10 @@ if(SHERPA_ONNX_ENABLE_WASM_KWS)
add_definitions(-DSHERPA_ONNX_ENABLE_WASM_KWS=1)
endif()

if(SHERPA_ONNX_ENABLE_WASM_VAD)
add_definitions(-DSHERPA_ONNX_ENABLE_WASM_VAD=1)
endif()

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17 CACHE STRING "The C++ version to be used.")
endif()
Expand Down
Loading

0 comments on commit 1ef8a7a

Please sign in to comment.