Skip to content

Commit

Permalink
support nodejs (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Nov 21, 2023
1 parent 38ad05b commit fe977b8
Show file tree
Hide file tree
Showing 34 changed files with 2,704 additions and 4 deletions.
62 changes: 62 additions & 0 deletions .github/scripts/test-nodejs-npm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

set -ex

echo "dir: $d"
cd $d
npm install
git status
ls -lh
ls -lh node_modules

# offline asr

wget -q https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-nemo-ctc-en-conformer-small.tar.bz2
tar xvf sherpa-onnx-nemo-ctc-en-conformer-small.tar.bz2
rm sherpa-onnx-nemo-ctc-en-conformer-small.tar.bz2
node ./test-offline-nemo-ctc.js
rm -rf sherpa-onnx-nemo-ctc-en-conformer-small

wget -q https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2
tar xvf sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2
rm sherpa-onnx-paraformer-zh-2023-03-28.tar.bz2
node ./test-offline-paraformer.js
rm -rf sherpa-onnx-paraformer-zh-2023-03-28

wget -q https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-zipformer-en-2023-06-26.tar.bz2
tar xvf sherpa-onnx-zipformer-en-2023-06-26.tar.bz2
rm sherpa-onnx-zipformer-en-2023-06-26.tar.bz2
node ./test-offline-transducer.js
rm -rf sherpa-onnx-zipformer-en-2023-06-26

wget -q https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-whisper-tiny.en.tar.bz2
tar xvf sherpa-onnx-whisper-tiny.en.tar.bz2
rm sherpa-onnx-whisper-tiny.en.tar.bz2
node ./test-offline-whisper.js
rm -rf sherpa-onnx-whisper-tiny.en

# online asr
wget -q https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-streaming-paraformer-bilingual-zh-en.tar.bz2
tar xvf sherpa-onnx-streaming-paraformer-bilingual-zh-en.tar.bz2
rm sherpa-onnx-streaming-paraformer-bilingual-zh-en.tar.bz2
node ./test-online-paraformer.js
rm -rf sherpa-onnx-streaming-paraformer-bilingual-zh-en

wget -q 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
rm sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
node ./test-online-transducer.js
rm -rf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20

# offline tts
wget -q https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-vctk.tar.bz2
tar xvf vits-vctk.tar.bz2
rm vits-vctk.tar.bz2
node ./test-offline-tts-en.js
rm -rf vits-vctk

wget -q https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-zh-aishell3.tar.bz2
tar xvf vits-zh-aishell3.tar.bz2
rm vits-zh-aishell3.tar.bz2
node ./test-offline-tts-zh.js
rm -rf vits-zh-aishell3
1 change: 1 addition & 0 deletions .github/workflows/dot-net.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- dot-net
- fix-dot-net
tags:
- '*'

Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/npm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: npm

on:
workflow_dispatch:

concurrency:
group: npm-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
nodejs:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.8"]

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

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- uses: actions/setup-node@v3
with:
node-version: 13
registry-url: 'https://registry.npmjs.org'

- name: Display node version
shell: bash
run: |
node --version
npm --version
cd nodejs-examples
npm install [email protected] -g
npm install [email protected]
npm --version
- name: Build nodejs package
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd scripts/nodejs
./run.sh
npm install
rm run.sh
npm ci
npm publish --provenance --access public
59 changes: 59 additions & 0 deletions .github/workflows/test-nodejs-npm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: test-nodejs-npm

on:
workflow_dispatch:

schedule:
# minute (0-59)
# hour (0-23)
# day of the month (1-31)
# month (1-12)
# day of the week (0-6)
# nightly build at 23:50 UTC time every day
- cron: "50 23 * * *"

concurrency:
group: test-nodejs-npm-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
test-nodejs-npm:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest] #, windows-latest]
python-version: ["3.8"]

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

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- uses: actions/setup-node@v3
with:
node-version: 13
registry-url: 'https://registry.npmjs.org'

- name: Display node version
shell: bash
run: |
node --version
npm --version
- name: Run tests
shell: bash
run: |
node --version
npm --version
export d=nodejs-examples
./.github/scripts/test-nodejs-npm.sh
108 changes: 108 additions & 0 deletions .github/workflows/test-nodejs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: test-nodejs

on:
push:
branches:
- master

pull_request:
branches:
- master

workflow_dispatch:

concurrency:
group: test-nodejs-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
test-nodejs:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest] #, windows-latest]
python-version: ["3.8"]

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

- name: ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ matrix.os }}-Release-ON

- name: Configure CMake
shell: bash
run: |
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
cmake --version
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=./install ..
make -j2
make install
ls -lh install/lib
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Copy files
shell: bash
run: |
os=${{ matrix.os }}
if [[ $os == 'ubuntu-latest' ]]; then
mkdir -p scripts/nodejs/lib/linux-x64
dst=scripts/nodejs/lib/linux-x64
elif [[ $os == 'macos-latest' ]]; then
mkdir -p scripts/nodejs/lib/osx-x64
dst=scripts/nodejs/lib/osx-x64
fi
cp -v build/install/lib/* $dst/
- name: replace files
shell: bash
run: |
cd nodejs-examples
files=$(ls -1 *.js)
for f in ${files[@]}; do
echo $f
sed -i.bak s%\'sherpa-onnx\'%\'./index.js\'% $f
git status
done
git diff
cp *.js ../scripts/nodejs
- uses: actions/setup-node@v3
with:
node-version: 13
registry-url: 'https://registry.npmjs.org'

- name: Display node version
shell: bash
run: |
node --version
npm --version
- name: Run tests
shell: bash
run: |
node --version
npm --version
export d=scripts/nodejs
pushd $d
npm install
npm install wav
popd
./.github/scripts/test-nodejs-npm.sh
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ swift-api-examples/k2fsa-*
run-*.sh
two-pass-*.sh
build-*
vits-vctk
vits-zh-aishell3
jslint.mjs
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(sherpa-onnx)

set(SHERPA_ONNX_VERSION "1.8.10")
set(SHERPA_ONNX_VERSION "1.8.11")

# Disable warning about
#
Expand Down
2 changes: 2 additions & 0 deletions nodejs-examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package-lock.json
Loading

0 comments on commit fe977b8

Please sign in to comment.