mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2026-02-13 09:49:30 +00:00
support noise isolation
This commit is contained in:
@@ -19,7 +19,8 @@ class TaskConfig extends Task {
|
||||
'vad',
|
||||
'ttsStream',
|
||||
'autoStreamTts',
|
||||
'disableTtsCache'
|
||||
'disableTtsCache',
|
||||
'noiseIsolation'
|
||||
].forEach((k) => this[k] = this.data[k] || {});
|
||||
|
||||
if ('notifyEvents' in this.data) {
|
||||
@@ -90,6 +91,7 @@ class TaskConfig extends Task {
|
||||
get hasNotifySttLatency() { return Object.keys(this.data).includes('notifySttLatency'); }
|
||||
get hasTtsStream() { return Object.keys(this.ttsStream).length; }
|
||||
get hasDisableTtsCache() { return Object.keys(this.data).includes('disableTtsCache'); }
|
||||
get hasNoiseIsolation() { return Object.keys(this.data).includes('noiseIsolation'); }
|
||||
|
||||
get summary() {
|
||||
const phrase = [];
|
||||
@@ -128,6 +130,7 @@ class TaskConfig extends Task {
|
||||
}
|
||||
if ('autoStreamTts' in this.data) phrase.push(`enable Say.stream value ${this.data.autoStreamTts ? 'on' : 'off'}`);
|
||||
if (this.hasDisableTtsCache) phrase.push(`disableTtsCache ${this.data.disableTtsCache ? 'on' : 'off'}`);
|
||||
if (this.hasNoiseIsolation) phrase.push(`noiseIsolation ${this.noiseIsolation.enable ? 'on' : 'off'}`);
|
||||
return `${this.name}{${phrase.join(',')}}`;
|
||||
}
|
||||
|
||||
@@ -365,6 +368,17 @@ class TaskConfig extends Task {
|
||||
this.logger.info(`set disableTtsCache = ${this.disableTtsCache}`);
|
||||
cs.disableTtsCache = this.data.disableTtsCache;
|
||||
}
|
||||
|
||||
if (this.hasNoiseIsolation) {
|
||||
const {enable, ...opts} = this.noiseIsolation;
|
||||
if (enable) {
|
||||
this.logger.debug({opts}, 'Config: enabling noiseIsolation');
|
||||
cs.startBackgroundTask('noiseIsolation', {verb: 'noiseIsolation', ...opts});
|
||||
} else {
|
||||
this.logger.info('Config: disabling noiseIsolation');
|
||||
cs.stopBackgroundTask('noiseIsolation');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async kill(cs) {
|
||||
|
||||
@@ -99,6 +99,9 @@ function makeTask(logger, obj, parent) {
|
||||
case TaskName.Alert:
|
||||
const TaskAlert = require('./alert');
|
||||
return new TaskAlert(logger, data, parent);
|
||||
case TaskName.NoiseIsolation:
|
||||
const TaskNoiseIsolation = require('./noise-isolation');
|
||||
return new TaskNoiseIsolation(logger, data, parent);
|
||||
}
|
||||
|
||||
// should never reach
|
||||
|
||||
90
lib/tasks/noise-isolation.js
Normal file
90
lib/tasks/noise-isolation.js
Normal file
@@ -0,0 +1,90 @@
|
||||
const Task = require('./task');
|
||||
const {TaskName, TaskPreconditions} = require('../utils/constants');
|
||||
|
||||
class TaskNoiseIsolation extends Task {
|
||||
constructor(logger, opts, parentTask) {
|
||||
super(logger, opts, parentTask);
|
||||
this.preconditions = TaskPreconditions.Endpoint;
|
||||
|
||||
this.vendor = this.data.vendor || 'krisp';
|
||||
this.direction = this.data.direction || 'read';
|
||||
this.level = typeof this.data.level === 'number' ? this.data.level : 100;
|
||||
this.model = this.data.model;
|
||||
}
|
||||
|
||||
get name() { return TaskName.NoiseIsolation; }
|
||||
|
||||
get apiCommand() {
|
||||
return `uuid_${this.vendor}_noise_isolation`;
|
||||
}
|
||||
|
||||
get summary() {
|
||||
return `${this.name}{vendor=${this.vendor},direction=${this.direction},level=${this.level}}`;
|
||||
}
|
||||
|
||||
async exec(cs, {ep}) {
|
||||
await super.exec(cs);
|
||||
this.ep = ep;
|
||||
|
||||
if (!ep?.connected) {
|
||||
this.logger.info('TaskNoiseIsolation:exec - no endpoint connected');
|
||||
this.notifyTaskDone();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await this._startNoiseIsolation(ep);
|
||||
await this.awaitTaskDone();
|
||||
} catch (err) {
|
||||
this.logger.error({err}, 'TaskNoiseIsolation:exec - error');
|
||||
}
|
||||
}
|
||||
|
||||
async _startNoiseIsolation(ep) {
|
||||
// API format: uuid_${vendor}_noise_isolation <uuid> start <direction> [level] [model]
|
||||
// model is only added if level is set
|
||||
const args = [ep.uuid, 'start', this.direction];
|
||||
if (this.level !== 100) {
|
||||
args.push(this.level);
|
||||
if (this.model) {
|
||||
args.push(this.model);
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.info({args, apiCommand: this.apiCommand}, 'TaskNoiseIsolation:_startNoiseIsolation');
|
||||
|
||||
try {
|
||||
const res = await ep.api(this.apiCommand, args.join(' '));
|
||||
if (!res.body?.startsWith('+OK')) {
|
||||
this.logger.error({res}, 'TaskNoiseIsolation:_startNoiseIsolation - error starting noise isolation');
|
||||
} else {
|
||||
this.logger.info('TaskNoiseIsolation:_startNoiseIsolation - noise isolation started');
|
||||
}
|
||||
} catch (err) {
|
||||
this.logger.error({err}, 'TaskNoiseIsolation:_startNoiseIsolation - error');
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async _stopNoiseIsolation(ep) {
|
||||
if (!ep?.connected) return;
|
||||
|
||||
const args = [ep.uuid, 'stop'];
|
||||
this.logger.info({args, apiCommand: this.apiCommand}, 'TaskNoiseIsolation:_stopNoiseIsolation');
|
||||
|
||||
try {
|
||||
await ep.api(this.apiCommand, args.join(' '));
|
||||
this.logger.info('TaskNoiseIsolation:_stopNoiseIsolation - noise isolation stopped');
|
||||
} catch (err) {
|
||||
this.logger.info({err}, 'TaskNoiseIsolation:_stopNoiseIsolation - error stopping noise isolation');
|
||||
}
|
||||
}
|
||||
|
||||
async kill(cs) {
|
||||
super.kill(cs);
|
||||
await this._stopNoiseIsolation(this.ep);
|
||||
this.notifyTaskDone();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TaskNoiseIsolation;
|
||||
Reference in New Issue
Block a user