This repository has been archived on 2025-08-26. You can view files and clone it, but cannot push or open issues or pull requests.
Files
enginex-mr_series-sherpa-onnx/nodejs-examples/test-offline-whisper.js
Fangjun Kuang 282211c01f Remove portaudio-go in Go API examples. (#2317)
Replace the deprecated portaudio-go integration with malgo in the Go real-time 
speech recognition example and correct version string typos in the Node.js examples.

- Fixed “verison” typo in Node.js console logs.
- Swapped out portaudio-go for malgo in the Go microphone example, 
   introducing initRecognizer, callback-driven streaming, and sample conversion.
- Removed portaudio-go from go.mod.
2025-06-26 11:33:50 +08:00

40 lines
1.1 KiB
JavaScript

// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang)
//
const sherpa_onnx = require('sherpa-onnx');
console.log(`version : ${sherpa_onnx.version}`);
console.log(`git sha1: ${sherpa_onnx.gitSha1}`);
console.log(`git date: ${sherpa_onnx.gitDate}`);
function createOfflineRecognizer() {
let modelConfig = {
whisper: {
encoder: './sherpa-onnx-whisper-tiny.en/tiny.en-encoder.int8.onnx',
decoder: './sherpa-onnx-whisper-tiny.en/tiny.en-decoder.int8.onnx',
language: '',
task: 'transcribe',
tailPaddings: -1,
},
tokens: './sherpa-onnx-whisper-tiny.en/tiny.en-tokens.txt',
};
let config = {
modelConfig: modelConfig,
};
return sherpa_onnx.createOfflineRecognizer(config);
}
recognizer = createOfflineRecognizer();
stream = recognizer.createStream();
const waveFilename = './sherpa-onnx-whisper-tiny.en/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();