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.
40 lines
1.1 KiB
JavaScript
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();
|