Skip to content

Commit

Permalink
mod_vad_detect (#97)
Browse files Browse the repository at this point in the history
* mod_vad_detect

* mod_vad_detect

* mod_vad_detect

* mod_vad_detect
  • Loading branch information
xquanluu authored May 28, 2024
1 parent 4871433 commit ad5f580
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions lib/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,85 @@ class Endpoint extends Emitter {
});
});
}
/**
* VAD detection
* @param {string} opts.strategy = one-shot, continuous, default is one-shot
* @param {string} [opts.mode] Default value is 2
* -1 ("disable fvad, use native")
* - 0 ("quality")
* - 1 ("low bitrate")
* - 2 ("aggressive")
* - 3 ("very aggressive")
* @param {string} [opts.silenceMs] - number of milliseconds of silence that must
* come to transition from talking to stop talking, default is 250 ms
* @param {object|string} [opts.voiceMs] - number of milliseconds of voice that
* must come to transition to start talking, default is 150ms
* @param {function} [callback] - callback invoked when api request completes
* @return {Promise|Endpoint} returns a Promise if no callback supplied; otherwise
* a reference to the Endpoint object
* Freeswitch command
* uuid_vad_detect [start|stop] [one-shot|continuous] mode silence-ms voice-ms [bugname]
*/
startVadDetection(opts, callback) {
opts = opts || {};
const strategy = opts.strategy || 'one-shot';
const mode = opts.mode || 2;
const silenceMs = opts.silenceMs || 250;
const voiceMs = opts.voiceMs || 150;
const bugname = opts.bugname || 'vad_detection';

const __x = (callback) => {
const args = [this.uuid, 'start', strategy, mode, silenceMs, voiceMs, bugname];
this.api('uuid_vad_detect', args, (err, evt) => {
if (err) return callback(err);
const body = evt.getBody() ;
if (0 === body.indexOf('+OK')) {
return callback(null) ;
}
callback(new Error(body)) ;
});
};

if (callback) {
__x(callback) ;
return this ;
}

return new Promise((resolve, reject) => {
__x((err, result) => {
if (err) return reject(err);
resolve(result);
});
});
}

stopVadDetection(opts, callback) {
opts = opts || {};
const bugname = opts.bugname || 'vad_detection';
const __x = (callback) => {
const args = [this.uuid, 'stop', bugname];
this.api('uuid_vad_detect', args, (err, evt) => {
if (err) return callback(err);
const body = evt.getBody() ;
if (0 === body.indexOf('+OK')) {
return callback(null) ;
}
callback(new Error(body)) ;
});
};

if (callback) {
__x(callback) ;
return this ;
}

return new Promise((resolve, reject) => {
__x((err, result) => {
if (err) return reject(err);
resolve(result);
});
});
}

/**
* Fork audio from the endpoint to a remote websocket server
Expand Down

0 comments on commit ad5f580

Please sign in to comment.