improving the vad filter
This commit is contained in:
parent
c5a9f266fd
commit
395eff3b8e
3 changed files with 32 additions and 4 deletions
|
@ -54,6 +54,12 @@ namespace audio {
|
||||||
get_threshold() : number;
|
get_threshold() : number;
|
||||||
set_threshold(value: number) : Promise<void>;
|
set_threshold(value: number) : Promise<void>;
|
||||||
|
|
||||||
|
get_attack_smooth() : number;
|
||||||
|
get_release_smooth() : number;
|
||||||
|
|
||||||
|
set_attack_smooth(value: number);
|
||||||
|
set_release_smooth(value: number);
|
||||||
|
|
||||||
callback_level?: (value: number) => any;
|
callback_level?: (value: number) => any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,6 +167,10 @@ class RecorderProfile {
|
||||||
if(this.config.vad_type === "threshold") {
|
if(this.config.vad_type === "threshold") {
|
||||||
const filter = this.input.get_filter(audio.recorder.filter.Type.THRESHOLD) as audio.recorder.filter.ThresholdFilter;
|
const filter = this.input.get_filter(audio.recorder.filter.Type.THRESHOLD) as audio.recorder.filter.ThresholdFilter;
|
||||||
await filter.set_threshold(this.config.vad_threshold.threshold);
|
await filter.set_threshold(this.config.vad_threshold.threshold);
|
||||||
|
await filter.set_margin_frames(10); /* 500ms */
|
||||||
|
|
||||||
|
filter.set_attack_smooth(.25);
|
||||||
|
filter.set_release_smooth(.9);
|
||||||
|
|
||||||
this.input.enable_filter(audio.recorder.filter.Type.THRESHOLD);
|
this.input.enable_filter(audio.recorder.filter.Type.THRESHOLD);
|
||||||
} else if(this.config.vad_type === "push_to_talk") {
|
} else if(this.config.vad_type === "push_to_talk") {
|
||||||
|
|
|
@ -90,6 +90,10 @@ namespace audio {
|
||||||
private _silence_count = 0;
|
private _silence_count = 0;
|
||||||
private _margin_frames = 5;
|
private _margin_frames = 5;
|
||||||
|
|
||||||
|
private _current_level = 0;
|
||||||
|
private _smooth_release = 0;
|
||||||
|
private _smooth_attack = 0;
|
||||||
|
|
||||||
finalize() {
|
finalize() {
|
||||||
clearInterval(this._update_task);
|
clearInterval(this._update_task);
|
||||||
this._update_task = 0;
|
this._update_task = 0;
|
||||||
|
@ -159,8 +163,25 @@ namespace audio {
|
||||||
level = 100 + ( db * 1.92 );
|
level = 100 + ( db * 1.92 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const last_level = this._current_level;
|
||||||
|
let smooth;
|
||||||
|
if(this._silence_count == 0)
|
||||||
|
smooth = this._smooth_release;
|
||||||
|
else
|
||||||
|
smooth = this._smooth_attack;
|
||||||
|
this._current_level = last_level * smooth + level * (1 - smooth);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this._update_gain_node();
|
||||||
|
if(this.callback_level)
|
||||||
|
this.callback_level(this._current_level);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _update_gain_node() {
|
||||||
let state = false;
|
let state = false;
|
||||||
if(level > this._threshold) {
|
if(this._current_level > this._threshold) {
|
||||||
this._silence_count = 0;
|
this._silence_count = 0;
|
||||||
state = true;
|
state = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -179,9 +200,6 @@ namespace audio {
|
||||||
this.callback_active_change(true);
|
this.callback_active_change(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.callback_level)
|
|
||||||
this.callback_level(level);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue