Skip to content

Commit

Permalink
Fix sherpa-onnx-node-version in node examples (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored May 15, 2024
1 parent 03c956a commit c2dcdab
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/node-addon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ for usages.

||Method|Support multiple threads|Minimum required node version|
|---|---|---|---|
|this package| https://github.com/nodejs/node-addon-api | Yes | v10|
|this package| https://github.com/nodejs/node-addon-api | Yes | v16|
|https://www.npmjs.com/package/sherpa-onnx| WebAssembly | No | v18|
4 changes: 3 additions & 1 deletion .github/workflows/test-nodejs-addon-npm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-11, macos-14, ubuntu-20.04, ubuntu-22.04, windows-latest]
os: [macos-latest, macos-14, ubuntu-20.04, ubuntu-22.04, windows-latest]
node-version: ["16", "17", "18", "19", "21", "22"]

steps:
Expand Down Expand Up @@ -73,6 +73,8 @@ jobs:
export DYLD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-darwin-x64:$DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-darwin-arm64:$DYLD_LIBRARY_PATH
export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-darwin-x64:$DYLD_LIBRARY_PATH
export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-darwin-arm64:$DYLD_LIBRARY_PATH
export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-linux-x64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$PWD/node_modules/sherpa-onnx-linux-arm64:$LD_LIBRARY_PATH
Expand Down
2 changes: 1 addition & 1 deletion nodejs-addon-examples/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Introduction

Note: You need `Node >= 10`.
Note: You need `Node >= 16`.

This repo contains examples for NodeJS.
It uses [node-addon-api](https://github.com/nodejs/node-addon-api) to wrap
Expand Down
3 changes: 1 addition & 2 deletions nodejs-addon-examples/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"dependencies": {
"perf_hooks": "*",
"sherpa-onnx-node": "*"
"sherpa-onnx-node": "^1.0.24"
}
}
5 changes: 2 additions & 3 deletions nodejs-addon-examples/test_asr_non_streaming_nemo_ctc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) 2024 Xiaomi Corporation
const sherpa_onnx = require('sherpa-onnx-node');
const performance = require('perf_hooks').performance;

// Please download test files from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models
Expand All @@ -27,14 +26,14 @@ const waveFilename =

const recognizer = new sherpa_onnx.OfflineRecognizer(config);
console.log('Started')
let start = performance.now();
let start = Date.now();
const stream = recognizer.createStream();
const wave = sherpa_onnx.readWave(waveFilename);
stream.acceptWaveform({sampleRate: wave.sampleRate, samples: wave.samples});

recognizer.decode(stream);
result = recognizer.getResult(stream)
let stop = performance.now();
let stop = Date.now();
console.log('Done')

const elapsed_seconds = (stop - start) / 1000;
Expand Down
6 changes: 2 additions & 4 deletions nodejs-addon-examples/test_asr_non_streaming_paraformer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) 2024 Xiaomi Corporation
const sherpa_onnx = require('sherpa-onnx-node');
const performance = require('perf_hooks').performance;


// Please download test files from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models
Expand All @@ -26,14 +24,14 @@ const waveFilename =

const recognizer = new sherpa_onnx.OfflineRecognizer(config);
console.log('Started')
let start = performance.now();
let start = Date.now();
const stream = recognizer.createStream();
const wave = sherpa_onnx.readWave(waveFilename);
stream.acceptWaveform({sampleRate: wave.sampleRate, samples: wave.samples});

recognizer.decode(stream);
result = recognizer.getResult(stream)
let stop = performance.now();
let stop = Date.now();
console.log('Done')

const elapsed_seconds = (stop - start) / 1000;
Expand Down
6 changes: 2 additions & 4 deletions nodejs-addon-examples/test_asr_non_streaming_transducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) 2024 Xiaomi Corporation
const sherpa_onnx = require('sherpa-onnx-node');
const performance = require('perf_hooks').performance;


// Please download test files from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models
Expand Down Expand Up @@ -30,14 +28,14 @@ const waveFilename = './sherpa-onnx-zipformer-en-2023-04-01/test_wavs/1.wav';

const recognizer = new sherpa_onnx.OfflineRecognizer(config);
console.log('Started')
let start = performance.now();
let start = Date.now();
const stream = recognizer.createStream();
const wave = sherpa_onnx.readWave(waveFilename);
stream.acceptWaveform({sampleRate: wave.sampleRate, samples: wave.samples});

recognizer.decode(stream);
result = recognizer.getResult(stream)
let stop = performance.now();
let stop = Date.now();
console.log('Done')

const elapsed_seconds = (stop - start) / 1000;
Expand Down
6 changes: 2 additions & 4 deletions nodejs-addon-examples/test_asr_non_streaming_whisper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) 2024 Xiaomi Corporation
const sherpa_onnx = require('sherpa-onnx-node');
const performance = require('perf_hooks').performance;


// Please download test files from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models
Expand All @@ -26,14 +24,14 @@ const waveFilename = './sherpa-onnx-whisper-tiny.en/test_wavs/0.wav';

const recognizer = new sherpa_onnx.OfflineRecognizer(config);
console.log('Started')
let start = performance.now();
let start = Date.now();
const stream = recognizer.createStream();
const wave = sherpa_onnx.readWave(waveFilename);
stream.acceptWaveform({sampleRate: wave.sampleRate, samples: wave.samples});

recognizer.decode(stream);
result = recognizer.getResult(stream)
let stop = performance.now();
let stop = Date.now();
console.log('Done')

const elapsed_seconds = (stop - start) / 1000;
Expand Down
6 changes: 2 additions & 4 deletions nodejs-addon-examples/test_asr_streaming_ctc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) 2024 Xiaomi Corporation
const sherpa_onnx = require('sherpa-onnx-node');
const performance = require('perf_hooks').performance;


// Please download test files from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models
Expand All @@ -28,7 +26,7 @@ const waveFilename =

const recognizer = new sherpa_onnx.OnlineRecognizer(config);
console.log('Started')
let start = performance.now();
let start = Date.now();
const stream = recognizer.createStream();
const wave = sherpa_onnx.readWave(waveFilename);
stream.acceptWaveform({sampleRate: wave.sampleRate, samples: wave.samples});
Expand All @@ -40,7 +38,7 @@ while (recognizer.isReady(stream)) {
recognizer.decode(stream);
}
result = recognizer.getResult(stream)
let stop = performance.now();
let stop = Date.now();
console.log('Done')

const elapsed_seconds = (stop - start) / 1000;
Expand Down
6 changes: 2 additions & 4 deletions nodejs-addon-examples/test_asr_streaming_ctc_hlg.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) 2024 Xiaomi Corporation
const sherpa_onnx = require('sherpa-onnx-node');
const performance = require('perf_hooks').performance;


// Please download test files from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models
Expand Down Expand Up @@ -31,7 +29,7 @@ const waveFilename =

const recognizer = new sherpa_onnx.OnlineRecognizer(config);
console.log('Started')
let start = performance.now();
let start = Date.now();
const stream = recognizer.createStream();
const wave = sherpa_onnx.readWave(waveFilename);
stream.acceptWaveform({sampleRate: wave.sampleRate, samples: wave.samples});
Expand All @@ -43,7 +41,7 @@ while (recognizer.isReady(stream)) {
recognizer.decode(stream);
}
result = recognizer.getResult(stream)
let stop = performance.now();
let stop = Date.now();
console.log('Done')

const elapsed_seconds = (stop - start) / 1000;
Expand Down
6 changes: 2 additions & 4 deletions nodejs-addon-examples/test_asr_streaming_paraformer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) 2024 Xiaomi Corporation
const sherpa_onnx = require('sherpa-onnx-node');
const performance = require('perf_hooks').performance;


// Please download test files from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models
Expand Down Expand Up @@ -29,7 +27,7 @@ const waveFilename =

const recognizer = new sherpa_onnx.OnlineRecognizer(config);
console.log('Started')
let start = performance.now();
let start = Date.now();
const stream = recognizer.createStream();
const wave = sherpa_onnx.readWave(waveFilename);
stream.acceptWaveform({sampleRate: wave.sampleRate, samples: wave.samples});
Expand All @@ -41,7 +39,7 @@ while (recognizer.isReady(stream)) {
recognizer.decode(stream);
}
result = recognizer.getResult(stream)
let stop = performance.now();
let stop = Date.now();
console.log('Done')

const elapsed_seconds = (stop - start) / 1000;
Expand Down
6 changes: 2 additions & 4 deletions nodejs-addon-examples/test_asr_streaming_transducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) 2024 Xiaomi Corporation
const sherpa_onnx = require('sherpa-onnx-node');
const performance = require('perf_hooks').performance;


// Please download test files from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models
Expand Down Expand Up @@ -32,7 +30,7 @@ const waveFilename =

const recognizer = new sherpa_onnx.OnlineRecognizer(config);
console.log('Started')
let start = performance.now();
let start = Date.now();
const stream = recognizer.createStream();
const wave = sherpa_onnx.readWave(waveFilename);
stream.acceptWaveform({sampleRate: wave.sampleRate, samples: wave.samples});
Expand All @@ -44,7 +42,7 @@ while (recognizer.isReady(stream)) {
recognizer.decode(stream);
}
result = recognizer.getResult(stream)
let stop = performance.now();
let stop = Date.now();
console.log('Done')

const elapsed_seconds = (stop - start) / 1000;
Expand Down
4 changes: 2 additions & 2 deletions nodejs-addon-examples/test_audio_tagging_ced.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ const testWaves = [
console.log('------');

for (let filename of testWaves) {
const start = performance.now();
const start = Date.now();
const stream = at.createStream();
const wave = sherpa_onnx.readWave(filename);
stream.acceptWaveform({sampleRate: wave.sampleRate, samples: wave.samples});
const events = at.compute(stream);
const stop = performance.now();
const stop = Date.now();

const elapsed_seconds = (stop - start) / 1000;
const duration = wave.samples.length / wave.sampleRate;
Expand Down
4 changes: 2 additions & 2 deletions nodejs-addon-examples/test_audio_tagging_zipformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const testWaves = [
console.log('------');

for (let filename of testWaves) {
const start = performance.now();
const start = Date.now();
const stream = at.createStream();
const wave = sherpa_onnx.readWave(filename);
stream.acceptWaveform({sampleRate: wave.sampleRate, samples: wave.samples});
const events = at.compute(stream);
const stop = performance.now();
const stop = Date.now();

const elapsed_seconds = (stop - start) / 1000;
const duration = wave.samples.length / wave.sampleRate;
Expand Down
6 changes: 2 additions & 4 deletions nodejs-addon-examples/test_keyword_spotter_transducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) 2024 Xiaomi Corporation
const sherpa_onnx = require('sherpa-onnx-node');
const performance = require('perf_hooks').performance;


// Please download test files from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/kws-models
Expand Down Expand Up @@ -34,7 +32,7 @@ const waveFilename =

const kws = new sherpa_onnx.KeywordSpotter(config);
console.log('Started')
let start = performance.now();
let start = Date.now();
const stream = kws.createStream();
const wave = sherpa_onnx.readWave(waveFilename);
stream.acceptWaveform({sampleRate: wave.sampleRate, samples: wave.samples});
Expand All @@ -50,7 +48,7 @@ while (kws.isReady(stream)) {
}
kws.decode(stream);
}
let stop = performance.now();
let stop = Date.now();

console.log('Done')

Expand Down
5 changes: 2 additions & 3 deletions nodejs-addon-examples/test_tts_non_streaming_vits_coqui_de.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) 2024 Xiaomi Corporation
const sherpa_onnx = require('sherpa-onnx-node');
const performance = require('perf_hooks').performance;

// please download model files from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/tts-models
Expand All @@ -24,9 +23,9 @@ const tts = createOfflineTts();

const text = 'Alles hat ein Ende, nur die Wurst hat zwei.'

let start = performance.now();
let start = Date.now();
const audio = tts.generate({text: text, sid: 0, speed: 1.0});
let stop = performance.now();
let stop = Date.now();
const elapsed_seconds = (stop - start) / 1000;
const duration = audio.samples.length / audio.sampleRate;
const real_time_factor = elapsed_seconds / duration;
Expand Down
5 changes: 2 additions & 3 deletions nodejs-addon-examples/test_tts_non_streaming_vits_piper_en.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) 2024 Xiaomi Corporation
const sherpa_onnx = require('sherpa-onnx-node');
const performance = require('perf_hooks').performance;

// please download model files from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/tts-models
Expand All @@ -27,9 +26,9 @@ const text =
'Today as always, men fall into two groups: slaves and free men. Whoever does not have two-thirds of his day for himself, is a slave, whatever he may be: a statesman, a businessman, an official, or a scholar.'


let start = performance.now();
let start = Date.now();
const audio = tts.generate({text: text, sid: 0, speed: 1.0});
let stop = performance.now();
let stop = Date.now();
const elapsed_seconds = (stop - start) / 1000;
const duration = audio.samples.length / audio.sampleRate;
const real_time_factor = elapsed_seconds / duration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) 2024 Xiaomi Corporation
const sherpa_onnx = require('sherpa-onnx-node');
const performance = require('perf_hooks').performance;

// please download model files from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/tts-models
Expand Down Expand Up @@ -29,9 +28,9 @@ const tts = createOfflineTts();
const text =
'他在长沙出生,长白山长大,去过长江,现在他是一个银行的行长,主管行政工作。有困难,请拨110,或者13020240513。今天是2024年5月13号, 他上个月的工资是12345块钱。'

let start = performance.now();
let start = Date.now();
const audio = tts.generate({text: text, sid: 88, speed: 1.0});
let stop = performance.now();
let stop = Date.now();
const elapsed_seconds = (stop - start) / 1000;
const duration = audio.samples.length / audio.sampleRate;
const real_time_factor = elapsed_seconds / duration;
Expand Down
5 changes: 2 additions & 3 deletions nodejs-addon-examples/test_tts_non_streaming_vits_zh_ll.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) 2024 Xiaomi Corporation
const sherpa_onnx = require('sherpa-onnx-node');
const performance = require('perf_hooks').performance;

// please download model files from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/tts-models
Expand Down Expand Up @@ -29,9 +28,9 @@ const tts = createOfflineTts();
const text =
'当夜幕降临,星光点点,伴随着微风拂面,我在静谧中感受着时光的流转,思念如涟漪荡漾,梦境如画卷展开,我与自然融为一体,沉静在这片宁静的美丽之中,感受着生命的奇迹与温柔。2024年5月13号,拨打110或者18920240513。123456块钱。'

let start = performance.now();
let start = Date.now();
const audio = tts.generate({text: text, sid: 2, speed: 1.0});
let stop = performance.now();
let stop = Date.now();
const elapsed_seconds = (stop - start) / 1000;
const duration = audio.samples.length / audio.sampleRate;
const real_time_factor = elapsed_seconds / duration;
Expand Down

0 comments on commit c2dcdab

Please sign in to comment.