Repository navigation
Add JavaScript (node-addon) API for ten-vad #2383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,14 +8,28 @@ const sherpa_onnx = require('sherpa-onnx-node'); | |||||||||||||||||||||||||
| function createVad() { | ||||||||||||||||||||||||||
| // please download silero_vad.onnx from | ||||||||||||||||||||||||||
| // https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/silero_vad.onnx | ||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||
| // OR | ||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||
| // please download ten-vad.onnx from | ||||||||||||||||||||||||||
| // https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/ten-vad.onnx | ||||||||||||||||||||||||||
| const config = { | ||||||||||||||||||||||||||
| sileroVad: { | ||||||||||||||||||||||||||
| // model: '', | ||||||||||||||||||||||||||
| model: './silero_vad.onnx', | ||||||||||||||||||||||||||
| threshold: 0.5, | ||||||||||||||||||||||||||
| minSpeechDuration: 0.25, | ||||||||||||||||||||||||||
| minSilenceDuration: 0.5, | ||||||||||||||||||||||||||
| windowSize: 512, | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| tenVad: { | ||||||||||||||||||||||||||
| model: '', | ||||||||||||||||||||||||||
| // model: './ten-vad.onnx', | ||||||||||||||||||||||||||
| threshold: 0.5, | ||||||||||||||||||||||||||
| minSpeechDuration: 0.25, | ||||||||||||||||||||||||||
| minSilenceDuration: 0.5, | ||||||||||||||||||||||||||
| windowSize: 256, | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
| sampleRate: 16000, | ||||||||||||||||||||||||||
| debug: true, | ||||||||||||||||||||||||||
| numThreads: 1, | ||||||||||||||||||||||||||
|
|
@@ -47,7 +61,10 @@ const ai = new portAudio.AudioIO({ | |||||||||||||||||||||||||
| let printed = false; | ||||||||||||||||||||||||||
| let index = 0; | ||||||||||||||||||||||||||
| ai.on('data', data => { | ||||||||||||||||||||||||||
| const windowSize = vad.config.sileroVad.windowSize; | ||||||||||||||||||||||||||
| const windowSize = vad.config.sileroVad.model != '' ? | ||||||||||||||||||||||||||
| vad.config.sileroVad.windowSize : | ||||||||||||||||||||||||||
| vad.config.tenVad.windowSize; | ||||||||||||||||||||||||||
|
Comment on lines
+64
to
+66
|
||||||||||||||||||||||||||
| const windowSize = vad.config.sileroVad.model != '' ? | |
| vad.config.sileroVad.windowSize : | |
| vad.config.tenVad.windowSize; | |
| const windowSize = vad.config.tenVad.model != '' ? | |
| vad.config.tenVad.windowSize : | |
| vad.config.sileroVad.windowSize; |
Copilot
AI
Jul 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition checks sileroVad.model to choose the window size but should instead check tenVad.model to properly select the Ten VAD configuration when provided.
| const windowSize = vad.config.sileroVad.model != '' ? | |
| vad.config.sileroVad.windowSize : | |
| vad.config.tenVad.windowSize; | |
| const windowSize = vad.config.tenVad.model != '' ? | |
| vad.config.tenVad.windowSize : | |
| vad.config.sileroVad.windowSize; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,9 +91,11 @@ ai.on('data', data => { | |
| const fullLang = display.of(lang); | ||
|
|
||
| const filename = `${index}-${fullLang}-${ | ||
| new Date() | ||
| .toLocaleTimeString('en-US', {hour12: false}) | ||
| .split(' ')[0]}.wav`; | ||
| new Date() | ||
| .toLocaleTimeString('en-US', {hour12: false}) | ||
| .split(' ')[0]}.wav` | ||
| .replace(/:/g, '-'); | ||
|
Comment on lines
93
to
+97
|
||
|
|
||
| sherpa_onnx.writeWave( | ||
| filename, | ||
| {samples: segment.samples, sampleRate: vad.config.sampleRate}); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TenVadConfigdoes not have amaxSpeechDurationproperty, but this line mapsmax_speech_duration. Either addmaxSpeechDurationtoTenVadConfigor remove this mapping to match the class definition.