diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 1e3e1ce9..3f50a1db 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -3,10 +3,13 @@
-
-
-
-
+
+
+
+
+
+
+
@@ -29,100 +32,90 @@
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -146,6 +139,7 @@
update
on_data
on_connected
+ vad_vad_bar_filler
@@ -161,12 +155,9 @@
-
-
-
@@ -177,8 +168,6 @@
-
-
@@ -187,6 +176,12 @@
+
+
+
+
+
+
@@ -352,7 +347,7 @@
1519749313999
-
+
1520446012318
@@ -368,14 +363,22 @@
1520450076160
-
+
+ 1520452384034
+
+
+
+ 1520452384034
+
+
-
+
+
@@ -384,8 +387,8 @@
-
-
+
+
@@ -464,7 +467,8 @@
-
+
+
@@ -473,14 +477,6 @@
-
-
-
-
-
-
-
-
@@ -578,22 +574,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -602,14 +582,6 @@
-
-
-
-
-
-
-
-
@@ -666,16 +638,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -729,14 +691,6 @@
-
-
-
-
-
-
-
-
@@ -748,19 +702,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -777,22 +718,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -819,14 +744,6 @@
-
-
-
-
-
-
-
-
@@ -835,16 +752,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -887,5 +794,99 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/css/general.css b/css/general.css
index 16ebcbe9..26783d71 100644
--- a/css/general.css
+++ b/css/general.css
@@ -246,4 +246,47 @@ html {
border: gray solid;
border-width: 2px;
border-radius: 0px 6px 6px 6px;
+}
+
+.vad_vad_bar {
+ position: relative;
+ width: 100%;
+ height: 20px;
+}
+
+.vad_vad_bar .vad_vad_bar_filler {
+ background-color: green;
+ width: 50%;
+ height: 100%;
+}
+
+/* The slider itself */
+.vad_vad_slider {
+ margin: 0px;
+ background-color: gray;
+ -webkit-appearance: none; /* Override default CSS styles */
+ appearance: none;
+ width: 100%;
+ height: 100%;
+ outline: none;
+ opacity: 0.7; /* Set transparency (for mouse-over effects on hover) */
+ -webkit-transition: .2s; /* 0.2 seconds transition on hover */
+ transition: opacity .2s;
+}
+
+/* The slider handle (use -webkit- (Chrome, Opera, Safari, Edge) and -moz- (Firefox) to override default look) */
+.vad_vad_slider::-webkit-slider-thumb {
+ -webkit-appearance: none; /* Override default look */
+ appearance: none;
+ width: 2px; /* Set a specific slider handle width */
+ height: 20px; /* Slider handle height */
+ background: #000000; /* Green background */
+ cursor: pointer; /* Cursor on hover */
+}
+
+.vad_vad_slider::-moz-range-thumb {
+ width: 2px; /* Set a specific slider handle width */
+ height: 100%; /* Slider handle height */
+ background: #000000; /* Green background */
+ cursor: pointer; /* Cursor on hover */
}
\ No newline at end of file
diff --git a/index.html b/index.html
index 7d904683..f7b760b4 100644
--- a/index.html
+++ b/index.html
@@ -191,9 +191,14 @@
diff --git a/js/ui/modal/ModalSettings.ts b/js/ui/modal/ModalSettings.ts
index c69619e8..11554256 100644
--- a/js/ui/modal/ModalSettings.ts
+++ b/js/ui/modal/ModalSettings.ts
@@ -4,12 +4,13 @@
namespace Modals {
export function spawnSettingsModal() {
- const modal = createModal({
+ let modal;
+ modal = createModal({
header: "Settings",
body: () => {
let template = $("#tmpl_settings").tmpl();
template = $.spawn("div").append(template);
- initialiseSettingListeners(template = template.tabify());
+ initialiseSettingListeners(modal,template = template.tabify());
return template;
},
footer: () => {
@@ -31,16 +32,15 @@ namespace Modals {
modal.open();
}
- function initialiseSettingListeners(tag: JQuery) {
+ function initialiseSettingListeners(modal: Modal, tag: JQuery) {
//Voice
- initialiseVoiceListeners(tag.find(".settings_voice"));
+ initialiseVoiceListeners(modal, tag.find(".settings_voice"));
}
- function initialiseVoiceListeners(tag: JQuery) {
+ function initialiseVoiceListeners(modal: Modal, tag: JQuery) {
let currentVAD = globalClient.settings.global("vad_type");
tag.find("input[type=radio][name=\"vad_type\"]").change(function (this: HTMLButtonElement) {
- console.log(this.value + " => " + $(this).attr("display"));
tag.find(".vad_settings .vad_type").text($(this).attr("display"));
tag.find(".vad_settings .vad_type_settings").hide();
tag.find(".vad_settings .vad_type_" + this.value).show();
@@ -51,6 +51,17 @@ namespace Modals {
case "ppt":
let keyCode: number = Number.parseInt(globalClient.settings.global("vad_ppt_key", Key.T.toString()));
tag.find(".vat_ppt_key").text(String.fromCharCode(keyCode));
+ break;
+ case "vad":
+ let slider = tag.find(".vad_vad_slider");
+ let vad: VoiceActivityDetectorVAD = globalClient.voiceConnection.voiceRecorder.getVADHandler() as VoiceActivityDetectorVAD;
+ slider.val(vad.percentageThreshold);
+ slider.trigger("change");
+ vad.percentage_listener = per => {
+ tag.find(".vad_vad_bar_filler")
+ .css("width", per + "%");
+ };
+ break;
}
});
@@ -58,7 +69,6 @@ namespace Modals {
currentVAD = "ppt";
let elm = tag.find("input[type=radio][name=\"vad_type\"][value=\"" + currentVAD + "\"]");
elm.attr("checked", "true");
- elm.trigger("change");
tag.find(".vat_ppt_key").click(function () {
@@ -68,7 +78,6 @@ namespace Modals {
let head = $.spawn("div");
head.text("Type the key you wish");
head.css("background-color", "blue");
- console.log("SPAWNED!");
return head;
},
footer: ""
@@ -82,5 +91,26 @@ namespace Modals {
});
modal.open();
});
+
+
+ //VAD VAD
+ let slider = tag.find(".vad_vad_slider");
+ slider.on("input change", () => {
+ globalClient.settings.changeGlobal("vad_threshold", slider.val().toString());
+ let vad = globalClient.voiceConnection.voiceRecorder.getVADHandler();
+ if(vad instanceof VoiceActivityDetectorVAD)
+ vad.percentageThreshold = slider.val() as number;
+ tag.find(".vad_vad_slider_value").text(slider.val().toString());
+ });
+ modal.properties.registerCloseListener(() => {
+ let vad = globalClient.voiceConnection.voiceRecorder.getVADHandler();
+ if(vad instanceof VoiceActivityDetectorVAD)
+ vad.percentage_listener = undefined;
+
+ });
+
+
+ //Trigger radio button select for VAD setting setup
+ elm.trigger("change");
}
}
\ No newline at end of file
diff --git a/js/utils/modal.js b/js/utils/modal.js
index 3f1846cb..bc7141d1 100644
--- a/js/utils/modal.js
+++ b/js/utils/modal.js
@@ -44,13 +44,32 @@ class ModalProperties {
this.hight = "auto";
this.closeable = true;
}
+ registerCloseListener(listener) {
+ if (this.closeListener) {
+ if ($.isArray(this.closeListener))
+ this.closeListener.push(listener);
+ else
+ this.closeListener = [this.closeListener, listener];
+ }
+ else
+ this.closeListener = listener;
+ return this;
+ }
+ triggerClose() {
+ if ($.isArray(this.closeListener))
+ for (let listener of this.closeListener)
+ listener();
+ else
+ this.closeListener();
+ }
}
class Modal {
constructor(props) {
this.properties = props;
- this._create();
}
_create() {
+ if (this.htmlTag)
+ return;
let modal = $.spawn("div");
modal.addClass("modal");
let content = $.spawn("div");
@@ -72,6 +91,7 @@ class Modal {
this.htmlTag = modal;
}
open() {
+ this._create();
this.htmlTag.appendTo($("body"));
this.htmlTag.show();
}
@@ -80,7 +100,7 @@ class Modal {
this.htmlTag.animate({ opacity: 0 }, () => {
_this.htmlTag.detach();
});
- this.properties.closeListener();
+ this.properties.triggerClose();
}
}
function createModal(data) {
diff --git a/js/utils/modal.js.map b/js/utils/modal.js.map
index 3f1707cf..b5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KAAK,CAAC,KAAK,CAAC,CAAC;IAC1B,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IAClC,cAAc,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvE,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;IAEpB,KAAK,CAAC,IAAI,GAAG,cAAc,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IACtE,KAAK,CAAC,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;IAEnE,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC"}
\ No newline at end of file
diff --git a/js/utils/modal.ts b/js/utils/modal.ts
index b2f7c847..7e0fcc6d 100644
--- a/js/utils/modal.ts
+++ b/js/utils/modal.ts
@@ -41,12 +41,28 @@ class ModalProperties {
body: BodyCreator = () => "BODY";
footer: BodyCreator = () => "FOOTER";
- closeListener: () => void = () => {};
-
+ closeListener: (() => void) | (() => void)[] = () => {};
+ registerCloseListener(listener: () => void) : this {
+ if(this.closeListener) {
+ if($.isArray(this.closeListener))
+ this.closeListener.push(listener);
+ else
+ this.closeListener = [this.closeListener, listener];
+ } else this.closeListener = listener;
+ return this;
+ }
width: number | string = "60%";
hight: number | string = "auto";
closeable: boolean = true;
+
+ triggerClose(){
+ if($.isArray(this.closeListener))
+ for(let listener of this.closeListener)
+ listener();
+ else
+ this.closeListener();
+ }
}
class Modal {
@@ -55,10 +71,10 @@ class Modal {
constructor(props: ModalProperties) {
this.properties = props;
- this._create();
}
private _create() {
+ if(this.htmlTag) return;
let modal = $.spawn("div");
modal.addClass("modal");
@@ -87,6 +103,7 @@ class Modal {
}
open() {
+ this._create();
this.htmlTag.appendTo($("body"));
this.htmlTag.show();
}
@@ -96,7 +113,7 @@ class Modal {
this.htmlTag.animate({opacity: 0}, () => {
_this.htmlTag.detach();
});
- this.properties.closeListener();
+ this.properties.triggerClose();
}
}
diff --git a/js/voice/VoiceRecorder.ts b/js/voice/VoiceRecorder.ts
index e063396e..74312440 100644
--- a/js/voice/VoiceRecorder.ts
+++ b/js/voice/VoiceRecorder.ts
@@ -2,9 +2,19 @@
///
abstract class VoiceActivityDetector {
+ protected handle: VoiceRecorder;
+
abstract shouldRecord(buffer: AudioBuffer) : boolean;
- initialise(handle: VoiceRecorder) {}
+ initialise() {}
finalize() {}
+
+ initialiseNewStream(old: MediaStreamAudioSourceNode, _new: MediaStreamAudioSourceNode) : void {}
+
+ changeHandle(handle: VoiceRecorder, triggerNewStream: boolean) {
+ const oldStream = !this.handle ? undefined : this.handle.getMicrophoneStream();
+ this.handle = handle;
+ if(triggerNewStream) this.initialiseNewStream(oldStream, !handle ? undefined : handle.getMicrophoneStream());
+ }
}
class VoiceRecorder {
@@ -24,7 +34,7 @@ class VoiceRecorder {
private audioContext: AudioContext;
private processor: any;
- private mute: any;
+ private mute: GainNode;
private vadHandler: VoiceActivityDetector;
private _chunkCount: number = 0;
@@ -33,7 +43,7 @@ class VoiceRecorder {
this.handle = handle;
this.userMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
- this.audioContext = new AudioContext();
+ this.audioContext = AudioController.globalContext;
this.processor = this.audioContext.createScriptProcessor(VoiceRecorder.BUFFER_SIZE, VoiceRecorder.CHANNELS, VoiceRecorder.CHANNELS);
const _this = this;
@@ -43,11 +53,12 @@ class VoiceRecorder {
else {
if(this._chunkCount != 0) this.on_end();
this._chunkCount = 0
- };
+ }
});
//Not needed but make sure we have data for the preprocessor
this.mute = this.audioContext.createGain();
+ this.mute.gain.setValueAtTime(0, 0);
this.processor.connect(this.mute);
this.mute.connect(this.audioContext.destination);
@@ -60,6 +71,18 @@ class VoiceRecorder {
return !!this.userMedia;
}
+ getMediaStream() : MediaStream {
+ return this.mediaStream;
+ }
+
+ getDestinationContext() : AudioNode {
+ return this.mute;
+ }
+
+ getMicrophoneStream() : MediaStreamAudioSourceNode {
+ return this.microphoneStream;
+ }
+
reinizaliszeVAD() {
let type = this.handle.client.settings.global("vad_type", "ppt");
if(type == "ppt") {
@@ -70,15 +93,25 @@ class VoiceRecorder {
} else if(type == "pt") {
if(!(this.getVADHandler() instanceof PassThroughVAD))
this.setVADHander(new PassThroughVAD());
+ } else if(type == "vad") {
+ if(!(this.getVADHandler() instanceof VoiceActivityDetectorVAD))
+ this.setVADHander(new VoiceActivityDetectorVAD());
+ let threshold = Number.parseInt(globalClient.settings.global("vad_threshold", "50"));
+ (this.getVADHandler() as VoiceActivityDetectorVAD).percentageThreshold = threshold;
} else {
console.warn("Invalid VAD handler! (" + type + ")");
}
}
setVADHander(handler: VoiceActivityDetector) {
- if(this.vadHandler) this.vadHandler.finalize();
+ if(this.vadHandler) {
+ this.vadHandler.changeHandle(null, true);
+ this.vadHandler.finalize();
+ }
this.vadHandler = handler;
- this.vadHandler.initialise(this);
+ this.vadHandler.changeHandle(this, false);
+ this.vadHandler.initialise();
+ this.vadHandler.initialiseNewStream(undefined, this.microphoneStream);
}
getVADHandler() : VoiceActivityDetector {
@@ -125,8 +158,10 @@ class VoiceRecorder {
console.log("Start recording!");
this.mediaStream = stream as MediaStream;
+ const oldStream = this.microphoneStream;
this.microphoneStream = this.audioContext.createMediaStreamSource(stream);
this.microphoneStream.connect(this.processor);
+ this.vadHandler.initialiseNewStream(oldStream, this.microphoneStream);
}
}
@@ -142,6 +177,58 @@ class PassThroughVAD extends VoiceActivityDetector {
}
}
+class VoiceActivityDetectorVAD extends VoiceActivityDetector {
+ analyzer: AnalyserNode;
+ buffer: Uint8Array;
+
+ continuesCount: number = 0;
+ maxContinuesCount: number = 12;
+
+ percentageThreshold: number = 50;
+
+ percentage_listener: (per: number) => void = ($) => {};
+
+ initialise() {
+ this.analyzer = AudioController.globalContext.createAnalyser();
+ this.analyzer.smoothingTimeConstant = 1; //TODO test
+ this.buffer = new Uint8Array(this.analyzer.fftSize);
+ return super.initialise();
+ }
+
+ initialiseNewStream(old: MediaStreamAudioSourceNode, _new: MediaStreamAudioSourceNode): void {
+ if(this.analyzer)
+ this.analyzer.disconnect();
+ if(_new)
+ _new.connect(this.analyzer);
+ }
+
+ shouldRecord(buffer: AudioBuffer): boolean {
+ let usage = this.calculateUsage();
+ if($.isFunction(this.percentage_listener)) this.percentage_listener(usage);
+ if(usage >= this.percentageThreshold) {
+ this.continuesCount = 0;
+ } else this.continuesCount++;
+ return this.continuesCount < this.maxContinuesCount;
+ }
+
+ calculateUsage() : number {
+ let total = 0
+ ,float
+ ,rms;
+ this.analyzer.getByteTimeDomainData(this.buffer);
+ for(let index = 0; index < this.analyzer.fftSize; index++) {
+ float = ( this.buffer[index++] / 0x7f ) - 1;
+ total += (float * float);
+ }
+ rms = Math.sqrt(total / this.analyzer.fftSize);
+ let db = 20 * ( Math.log(rms) / Math.log(10) );
+ // sanity check
+ db = Math.max(-192, Math.min(db, 0));
+ let percentage = 100 + ( db * 1.92 );
+ return percentage;
+ }
+}
+
class PushToTalkVAD extends VoiceActivityDetector {
private _key: number;
private _pushed: boolean = false;
@@ -162,10 +249,10 @@ class PushToTalkVAD extends VoiceActivityDetector {
}
- initialise(handle: VoiceRecorder) {
+ initialise() {
document.addEventListener("keydown", this._evListenerDown);
document.addEventListener("keyup", this._evListenerUp);
- return super.initialise(handle);
+ return super.initialise();
}
finalize() {