Add Javascript (WebAssembly) API for Dolphin CTC models (#2093)

This commit is contained in:
Fangjun Kuang
2025-04-03 15:02:06 +08:00
committed by GitHub
parent 74f402e490
commit 639ad1744f
9 changed files with 172 additions and 50 deletions

View File

@@ -140,6 +140,20 @@ node ./test-offline-tts-vits-zh.js
In the following, we demonstrate how to decode files and how to perform
speech recognition with a microphone with `nodejs`.
## ./test-offline-dolphin-ctc.js
[./test-offline-dolphin-ctc.js](./test-offline-dolphin-ctc.js) demonstrates
how to decode a file with a [Dolphin](https://github.com/DataoceanAI/Dolphin) CTC model.
You can use the following command to run it:
```bash
wget -q https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
tar xvf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
rm sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
node ./test-offline-dolphin-ctc.js
```
## ./test-offline-nemo-ctc.js
[./test-offline-nemo-ctc.js](./test-offline-nemo-ctc.js) demonstrates

View File

@@ -0,0 +1,37 @@
// Copyright (c) 2025 Xiaomi Corporation (authors: Fangjun Kuang)
//
const fs = require('fs');
const {Readable} = require('stream');
const wav = require('wav');
const sherpa_onnx = require('sherpa-onnx');
function createOfflineRecognizer() {
let config = {
modelConfig: {
dolphin: {
model:
'./sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02/model.int8.onnx',
},
tokens:
'./sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02/tokens.txt',
}
};
return sherpa_onnx.createOfflineRecognizer(config);
}
const recognizer = createOfflineRecognizer();
const stream = recognizer.createStream();
const waveFilename =
'./sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02/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();