Skip to content

Commit

Permalink
WebAssembly example for VAD + Non-streaming ASR (#1284)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Aug 24, 2024
1 parent 1ef8a7a commit 537e163
Show file tree
Hide file tree
Showing 29 changed files with 1,281 additions and 70 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/wasm-simd-hf-space-de-tts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ jobs:
- 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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/wasm-simd-hf-space-en-asr-zipformer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
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
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/wasm-simd-hf-space-en-tts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ jobs:
- 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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/wasm-simd-hf-space-silero-vad.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install emsdk
uses: mymindstorm/setup-emsdk@v14
with:
Expand Down
93 changes: 93 additions & 0 deletions .github/workflows/wasm-simd-hf-space-vad-asr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: wasm-simd-hf-space-vad-asr

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

workflow_dispatch:

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

jobs:
wasm-simd-hf-space-vad-asr:
name: ${{ matrix.index }}/${{ matrix.total }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
total: ["8"]
index: ["0", "1", "2", "3", "4", "5", "6", "7"]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Python dependencies
shell: bash
run: |
python3 -m pip install --upgrade pip jinja2
- 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: Generate build script
shell: bash
run: |
cd scripts/wasm
total=${{ matrix.total }}
index=${{ matrix.index }}
./generate-vad-asr.py --total $total --index $index
chmod +x run-vad-asr.sh
mv -v ./run-vad-asr.sh ../..
- name: Show build scripts
shell: bash
run: |
cat ./run-vad-asr.sh
- uses: actions/upload-artifact@v4
with:
name: run-vad-asr-${{ matrix.index }}
path: ./run-vad-asr.sh

- name: Build sherpa-onnx for WebAssembly
shell: bash
env:
MS_TOKEN: ${{ secrets.MODEL_SCOPE_GIT_TOKEN }}
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
./run-vad-asr.sh
- name: Release jar
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: Upload wasm files
uses: actions/upload-artifact@v4
with:
name: sherpa-onnx-wasm-simd-vad-asr-${{ matrix.index }}
path: ./sherpa-onnx-wasm-simd-*.tar.bz2
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ jobs:
- 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ jobs:
- 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
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/wasm-simd-hf-space-zh-en-asr-zipformer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ jobs:
- 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
Expand Down
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ 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_VAD_ASR "Whether to enable WASM for VAD+ASR" 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 @@ -137,6 +138,7 @@ 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_VAD_ASR ${SHERPA_ONNX_ENABLE_WASM_VAD_ASR}")
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 @@ -211,11 +213,22 @@ if(SHERPA_ONNX_ENABLE_WASM)
endif()

if(SHERPA_ONNX_ENABLE_WASM_KWS)
if(NOT SHERPA_ONNX_ENABLE_WASM)
message(FATAL_ERROR "Please set SHERPA_ONNX_ENABLE_WASM to ON if you enable WASM for KWS")
endif()
add_definitions(-DSHERPA_ONNX_ENABLE_WASM_KWS=1)
endif()

if(SHERPA_ONNX_ENABLE_WASM_VAD)
add_definitions(-DSHERPA_ONNX_ENABLE_WASM_VAD=1)
if(NOT SHERPA_ONNX_ENABLE_WASM)
message(FATAL_ERROR "Please set SHERPA_ONNX_ENABLE_WASM to ON if you enable WASM for VAD")
endif()
endif()

if(SHERPA_ONNX_ENABLE_WASM_VAD_ASR)
if(NOT SHERPA_ONNX_ENABLE_WASM)
message(FATAL_ERROR "Please set SHERPA_ONNX_ENABLE_WASM to ON if you enable WASM for VAD+ASR")
endif()
endif()

if(NOT CMAKE_CXX_STANDARD)
Expand Down
Loading

0 comments on commit 537e163

Please sign in to comment.