2024-05-04 13:27:39 +08:00
|
|
|
# Introduction
|
|
|
|
|
|
|
|
|
|
Note: You need `Node >= 10`.
|
|
|
|
|
|
|
|
|
|
This repo contains examples for NodeJS.
|
|
|
|
|
It uses [node-addon-api](https://github.com/nodejs/node-addon-api) to wrap
|
|
|
|
|
`sherpa-onnx` for NodeJS and it supports multiple threads.
|
|
|
|
|
|
|
|
|
|
Note: [../nodejs-examples](../nodejs-examples) uses WebAssembly to wrap
|
|
|
|
|
`sherpa-onnx` for NodeJS and it does not support multiple threads.
|
|
|
|
|
|
|
|
|
|
Before you continue, please first run
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
npm install
|
|
|
|
|
|
|
|
|
|
# For macOS x64
|
|
|
|
|
export DYLD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-darwin-x64:$DYLD_LIBRARY_PATH
|
|
|
|
|
|
|
|
|
|
# For macOS arm64
|
|
|
|
|
export DYLD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-darwin-arm64:$DYLD_LIBRARY_PATH
|
|
|
|
|
|
|
|
|
|
# For Linux x64
|
|
|
|
|
export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-linux-x64:$LD_LIBRARY_PATH
|
|
|
|
|
|
2024-05-07 23:05:40 +08:00
|
|
|
# For Linux arm64, e.g., Raspberry Pi 4
|
|
|
|
|
export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-linux-arm64:$LD_LIBRARY_PATH
|
|
|
|
|
```
|
2024-05-04 13:27:39 +08:00
|
|
|
|
2024-05-13 11:58:25 +08:00
|
|
|
# Voice Activity detection (VAD)
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/silero_vad.onnx
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# To run the test with a microphone, you need to install the package naudiodon2
|
|
|
|
|
npm install naudiodon2
|
|
|
|
|
|
|
|
|
|
node ./test_vad_microphone.js
|
|
|
|
|
```
|
|
|
|
|
|
2024-05-13 16:03:34 +08:00
|
|
|
## Streaming speech recognition with Zipformer transducer
|
2024-05-10 18:21:05 +08:00
|
|
|
|
2024-05-04 13:27:39 +08:00
|
|
|
```bash
|
|
|
|
|
wget 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
|
|
|
|
|
|
2024-05-10 18:21:05 +08:00
|
|
|
node ./test_asr_streaming_transducer.js
|
|
|
|
|
|
2024-05-13 11:58:25 +08:00
|
|
|
# To run the test with a microphone, you need to install the package naudiodon2
|
2024-05-12 12:03:43 +08:00
|
|
|
npm install naudiodon2
|
|
|
|
|
|
2024-05-10 18:21:05 +08:00
|
|
|
node ./test_asr_streaming_transducer_microphone.js
|
2024-05-04 13:27:39 +08:00
|
|
|
```
|
2024-05-11 20:58:23 +08:00
|
|
|
|
2024-05-13 16:03:34 +08:00
|
|
|
## Streaming speech recognition with Zipformer CTC
|
2024-05-11 20:58:23 +08:00
|
|
|
|
|
|
|
|
```bash
|
2024-05-13 11:58:25 +08:00
|
|
|
wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-streaming-zipformer-ctc-small-2024-03-18.tar.bz2
|
|
|
|
|
tar xvf sherpa-onnx-streaming-zipformer-ctc-small-2024-03-18.tar.bz2
|
|
|
|
|
rm sherpa-onnx-streaming-zipformer-ctc-small-2024-03-18.tar.bz2
|
2024-05-11 20:58:23 +08:00
|
|
|
|
2024-05-13 11:58:25 +08:00
|
|
|
node ./test_asr_streaming_ctc.js
|
2024-05-12 12:03:43 +08:00
|
|
|
|
2024-05-13 11:58:25 +08:00
|
|
|
# To decode with HLG.fst
|
|
|
|
|
node ./test_asr_streaming_ctc_hlg.js
|
|
|
|
|
|
|
|
|
|
# To run the test with a microphone, you need to install the package naudiodon2
|
2024-05-12 12:03:43 +08:00
|
|
|
npm install naudiodon2
|
|
|
|
|
|
2024-05-13 11:58:25 +08:00
|
|
|
node ./test_asr_streaming_ctc_microphone.js
|
|
|
|
|
node ./test_asr_streaming_ctc_hlg_microphone.js
|
2024-05-11 20:58:23 +08:00
|
|
|
```
|
2024-05-13 16:03:34 +08:00
|
|
|
|
|
|
|
|
## Streaming speech recognition with Paraformer
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
wget 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_asr_streaming_paraformer.js
|
|
|
|
|
|
|
|
|
|
# To run the test with a microphone, you need to install the package naudiodon2
|
|
|
|
|
npm install naudiodon2
|
|
|
|
|
|
|
|
|
|
node ./test_asr_streaming_paraformer_microphone.js
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Non-streaming speech recognition with Zipformer transducer
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-zipformer-en-2023-04-01.tar.bz2
|
|
|
|
|
tar xvf sherpa-onnx-zipformer-en-2023-04-01.tar.bz2
|
|
|
|
|
rm sherpa-onnx-zipformer-en-2023-04-01.tar.bz2
|
|
|
|
|
|
|
|
|
|
node ./test_asr_non_streaming_transducer.js
|
|
|
|
|
|
|
|
|
|
# To run VAD + non-streaming ASR with transudcer using a microphone
|
|
|
|
|
npm install naudiodon2
|
|
|
|
|
node ./test_vad_asr_non_streaming_transducer_microphone.js
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Non-streaming speech recognition with Whisper
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
wget 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_asr_non_streaming_whisper.js
|
|
|
|
|
|
|
|
|
|
# To run VAD + non-streaming ASR with Paraformer using a microphone
|
|
|
|
|
npm install naudiodon2
|
|
|
|
|
node ./test_vad_asr_non_streaming_whisper_microphone.js
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Non-streaming speech recognition with NeMo CTC models
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-nemo-fast-conformer-ctc-be-de-en-es-fr-hr-it-pl-ru-uk-20k.tar.bz2
|
|
|
|
|
tar xvf sherpa-onnx-nemo-fast-conformer-ctc-be-de-en-es-fr-hr-it-pl-ru-uk-20k.tar.bz2
|
|
|
|
|
rm sherpa-onnx-nemo-fast-conformer-ctc-be-de-en-es-fr-hr-it-pl-ru-uk-20k.tar.bz2
|
|
|
|
|
|
|
|
|
|
node ./test_asr_non_streaming_nemo_ctc.js
|
|
|
|
|
|
|
|
|
|
# To run VAD + non-streaming ASR with Paraformer using a microphone
|
|
|
|
|
npm install naudiodon2
|
|
|
|
|
node ./test_vad_asr_non_streaming_nemo_ctc_microphone.js
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Non-streaming speech recognition with Paraformer
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
wget 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_asr_non_streaming_paraformer.js
|
|
|
|
|
|
|
|
|
|
# To run VAD + non-streaming ASR with Paraformer using a microphone
|
|
|
|
|
npm install naudiodon2
|
|
|
|
|
node ./test_vad_asr_non_streaming_paraformer_microphone.js
|
|
|
|
|
```
|