Skip to content

Commit 7645170

Browse files
committed
add support for silero vad
1 parent 9ec3a34 commit 7645170

File tree

3 files changed

+38
-26
lines changed

3 files changed

+38
-26
lines changed

lib/endpoint.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -936,17 +936,20 @@ class Endpoint extends Emitter {
936936
}
937937
/**
938938
* VAD detection
939-
* @param {string} opts.strategy = one-shot, continuous, default is one-shot
940-
* @param {string} [opts.mode] Default value is 2
939+
* @param {string} opts.vendor - vendor of VAD detection engine: 'native; (default), 'silero'
940+
* @param {string} opts.strategy = one-shot, continuous, default is continuous
941+
* @param {string} [opts.mode] (native) Default value is 2
941942
* -1 ("disable fvad, use native")
942943
* - 0 ("quality")
943944
* - 1 ("low bitrate")
944945
* - 2 ("aggressive")
945946
* - 3 ("very aggressive")
946-
* @param {string} [opts.silenceMs] - number of milliseconds of silence that must
947-
* come to transition from talking to stop talking, default is 250 ms
948-
* @param {object|string} [opts.voiceMs] - number of milliseconds of voice that
949-
* must come to transition to start talking, default is 150ms
947+
* @param {number} [opts.silenceMs] - number of milliseconds of silence that must
948+
* come to transition from talking to stop talking, default is 100 ms
949+
* @param {number} [opts.voiceMs] - number of milliseconds of voice that
950+
* must come to transition to start talking, default is 250ms
951+
* @param {number} [opts.threshold] - (silero) probability threshold for speech, default is 0.5
952+
* @param {number} [opts.speechPadMs] - (silero) number of milliseconds of speech padding, default is 30ms
950953
* @param {function} [callback] - callback invoked when api request completes
951954
* @return {Promise|Endpoint} returns a Promise if no callback supplied; otherwise
952955
* a reference to the Endpoint object
@@ -955,15 +958,21 @@ class Endpoint extends Emitter {
955958
*/
956959
startVadDetection(opts, callback) {
957960
opts = opts || {};
958-
const strategy = opts.strategy || 'one-shot';
961+
const vendor = opts.vendor || 'native';
962+
const apiCall = vendor === 'native' ? 'uuid_vad_detect' : 'uuid_vad_silero';
963+
const strategy = opts.strategy || 'continuous';
959964
const mode = opts.mode || 2;
960-
const silenceMs = opts.silenceMs || 250;
961-
const voiceMs = opts.voiceMs || 150;
962-
const bugname = opts.bugname || 'vad_detection';
965+
const silenceMs = opts.silenceMs || 100;
966+
const voiceMs = opts.voiceMs || 250;
967+
const threshold = opts.threshold || 0.5;
968+
const speechPadMs = opts.speechPadMs || 30;
969+
const bugname = opts.bugname || (vendor === 'native' ? 'vad_detection' : 'vad_detection_silero');
963970

964971
const __x = (callback) => {
965-
const args = [this.uuid, 'start', strategy, mode, silenceMs, voiceMs, bugname];
966-
this.api('uuid_vad_detect', args, (err, evt) => {
972+
const args = vendor === 'native' ?
973+
[this.uuid, 'start', strategy, mode, silenceMs, voiceMs, bugname] :
974+
[this.uuid, 'start', strategy, threshold, silenceMs, voiceMs, speechPadMs, bugname];
975+
this.api(apiCall, args, (err, evt) => {
967976
if (err) return callback(err);
968977
const body = evt.getBody() ;
969978
if (0 === body.indexOf('+OK')) {
@@ -988,10 +997,13 @@ class Endpoint extends Emitter {
988997

989998
stopVadDetection(opts, callback) {
990999
opts = opts || {};
991-
const bugname = opts.bugname || 'vad_detection';
1000+
const vendor = opts.vendor || 'native';
1001+
const apiCall = vendor === 'native' ? 'uuid_vad_detect' : 'uuid_vad_silero';
1002+
const bugname = opts.bugname || (vendor === 'native' ? 'vad_detection' : 'vad_detection_silero');
1003+
9921004
const __x = (callback) => {
9931005
const args = [this.uuid, 'stop', bugname];
994-
this.api('uuid_vad_detect', args, (err, evt) => {
1006+
this.api(apiCall, args, (err, evt) => {
9951007
if (err) return callback(err);
9961008
const body = evt.getBody() ;
9971009
if (0 === body.indexOf('+OK')) {

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drachtio-fsmrf",
3-
"version": "4.0.4",
3+
"version": "4.1.0",
44
"description": "freeswitch-based media resource function for drachtio",
55
"main": "lib/mrf.js",
66
"scripts": {
@@ -13,9 +13,9 @@
1313
"url": "git+https://github.com/drachtio/drachtio-fsmrf.git"
1414
},
1515
"engines": {
16-
"node": ">= 6.9.3"
16+
"node": ">= 18.0.0"
1717
},
18-
"author": "",
18+
"author": "Dave Horton",
1919
"license": "MIT",
2020
"bugs": {
2121
"url": "https://github.com/drachtio/drachtio-fsmrf/issues"

0 commit comments

Comments
 (0)