Add JavaScript API (WebAssembly) for FireRedAsr model. (#1874)

This commit is contained in:
Fangjun Kuang
2025-02-17 12:54:18 +08:00
committed by GitHub
parent 050df2a357
commit 7ad44bc43a
6 changed files with 112 additions and 4 deletions

View File

@@ -216,6 +216,21 @@ tar xvf sherpa-onnx-whisper-tiny.en.tar.bz2
node ./test-offline-whisper.js
```
## ./test-offline-fire-red-asr.js
[./test-offline-fire-red-asr.js](./test-offline-fire-red-asr.js) demonstrates
how to decode a file with a FireRedAsr AED model.
You can use the following command to run it:
```bash
wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16.tar.bz2
tar xvf sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16.tar.bz2
rm sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16.tar.bz2
node ./test-offline-fire-red-asr.js
```
## ./test-offline-moonshine.js
[./test-offline-moonshine.js](./test-offline-moonshine.js) demonstrates

View File

@@ -1,7 +1,7 @@
{
"dependencies": {
"naudiodon2": "^2.4.0",
"sherpa-onnx": "*",
"sherpa-onnx": "^1.10.44",
"wav": "^1.0.2"
}
}

View File

@@ -0,0 +1,37 @@
// Copyright (c) 2025 Xiaomi Corporation (authors: Fangjun Kuang)
//
const sherpa_onnx = require('sherpa-onnx');
function createOfflineRecognizer() {
let modelConfig = {
fireRedAsr: {
encoder:
'./sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16/encoder.int8.onnx',
decoder:
'./sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16/decoder.int8.onnx',
},
tokens: './sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16/tokens.txt',
debug: 1,
};
let config = {
modelConfig: modelConfig,
};
return sherpa_onnx.createOfflineRecognizer(config);
}
recognizer = createOfflineRecognizer();
stream = recognizer.createStream();
const waveFilename =
'./sherpa-onnx-fire-red-asr-large-zh_en-2025-02-16/test_wavs/0.wav';
const wave = sherpa_onnx.readWave(waveFilename);
stream.acceptWaveform(wave.sampleRate, wave.samples);
recognizer.decode(stream);
const text = recognizer.getResult(stream).text;
console.log(text);
stream.free();
recognizer.free();