diff --git a/custom-voices.html b/custom-voices.html index eb160791..34413ff7 100644 --- a/custom-voices.html +++ b/custom-voices.html @@ -14,6 +14,7 @@ + @@ -45,6 +46,30 @@

Enable Custom Voices

+
+
+ Enter credentials to enable Azure Cognitive Services TTS voices. +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
Enter GCP API key to enable Google Wavenet voices. diff --git a/js/custom-voices.js b/js/custom-voices.js index 014ec089..9a583b11 100644 --- a/js/custom-voices.js +++ b/js/custom-voices.js @@ -1,6 +1,6 @@ $(function() { - getSettings(["awsCreds", "gcpCreds", "ibmCreds"]) + getSettings(["awsCreds", "gcpCreds", "ibmCreds", "azureCreds"]) .then(function(items) { if (items.awsCreds) { $("#aws-access-key-id").val(obfuscate(items.awsCreds.accessKeyId)); @@ -13,11 +13,16 @@ $(function() { $("#ibm-api-key").val(obfuscate(items.ibmCreds.apiKey)); $("#ibm-url").val(obfuscate(items.ibmCreds.url)); } + if (items.azureCreds) { + $("#azure-tts-key").val(obfuscate(items.azureCreds.subKey)); + $("#azure-tts-region").val(obfuscate(items.azureCreds.region)); + } }) $(".status").hide(); $("#aws-save-button").click(awsSave); $("#gcp-save-button").click(gcpSave); $("#ibm-save-button").click(ibmSave); + $("#azure-save-button").click(azureSave); }) function obfuscate(key) { @@ -67,6 +72,50 @@ function testAws(accessKeyId, secretAccessKey) { } +function azureSave() { + $(".status").hide(); + var subKey = $("#azure-tts-key").val().trim(); + var region = $("#azure-tts-region").val().trim(); + if (subKey && region) { + $("#azure-progress").show(); + testAzure(subKey, region); + } + else if (!subKey && !region) { + clearSettings(["azureCreds"]) + .then(function() { + $("#azure-success").text("Azure Cognitive Services voices are disabled.").show(); + }) + } + else { + $("#azure-error").text("Missing required fields.").show(); + } +} + +function testAzure(subKey, region) { + const speechConfig = SpeechSDK.SpeechConfig.fromSubscription(subKey, region); + const audioConfig = SpeechSDK.AudioConfig.fromDefaultSpeakerOutput(); + + const synthesizer = new SpeechSDK.SpeechSynthesizer(speechConfig, audioConfig); + synthesizer.speakTextAsync("Azure Congitive Services test", + result => { + if (result) { + console.log(JSON.stringify(result)); + } + synthesizer.close(); + $("#azure-progress").hide(); + updateSettings({azureCreds: {subscriptionKey: subKey, region: region}}); + $("#azure-success").text("Azure Cognitive Services voices are enabled.").show(); + $("#azure-tts-key").val(obfuscate(subKey)); + $("#azure-tts-region").val(obfuscate(region)); + }, + error => { + console.log(error); + synthesizer.close(); + $("#azure-progress").hide(); + $("#azure-error").text("Test failed: " + err.message).show(); + }); +} + function gcpSave() { $(".status").hide(); var apiKey = $("#gcp-api-key").val().trim(); diff --git a/js/defaults.js b/js/defaults.js index e236c92b..9ae81479 100644 --- a/js/defaults.js +++ b/js/defaults.js @@ -103,7 +103,7 @@ function setState(key, value) { * VOICES */ function getVoices() { - return getSettings(["awsCreds", "gcpCreds"]) + return getSettings(["awsCreds", "gcpCreds", "azureCreds"]) .then(function(settings) { return Promise.all([ browserTtsEngine.getVoices(), @@ -112,6 +112,7 @@ function getVoices() { settings.awsCreds ? amazonPollyTtsEngine.getVoices() : [], settings.gcpCreds ? googleWavenetTtsEngine.getVoices() : googleWavenetTtsEngine.getFreeVoices(), ibmWatsonTtsEngine.getVoices(), + settings.azureCreds ? azureTtsEngine.getVoices() : [] ]) }) .then(function(arr) { @@ -135,6 +136,10 @@ function isAmazonCloud(voice) { return /^Amazon /.test(voice.voiceName); } +function isAzure(voice) { + return /^Azure /.test(voice.voiceName); +} + function isMicrosoftCloud(voice) { return /^Microsoft /.test(voice.voiceName) && voice.voiceName.indexOf(' - ') == -1; } @@ -156,7 +161,7 @@ function isIbmWatson(voice) { } function isRemoteVoice(voice) { - return isAmazonCloud(voice) || isMicrosoftCloud(voice) || isOpenFPT(voice) || isGoogleTranslate(voice) || isGoogleWavenet(voice) || isAmazonPolly(voice) || isIbmWatson(voice); + return isAmazonCloud(voice) || isAzure(voice) || isMicrosoftCloud(voice) || isOpenFPT(voice) || isGoogleTranslate(voice) || isGoogleWavenet(voice) || isAmazonPolly(voice) || isIbmWatson(voice); } function isPremiumVoice(voice) { diff --git a/js/microsoft.cognitiveservices.speech.sdk.bundle-min.js b/js/microsoft.cognitiveservices.speech.sdk.bundle-min.js new file mode 100644 index 00000000..4b8c632a --- /dev/null +++ b/js/microsoft.cognitiveservices.speech.sdk.bundle-min.js @@ -0,0 +1,8 @@ +!function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){window.SpeechSDK=r(1)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(2);r(4).Events.instance.attachListener(new n.ConsoleLoggingListener),function(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}(r(31))},function(e,t,r){"use strict";function n(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}Object.defineProperty(t,"__esModule",{value:!0}),n(r(3)),n(r(25)),n(r(181)),n(r(182)),n(r(183)),n(r(184)),n(r(200)),n(r(201)),n(r(202)),n(r(159))},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(4),i=function(e){var t=this;void 0===e&&(e=n.EventType.Warning),this.onEvent=function(e){if(e.eventType>=t.privLogLevelFilter){var r=t.toString(e);switch(e.eventType){case n.EventType.Debug:console.debug(r);break;case n.EventType.Info:console.info(r);break;case n.EventType.Warning:console.warn(r);break;case n.EventType.Error:console.error(r);break;default:console.log(r)}}},this.toString=function(e){var t=[""+e.EventTime,""+e.Name];for(var r in e)if(r&&e.hasOwnProperty(r)&&"eventTime"!==r&&"eventType"!==r&&"eventId"!==r&&"name"!==r&&"constructor"!==r){var n=e[r],i="";null!=n&&(i="number"==typeof n||"string"==typeof n?n.toString():JSON.stringify(n)),t.push(r+": "+i)}return t.join(" | ")},this.privLogLevelFilter=e};t.ConsoleLoggingListener=i},function(e,t,r){"use strict";function n(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}Object.defineProperty(t,"__esModule",{value:!0}),n(r(5)),n(r(8)),n(r(9)),n(r(11)),n(r(10)),n(r(12)),n(r(13)),n(r(7)),n(r(14)),n(r(15)),n(r(6)),n(r(16)),n(r(17)),n(r(18)),n(r(19)),n(r(20));var i=r(21);t.TranslationStatus=i.TranslationStatus,n(r(22)),n(r(23)),n(r(24))},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=r(6),s=function(e){function t(t,r,n){void 0===n&&(n=o.EventType.Info);var i=e.call(this,t,n)||this;return i.privAudioSourceId=r,i}return i(t,e),Object.defineProperty(t.prototype,"audioSourceId",{get:function(){return this.privAudioSourceId},enumerable:!0,configurable:!0}),t}(o.PlatformEvent);t.AudioSourceEvent=s;var a=function(e){function t(t){return e.call(this,"AudioSourceInitializingEvent",t)||this}return i(t,e),t}(s);t.AudioSourceInitializingEvent=a;var c=function(e){function t(t){return e.call(this,"AudioSourceReadyEvent",t)||this}return i(t,e),t}(s);t.AudioSourceReadyEvent=c;var p=function(e){function t(t){return e.call(this,"AudioSourceOffEvent",t)||this}return i(t,e),t}(s);t.AudioSourceOffEvent=p;var u=function(e){function t(t,r){var n=e.call(this,"AudioSourceErrorEvent",t,o.EventType.Error)||this;return n.privError=r,n}return i(t,e),Object.defineProperty(t.prototype,"error",{get:function(){return this.privError},enumerable:!0,configurable:!0}),t}(s);t.AudioSourceErrorEvent=u;var f=function(e){function t(t,r,n){var i=e.call(this,t,r)||this;return i.privAudioNodeId=n,i}return i(t,e),Object.defineProperty(t.prototype,"audioNodeId",{get:function(){return this.privAudioNodeId},enumerable:!0,configurable:!0}),t}(s);t.AudioStreamNodeEvent=f;var h=function(e){function t(t,r){return e.call(this,"AudioStreamNodeAttachingEvent",t,r)||this}return i(t,e),t}(f);t.AudioStreamNodeAttachingEvent=h;var v=function(e){function t(t,r){return e.call(this,"AudioStreamNodeAttachedEvent",t,r)||this}return i(t,e),t}(f);t.AudioStreamNodeAttachedEvent=v;var l=function(e){function t(t,r){return e.call(this,"AudioStreamNodeDetachedEvent",t,r)||this}return i(t,e),t}(f);t.AudioStreamNodeDetachedEvent=l;var d=function(e){function t(t,r,n){var i=e.call(this,"AudioStreamNodeErrorEvent",t,r)||this;return i.privError=n,i}return i(t,e),Object.defineProperty(t.prototype,"error",{get:function(){return this.privError},enumerable:!0,configurable:!0}),t}(f);t.AudioStreamNodeErrorEvent=d},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(7);!function(e){e[e.Debug=0]="Debug",e[e.Info=1]="Info",e[e.Warning=2]="Warning",e[e.Error=3]="Error"}(t.EventType||(t.EventType={}));var i=function(){function e(e,t){this.privName=e,this.privEventId=n.createNoDashGuid(),this.privEventTime=(new Date).toISOString(),this.privEventType=t,this.privMetadata={}}return Object.defineProperty(e.prototype,"name",{get:function(){return this.privName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventId",{get:function(){return this.privEventId},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventTime",{get:function(){return this.privEventTime},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"eventType",{get:function(){return this.privEventType},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"metadata",{get:function(){return this.privMetadata},enumerable:!0,configurable:!0}),e}();t.PlatformEvent=i},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){var e=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var r=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?r:3&r|8).toString(16)}))};t.createGuid=n;t.createNoDashGuid=function(){return n().replace(new RegExp("-","g"),"").toUpperCase()}},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=r(6),s=function(e){function t(t,r,n){void 0===n&&(n=o.EventType.Info);var i=e.call(this,t,n)||this;return i.privJsonResult=r,i}return i(t,e),Object.defineProperty(t.prototype,"jsonString",{get:function(){return this.privJsonResult},enumerable:!0,configurable:!0}),t}(o.PlatformEvent);t.ServiceEvent=s;var a=function(e){function t(t,r,n){void 0===n&&(n=o.EventType.Info);var i=e.call(this,t,n)||this;return i.privConnectionId=r,i}return i(t,e),Object.defineProperty(t.prototype,"connectionId",{get:function(){return this.privConnectionId},enumerable:!0,configurable:!0}),t}(o.PlatformEvent);t.ConnectionEvent=a;var c=function(e){function t(t,r,n){var i=e.call(this,"ConnectionStartEvent",t)||this;return i.privUri=r,i.privHeaders=n,i}return i(t,e),Object.defineProperty(t.prototype,"uri",{get:function(){return this.privUri},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"headers",{get:function(){return this.privHeaders},enumerable:!0,configurable:!0}),t}(a);t.ConnectionStartEvent=c;var p=function(e){function t(t,r){return e.call(this,"ConnectionEstablishedEvent",t)||this}return i(t,e),t}(a);t.ConnectionEstablishedEvent=p;var u=function(e){function t(t,r,n){var i=e.call(this,"ConnectionClosedEvent",t,o.EventType.Debug)||this;return i.privRreason=n,i.privStatusCode=r,i}return i(t,e),Object.defineProperty(t.prototype,"reason",{get:function(){return this.privRreason},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"statusCode",{get:function(){return this.privStatusCode},enumerable:!0,configurable:!0}),t}(a);t.ConnectionClosedEvent=u;var f=function(e){function t(t,r,n){var i=e.call(this,"ConnectionErrorEvent",t,o.EventType.Debug)||this;return i.privMessage=r,i.privType=n,i}return i(t,e),Object.defineProperty(t.prototype,"message",{get:function(){return this.privMessage},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"type",{get:function(){return this.privType},enumerable:!0,configurable:!0}),t}(a);t.ConnectionErrorEvent=f;var h=function(e){function t(t,r,n){var i=e.call(this,"ConnectionEstablishErrorEvent",t,o.EventType.Error)||this;return i.privStatusCode=r,i.privReason=n,i}return i(t,e),Object.defineProperty(t.prototype,"reason",{get:function(){return this.privReason},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"statusCode",{get:function(){return this.privStatusCode},enumerable:!0,configurable:!0}),t}(a);t.ConnectionEstablishErrorEvent=h;var v=function(e){function t(t,r,n){var i=e.call(this,"ConnectionMessageReceivedEvent",t)||this;return i.privNetworkReceivedTime=r,i.privMessage=n,i}return i(t,e),Object.defineProperty(t.prototype,"networkReceivedTime",{get:function(){return this.privNetworkReceivedTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"message",{get:function(){return this.privMessage},enumerable:!0,configurable:!0}),t}(a);t.ConnectionMessageReceivedEvent=v;var l=function(e){function t(t,r,n){var i=e.call(this,"ConnectionMessageSentEvent",t)||this;return i.privNetworkSentTime=r,i.privMessage=n,i}return i(t,e),Object.defineProperty(t.prototype,"networkSentTime",{get:function(){return this.privNetworkSentTime},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"message",{get:function(){return this.privMessage},enumerable:!0,configurable:!0}),t}(a);t.ConnectionMessageSentEvent=l},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n,i=r(10),o=r(7);!function(e){e[e.Text=0]="Text",e[e.Binary=1]="Binary"}(n=t.MessageType||(t.MessageType={}));var s=function(){function e(e,t,r,s){if(this.privBody=null,e===n.Text&&t&&"string"!=typeof t)throw new i.InvalidOperationError("Payload must be a string");if(e===n.Binary&&t&&!(t instanceof ArrayBuffer))throw new i.InvalidOperationError("Payload must be ArrayBuffer");switch(this.privMessageType=e,this.privBody=t,this.privHeaders=r||{},this.privId=s||o.createNoDashGuid(),this.messageType){case n.Binary:this.privSize=null!==this.binaryBody?this.binaryBody.byteLength:0;break;case n.Text:this.privSize=this.textBody.length}}return Object.defineProperty(e.prototype,"messageType",{get:function(){return this.privMessageType},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"headers",{get:function(){return this.privHeaders},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"body",{get:function(){return this.privBody},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"textBody",{get:function(){if(this.privMessageType===n.Binary)throw new i.InvalidOperationError("Not supported for binary message");return this.privBody},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"binaryBody",{get:function(){if(this.privMessageType===n.Text)throw new i.InvalidOperationError("Not supported for text message");return this.privBody},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return this.privId},enumerable:!0,configurable:!0}),e}();t.ConnectionMessage=s},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t){var r=e.call(this,t)||this;return r.name="ArgumentNull",r.message=t,r}return i(t,e),t}(Error);t.ArgumentNullError=o;var s=function(e){function t(t){var r=e.call(this,t)||this;return r.name="InvalidOperation",r.message=t,r}return i(t,e),t}(Error);t.InvalidOperationError=s;var a=function(e){function t(t,r){var n=e.call(this,r)||this;return n.name=t+"ObjectDisposed",n.message=r,n}return i(t,e),t}(Error);t.ObjectDisposedError=a},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){this.privStatusCode=e,this.privReason=t}return Object.defineProperty(e.prototype,"statusCode",{get:function(){return this.privStatusCode},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"reason",{get:function(){return this.privReason},enumerable:!0,configurable:!0}),e}();t.ConnectionOpenResponse=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(10),i=r(13),o=function(){function e(){}return Object.defineProperty(e,"instance",{get:function(){return e.privInstance},enumerable:!0,configurable:!0}),e.privInstance=new i.EventSource,e.setEventSource=function(t){if(!t)throw new n.ArgumentNullError("eventSource");e.privInstance=t},e}();t.Events=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(10),i=r(7),o=function(){function e(e){var t=this;this.privEventListeners={},this.privIsDisposed=!1,this.onEvent=function(e){if(t.isDisposed())throw new n.ObjectDisposedError("EventSource");if(t.metadata)for(var r in t.metadata)r&&e.metadata&&(e.metadata[r]||(e.metadata[r]=t.metadata[r]));for(var i in t.privEventListeners)i&&t.privEventListeners[i]&&t.privEventListeners[i](e)},this.attach=function(e){var r=i.createNoDashGuid();return t.privEventListeners[r]=e,{detach:function(){delete t.privEventListeners[r]}}},this.attachListener=function(e){return t.attach(e.onEvent)},this.isDisposed=function(){return t.privIsDisposed},this.dispose=function(){t.privEventListeners=null,t.privIsDisposed=!0},this.privMetadata=e}return Object.defineProperty(e.prototype,"metadata",{get:function(){return this.privMetadata},enumerable:!0,configurable:!0}),e}();t.EventSource=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.None=0]="None",e[e.Connected=1]="Connected",e[e.Connecting=2]="Connecting",e[e.Disconnected=3]="Disconnected"}(t.ConnectionState||(t.ConnectionState={}))},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(10),i=function e(t){var r=this;if(this.privSubscriptionIdCounter=0,this.privAddSubscriptions={},this.privRemoveSubscriptions={},this.privDisposedSubscriptions={},this.privDisposeReason=null,this.get=function(e){return r.throwIfDisposed(),r.privList[e]},this.first=function(){return r.get(0)},this.last=function(){return r.get(r.length()-1)},this.add=function(e){r.throwIfDisposed(),r.insertAt(r.privList.length,e)},this.insertAt=function(e,t){r.throwIfDisposed(),0===e?r.privList.unshift(t):e===r.privList.length?r.privList.push(t):r.privList.splice(e,0,t),r.triggerSubscriptions(r.privAddSubscriptions)},this.removeFirst=function(){return r.throwIfDisposed(),r.removeAt(0)},this.removeLast=function(){return r.throwIfDisposed(),r.removeAt(r.length()-1)},this.removeAt=function(e){return r.throwIfDisposed(),r.remove(e,1)[0]},this.remove=function(e,t){r.throwIfDisposed();var n=r.privList.splice(e,t);return r.triggerSubscriptions(r.privRemoveSubscriptions),n},this.clear=function(){r.throwIfDisposed(),r.remove(0,r.length())},this.length=function(){return r.throwIfDisposed(),r.privList.length},this.onAdded=function(e){r.throwIfDisposed();var t=r.privSubscriptionIdCounter++;return r.privAddSubscriptions[t]=e,{detach:function(){delete r.privAddSubscriptions[t]}}},this.onRemoved=function(e){r.throwIfDisposed();var t=r.privSubscriptionIdCounter++;return r.privRemoveSubscriptions[t]=e,{detach:function(){delete r.privRemoveSubscriptions[t]}}},this.onDisposed=function(e){r.throwIfDisposed();var t=r.privSubscriptionIdCounter++;return r.privDisposedSubscriptions[t]=e,{detach:function(){delete r.privDisposedSubscriptions[t]}}},this.join=function(e){return r.throwIfDisposed(),r.privList.join(e)},this.toArray=function(){var e=Array();return r.privList.forEach((function(t){e.push(t)})),e},this.any=function(e){return r.throwIfDisposed(),e?r.where(e).length()>0:r.length()>0},this.all=function(e){return r.throwIfDisposed(),r.where(e).length()===r.length()},this.forEach=function(e){r.throwIfDisposed();for(var t=0;t0&&t.privPromiseStore.first().result().isCompleted;){var e=t.privPromiseStore.removeFirst();e.result().isError||t.privList.add(e.result().result)}}))},this.dequeue=function(){t.throwIfDispose();var e=new s.Deferred;return t.privSubscribers&&(t.privSubscribers.add({deferral:e,type:n.Dequeue}),t.drain()),e.promise()},this.peek=function(){t.throwIfDispose();var e=new s.Deferred;return t.privSubscribers&&(t.privSubscribers.add({deferral:e,type:n.Peek}),t.drain()),e.promise()},this.length=function(){return t.throwIfDispose(),t.privList.length()},this.isDisposed=function(){return null==t.privSubscribers},this.drainAndDispose=function(e,r){if(!t.isDisposed()&&!t.privIsDisposing){t.privDisposeReason=r,t.privIsDisposing=!0;var n=t.privSubscribers;if(n){for(;n.length()>0;)n.removeFirst().deferral.resolve(void 0);t.privSubscribers===n&&(t.privSubscribers=n)}for(var i=0,o=t.privDetachables;i0&&e)return s.PromiseHelper.whenAll(t.privPromiseStore.toArray()).continueWith((function(){return t.privSubscribers=null,t.privList.forEach((function(t,r){e(t)})),t.privList=null,!0}));t.privSubscribers=null,t.privList=null}return s.PromiseHelper.fromResult(!0)},this.dispose=function(e){t.drainAndDispose(null,e)},this.drain=function(){if(!t.privIsDrainInProgress&&!t.privIsDisposing){t.privIsDrainInProgress=!0;var e=t.privSubscribers,r=t.privList;if(e&&r){for(;r.length()>0&&e.length()>0&&!t.privIsDisposing;){var i=e.removeFirst();if(i.type===n.Peek)i.deferral.resolve(r.first());else{var o=r.removeFirst();i.deferral.resolve(o)}}t.privSubscribers===e&&(t.privSubscribers=e),t.privList===r&&(t.privList=r)}t.privIsDrainInProgress=!1}},this.throwIfDispose=function(){if(t.isDisposed()){if(t.privDisposeReason)throw new i.InvalidOperationError(t.privDisposeReason);throw new i.ObjectDisposedError("Queue")}if(t.privIsDisposing)throw new i.InvalidOperationError("Queue disposing")},this.privList=e||new o.List,this.privDetachables=[],this.privSubscribers=new o.List,this.privDetachables.push(this.privList.onAdded(this.drain))};t.Queue=a},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(9),i=r(10),o=r(7),s=function(){function e(e,t,r){if(this.privPayload=null,!t)throw new i.ArgumentNullError("payload");if(e===n.MessageType.Binary&&!(t instanceof ArrayBuffer))throw new i.InvalidOperationError("Payload must be ArrayBuffer");if(e===n.MessageType.Text&&"string"!=typeof t)throw new i.InvalidOperationError("Payload must be a string");this.privMessageType=e,this.privPayload=t,this.privId=r||o.createNoDashGuid()}return Object.defineProperty(e.prototype,"messageType",{get:function(){return this.privMessageType},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"payload",{get:function(){return this.privPayload},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"textContent",{get:function(){if(this.privMessageType===n.MessageType.Binary)throw new i.InvalidOperationError("Not supported for binary message");return this.privPayload},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"binaryContent",{get:function(){if(this.privMessageType===n.MessageType.Text)throw new i.InvalidOperationError("Not supported for text message");return this.privPayload},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return this.privId},enumerable:!0,configurable:!0}),e}();t.RawWebsocketMessage=s},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(e,t){var r=this;this.encode=function(e){var t=r.downSampleAudioFrame(e,r.privActualSampleRate,r.privDesiredSampleRate);if(!t)return null;var n=2*t.length,i=new ArrayBuffer(n),o=new DataView(i);return r.floatTo16BitPCM(o,0,t),i},this.setString=function(e,t,r){for(var n=0;nt)return e;for(var n=t/r,i=Math.round(e.length/n),o=new Float32Array(i),s=0,a=0;a{const t=r.get(e);if(void 0===t)throw new Error(\'There is no interval scheduled with the given id "\'.concat(e,\'".\'));clearTimeout(t),r.delete(e)},u=e=>{const t=o.get(e);if(void 0===t)throw new Error(\'There is no timeout scheduled with the given id "\'.concat(e,\'".\'));clearTimeout(t),o.delete(e)},f=(e,t)=>{let n,r;if("performance"in self){const o=performance.now();n=o,r=e-Math.max(0,o-t)}else n=Date.now(),r=e;return{expected:n+r,remainingDelay:r}},c=(e,t,n,r)=>{const o="performance"in self?performance.now():Date.now();o>n?postMessage({id:null,method:"call",params:{timerId:t}}):e.set(t,setTimeout(c,n-o,e,t,n))},a=(e,t,n)=>{const{expected:o,remainingDelay:i}=f(e,n);r.set(t,setTimeout(c,i,r,t,o))},d=(e,t,n)=>{const{expected:r,remainingDelay:i}=f(e,n);o.set(t,setTimeout(c,i,o,t,r))}},function(e,t,n){"use strict";n.r(t);var r=n(2);for(var o in r)"default"!==o&&function(e){n.d(t,e,(function(){return r[e]}))}(o);var i=n(3);for(var o in i)"default"!==o&&function(e){n.d(t,e,(function(){return i[e]}))}(o);var u=n(4);for(var o in u)"default"!==o&&function(e){n.d(t,e,(function(){return u[e]}))}(o);var f=n(5);for(var o in f)"default"!==o&&function(e){n.d(t,e,(function(){return f[e]}))}(o);var c=n(6);for(var o in c)"default"!==o&&function(e){n.d(t,e,(function(){return c[e]}))}(o);var a=n(7);for(var o in a)"default"!==o&&function(e){n.d(t,e,(function(){return a[e]}))}(o);var d=n(8);for(var o in d)"default"!==o&&function(e){n.d(t,e,(function(){return d[e]}))}(o);var s=n(9);for(var o in s)"default"!==o&&function(e){n.d(t,e,(function(){return s[e]}))}(o)},function(e,t){},function(e,t){},function(e,t){},function(e,t){},function(e,t){},function(e,t){},function(e,t){},function(e,t){},function(e,t,n){"use strict";n.r(t);var r=n(11);for(var o in r)"default"!==o&&function(e){n.d(t,e,(function(){return r[e]}))}(o);var i=n(12);for(var o in i)"default"!==o&&function(e){n.d(t,e,(function(){return i[e]}))}(o);var u=n(13);for(var o in u)"default"!==o&&function(e){n.d(t,e,(function(){return u[e]}))}(o)},function(e,t){},function(e,t){},function(e,t){},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n(1);for(var i in o)"default"!==i&&function(e){n.d(t,e,(function(){return o[e]}))}(i);var u=n(10);for(var i in u)"default"!==i&&function(e){n.d(t,e,(function(){return u[e]}))}(i);addEventListener("message",({data:e})=>{try{if("clear"===e.method){const{id:t,params:{timerId:n}}=e;Object(r.b)(n),postMessage({error:null,id:t})}else{if("set"!==e.method)throw new Error(\'The given method "\'.concat(e.method,\'" is not supported\'));{const{params:{delay:t,now:n,timerId:o}}=e;Object(r.d)(t,o,n)}}}catch(t){postMessage({error:{message:t.message},id:e.id,result:null})}})}]);'],{type:"application/javascript; charset=utf-8"}),r=URL.createObjectURL(t);return e.workerTimers=e.load(r),e.workerTimers.setTimeout((function(){return URL.revokeObjectURL(r)}),0),e.workerTimers}},e.timers=e.loadWorkerTimers(),e.isCallNotification=function(e){return void 0!==e.method&&"call"===e.method},e.isClearResponse=function(e){return null===e.error&&"number"==typeof e.id},e}();t.Timeout=n},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=r(6),s=function(e){function t(t,r,n){var i=e.call(this,t,r)||this;return i.privSignature=n,i}return i(t,e),t}(o.PlatformEvent);t.OCSPEvent=s;var a=function(e){function t(t){return e.call(this,"OCSPMemoryCacheHitEvent",o.EventType.Debug,t)||this}return i(t,e),t}(s);t.OCSPMemoryCacheHitEvent=a;var c=function(e){function t(t){return e.call(this,"OCSPCacheMissEvent",o.EventType.Debug,t)||this}return i(t,e),t}(s);t.OCSPCacheMissEvent=c;var p=function(e){function t(t){return e.call(this,"OCSPDiskCacheHitEvent",o.EventType.Debug,t)||this}return i(t,e),t}(s);t.OCSPDiskCacheHitEvent=p;var u=function(e){function t(t){return e.call(this,"OCSPCacheUpdateNeededEvent",o.EventType.Debug,t)||this}return i(t,e),t}(s);t.OCSPCacheUpdateNeededEvent=u;var f=function(e){function t(t){return e.call(this,"OCSPMemoryCacheStoreEvent",o.EventType.Debug,t)||this}return i(t,e),t}(s);t.OCSPMemoryCacheStoreEvent=f;var h=function(e){function t(t){return e.call(this,"OCSPDiskCacheStoreEvent",o.EventType.Debug,t)||this}return i(t,e),t}(s);t.OCSPDiskCacheStoreEvent=h;var v=function(e){function t(t){return e.call(this,"OCSPCacheUpdatehCompleteEvent",o.EventType.Debug,t)||this}return i(t,e),t}(s);t.OCSPCacheUpdatehCompleteEvent=v;var l=function(e){function t(){return e.call(this,"OCSPStapleReceivedEvent",o.EventType.Debug,"")||this}return i(t,e),t}(s);t.OCSPStapleReceivedEvent=l;var d=function(e){function t(t){return e.call(this,"OCSPWSUpgradeStartedEvent",o.EventType.Debug,t)||this}return i(t,e),t}(s);t.OCSPWSUpgradeStartedEvent=d;var g=function(e){function t(t,r){var n=e.call(this,"OCSPCacheEntryExpiredEvent",o.EventType.Debug,t)||this;return n.privExpireTime=r,n}return i(t,e),t}(s);t.OCSPCacheEntryExpiredEvent=g;var y=function(e){function t(t,r,n){var i=e.call(this,"OCSPCacheEntryNeedsRefreshEvent",o.EventType.Debug,t)||this;return i.privExpireTime=n,i.privStartTime=r,i}return i(t,e),t}(s);t.OCSPCacheEntryNeedsRefreshEvent=y;var m=function(e){function t(t,r,n){var i=e.call(this,"OCSPCacheHitEvent",o.EventType.Debug,t)||this;return i.privExpireTime=n,i.privExpireTimeString=new Date(n).toLocaleDateString(),i.privStartTime=r,i.privStartTimeString=new Date(r).toLocaleTimeString(),i}return i(t,e),t}(s);t.OCSPCacheHitEvent=m;var S=function(e){function t(t,r){var n=e.call(this,"OCSPVerificationFailedEvent",o.EventType.Debug,t)||this;return n.privError=r,n}return i(t,e),t}(s);t.OCSPVerificationFailedEvent=S;var C=function(e){function t(t,r){var n=e.call(this,"OCSPCacheFetchErrorEvent",o.EventType.Debug,t)||this;return n.privError=r,n}return i(t,e),t}(s);t.OCSPCacheFetchErrorEvent=C;var P=function(e){function t(t){return e.call(this,"OCSPResponseRetrievedEvent",o.EventType.Debug,t)||this}return i(t,e),t}(s);t.OCSPResponseRetrievedEvent=P;var b=function(e){function t(t,r){var n=e.call(this,"OCSPCacheUpdateErrorEvent",o.EventType.Debug,t)||this;return n.privError=r,n}return i(t,e),t}(s);t.OCSPCacheUpdateErrorEvent=b},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(26),i=r(4),o=r(42);t.AudioWorkletSourceURLPropertyName="MICROPHONE-WorkletSourceUrl";var s=function(){function e(t,r,n){var o=this;this.privRecorder=t,this.deviceId=r,this.privStreams={},this.turnOn=function(){if(o.privInitializeDeferral)return o.privInitializeDeferral.promise();o.privInitializeDeferral=new i.Deferred;try{o.createAudioContext()}catch(t){if(t instanceof Error){var e=t;o.privInitializeDeferral.reject(e.name+": "+e.message)}else o.privInitializeDeferral.reject(t);return o.privInitializeDeferral.promise()}var t=window.navigator,r=t.getUserMedia||t.webkitGetUserMedia||t.mozGetUserMedia||t.msGetUserMedia;if(t.mediaDevices&&(r=function(e,r,n){t.mediaDevices.getUserMedia(e).then(r).catch(n)}),r){var n=function(){o.onEvent(new i.AudioSourceInitializingEvent(o.privId)),r({audio:!o.deviceId||{deviceId:o.deviceId},video:!1},(function(e){o.privMediaStream=e,o.onEvent(new i.AudioSourceReadyEvent(o.privId)),o.privInitializeDeferral.resolve(!0)}),(function(e){var t="Error occurred during microphone initialization: "+e,r=o.privInitializeDeferral;o.privInitializeDeferral=null,r.reject(t),o.onEvent(new i.AudioSourceErrorEvent(o.privId,t))}))};"suspended"===o.privContext.state?o.privContext.resume().then(n,(function(e){o.privInitializeDeferral.reject("Failed to initialize audio context: "+e)})):n()}else{var s="Browser does not support getUserMedia.";o.privInitializeDeferral.reject(s),o.onEvent(new i.AudioSourceErrorEvent(s,""))}return o.privInitializeDeferral.promise()},this.id=function(){return o.privId},this.attach=function(e){return o.onEvent(new i.AudioStreamNodeAttachingEvent(o.privId,e)),o.listen(e).onSuccessContinueWith((function(t){return o.onEvent(new i.AudioStreamNodeAttachedEvent(o.privId,e)),{detach:function(){t.readEnded(),o.turnOff(),delete o.privStreams[e],o.onEvent(new i.AudioStreamNodeDetachedEvent(o.privId,e))},id:function(){return e},read:function(){return t.read()}}}))},this.detach=function(e){e&&o.privStreams[e]&&(o.privStreams[e].close(),delete o.privStreams[e],o.onEvent(new i.AudioStreamNodeDetachedEvent(o.privId,e)))},this.turnOff=function(){for(var e in o.privStreams)if(e){var t=o.privStreams[e];t&&t.close()}return o.onEvent(new i.AudioSourceOffEvent(o.privId)),o.privInitializeDeferral=null,o.destroyAudioContext(),i.PromiseHelper.fromResult(!0)},this.listen=function(e){return o.turnOn().onSuccessContinueWith((function(t){var r=new i.ChunkedArrayBufferStream(o.privOutputChunkSize,e);o.privStreams[e]=r;try{o.privRecorder.record(o.privContext,o.privMediaStream,r)}catch(t){throw o.onEvent(new i.AudioStreamNodeErrorEvent(o.privId,e,t)),t}return r}))},this.onEvent=function(e){o.privEvents.onEvent(e),i.Events.instance.onEvent(e)},this.createAudioContext=function(){if(!o.privContext){if("undefined"==typeof AudioContext)throw new Error("Browser does not support Web Audio API (AudioContext is not available).");navigator.mediaDevices.getSupportedConstraints().sampleRate?o.privContext=new AudioContext({sampleRate:e.AUDIOFORMAT.samplesPerSec}):o.privContext=new AudioContext}},this.destroyAudioContext=function(){if(o.privContext){o.privRecorder.releaseMediaResources(o.privContext);var e=!1;"close"in o.privContext&&(e=!0),e?(o.privContext.close(),o.privContext=null):null!==o.privContext&&"running"===o.privContext.state&&o.privContext.suspend()}},this.privOutputChunkSize=e.AUDIOFORMAT.avgBytesPerSec/10,this.privId=n||i.createNoDashGuid(),this.privEvents=new i.EventSource}return Object.defineProperty(e.prototype,"format",{get:function(){return i.PromiseHelper.fromResult(e.AUDIOFORMAT)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"blob",{get:function(){return i.PromiseHelper.fromError("Not implemented for Mic input")},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"events",{get:function(){return this.privEvents},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"deviceInfo",{get:function(){return this.getMicrophoneLabel().onSuccessContinueWith((function(t){return{bitspersample:e.AUDIOFORMAT.bitsPerSample,channelcount:e.AUDIOFORMAT.channels,connectivity:n.connectivity.Unknown,manufacturer:"Speech SDK",model:t,samplerate:e.AUDIOFORMAT.samplesPerSec,type:n.type.Microphones}}))},enumerable:!0,configurable:!0}),e.prototype.setProperty=function(e,r){if(e!==t.AudioWorkletSourceURLPropertyName)throw new Error("Property '"+e+"' is not supported on Microphone.");this.privRecorder.setWorkletUrl(r)},e.prototype.getMicrophoneLabel=function(){var e=this;if(void 0!==this.privMicrophoneLabel)return i.PromiseHelper.fromResult(this.privMicrophoneLabel);if(void 0===this.privMediaStream||!this.privMediaStream.active)return i.PromiseHelper.fromResult("microphone");this.privMicrophoneLabel="microphone";var t=this.privMediaStream.getTracks()[0].getSettings().deviceId;if(void 0===t)return i.PromiseHelper.fromResult(this.privMicrophoneLabel);var r=new i.Deferred;return navigator.mediaDevices.enumerateDevices().then((function(n){for(var i=0,o=n;i + * @license MIT + */ +var n=r(39),i=r(40),o=r(41);function s(){return c.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(e,t){if(s()=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|e}function l(e,t){if(c.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var r=e.length;if(0===r)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return U(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return q(e).length;default:if(n)return U(e).length;t=(""+t).toLowerCase(),n=!0}}function d(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return A(this,t,r);case"utf8":case"utf-8":return w(this,t,r);case"ascii":return T(this,t,r);case"latin1":case"binary":return _(this,t,r);case"base64":return O(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return D(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function g(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function y(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=c.from(t,n)),c.isBuffer(t))return 0===t.length?-1:m(e,t,r,n,i);if("number"==typeof t)return t&=255,c.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):m(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function m(e,t,r,n,i){var o,s=1,a=e.length,c=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,c/=2,r/=2}function p(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var u=-1;for(o=r;oa&&(r=a-c),o=r;o>=0;o--){for(var f=!0,h=0;hi&&(n=i):n=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s>8,i=r%256,o.push(i),o.push(n);return o}(t,e.length-r),e,r,n)}function O(e,t,r){return 0===t&&r===e.length?n.fromByteArray(e):n.fromByteArray(e.slice(t,r))}function w(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i239?4:p>223?3:p>191?2:1;if(i+f<=r)switch(f){case 1:p<128&&(u=p);break;case 2:128==(192&(o=e[i+1]))&&(c=(31&p)<<6|63&o)>127&&(u=c);break;case 3:o=e[i+1],s=e[i+2],128==(192&o)&&128==(192&s)&&(c=(15&p)<<12|(63&o)<<6|63&s)>2047&&(c<55296||c>57343)&&(u=c);break;case 4:o=e[i+1],s=e[i+2],a=e[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(c=(15&p)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&c<1114112&&(u=c)}null===u?(u=65533,f=1):u>65535&&(u-=65536,n.push(u>>>10&1023|55296),u=56320|1023&u),n.push(u),i+=f}return function(e){var t=e.length;if(t<=E)return String.fromCharCode.apply(String,e);var r="",n=0;for(;n0&&(e=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(e+=" ... ")),""},c.prototype.compare=function(e,t,r,n,i){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(t>>>=0),a=Math.min(o,s),p=this.slice(n,i),u=e.slice(t,r),f=0;fi)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return S(this,e,t,r);case"utf8":case"utf-8":return C(this,e,t,r);case"ascii":return P(this,e,t,r);case"latin1":case"binary":return b(this,e,t,r);case"base64":return R(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var E=4096;function T(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;in)&&(r=n);for(var i="",o=t;or)throw new RangeError("Trying to access beyond buffer length")}function j(e,t,r,n,i,o){if(!c.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||te.length)throw new RangeError("Index out of range")}function k(e,t,r,n){t<0&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-r,2);i>>8*(n?i:1-i)}function N(e,t,r,n){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-r,4);i>>8*(n?i:3-i)&255}function x(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function z(e,t,r,n,o){return o||x(e,0,r,4),i.write(e,t,r,n,23,4),r+4}function L(e,t,r,n,o){return o||x(e,0,r,8),i.write(e,t,r,n,52,8),r+8}c.prototype.slice=function(e,t){var r,n=this.length;if((e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t0&&(i*=256);)n+=this[e+--t]*i;return n},c.prototype.readUInt8=function(e,t){return t||M(e,1,this.length),this[e]},c.prototype.readUInt16LE=function(e,t){return t||M(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUInt16BE=function(e,t){return t||M(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUInt32LE=function(e,t){return t||M(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUInt32BE=function(e,t){return t||M(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||M(e,t,this.length);for(var n=this[e],i=1,o=0;++o=(i*=128)&&(n-=Math.pow(2,8*t)),n},c.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||M(e,t,this.length);for(var n=t,i=1,o=this[e+--n];n>0&&(i*=256);)o+=this[e+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*t)),o},c.prototype.readInt8=function(e,t){return t||M(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){t||M(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},c.prototype.readInt16BE=function(e,t){t||M(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},c.prototype.readInt32LE=function(e,t){return t||M(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return t||M(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readFloatLE=function(e,t){return t||M(e,4,this.length),i.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return t||M(e,4,this.length),i.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return t||M(e,8,this.length),i.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return t||M(e,8,this.length),i.read(this,e,!1,52,8)},c.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t|=0,r|=0,n)||j(this,e,t,r,Math.pow(2,8*r)-1,0);var i=1,o=0;for(this[t]=255&e;++o=0&&(o*=256);)this[t+i]=e/o&255;return t+r},c.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,1,255,0),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},c.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):k(this,e,t,!0),t+2},c.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):k(this,e,t,!1),t+2},c.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):N(this,e,t,!0),t+4},c.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):N(this,e,t,!1),t+4},c.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);j(this,e,t,r,i-1,-i)}var o=0,s=1,a=0;for(this[t]=255&e;++o>0)-a&255;return t+r},c.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);j(this,e,t,r,i-1,-i)}var o=r-1,s=1,a=0;for(this[t+o]=255&e;--o>=0&&(s*=256);)e<0&&0===a&&0!==this[t+o+1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+r},c.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,1,127,-128),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):k(this,e,t,!0),t+2},c.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):k(this,e,t,!1),t+2},c.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,4,2147483647,-2147483648),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):N(this,e,t,!0),t+4},c.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):N(this,e,t,!1),t+4},c.prototype.writeFloatLE=function(e,t,r){return z(this,e,t,!0,r)},c.prototype.writeFloatBE=function(e,t,r){return z(this,e,t,!1,r)},c.prototype.writeDoubleLE=function(e,t,r){return L(this,e,t,!0,r)},c.prototype.writeDoubleBE=function(e,t,r){return L(this,e,t,!1,r)},c.prototype.copy=function(e,t,r,n){if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t=0;--i)e[i+t]=this[i+r];else if(o<1e3||!c.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(o=t;o55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function q(e){return n.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(B,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function H(e,t,r,n){for(var i=0;i=t.length||i>=e.length);++i)t[i+r]=e[i];return i}}).call(this,r(38))},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){"use strict";t.byteLength=function(e){var t=p(e),r=t[0],n=t[1];return 3*(r+n)/4-n},t.toByteArray=function(e){var t,r,n=p(e),s=n[0],a=n[1],c=new o(function(e,t,r){return 3*(t+r)/4-r}(0,s,a)),u=0,f=a>0?s-4:s;for(r=0;r>16&255,c[u++]=t>>8&255,c[u++]=255&t;2===a&&(t=i[e.charCodeAt(r)]<<2|i[e.charCodeAt(r+1)]>>4,c[u++]=255&t);1===a&&(t=i[e.charCodeAt(r)]<<10|i[e.charCodeAt(r+1)]<<4|i[e.charCodeAt(r+2)]>>2,c[u++]=t>>8&255,c[u++]=255&t);return c},t.fromByteArray=function(e){for(var t,r=e.length,i=r%3,o=[],s=0,a=r-i;sa?a:s+16383));1===i?(t=e[r-1],o.push(n[t>>2]+n[t<<4&63]+"==")):2===i&&(t=(e[r-2]<<8)+e[r-1],o.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"="));return o.join("")};for(var n=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,c=s.length;a0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function u(e,t,r){for(var i,o,s=[],a=t;a>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return s.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(e,t){t.read=function(e,t,r,n,i){var o,s,a=8*i-n-1,c=(1<>1,u=-7,f=r?i-1:0,h=r?-1:1,v=e[t+f];for(f+=h,o=v&(1<<-u)-1,v>>=-u,u+=a;u>0;o=256*o+e[t+f],f+=h,u-=8);for(s=o&(1<<-u)-1,o>>=-u,u+=n;u>0;s=256*s+e[t+f],f+=h,u-=8);if(0===o)o=1-p;else{if(o===c)return s?NaN:1/0*(v?-1:1);s+=Math.pow(2,n),o-=p}return(v?-1:1)*s*Math.pow(2,o-n)},t.write=function(e,t,r,n,i,o){var s,a,c,p=8*o-i-1,u=(1<>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,v=n?0:o-1,l=n?1:-1,d=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=u):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),(t+=s+f>=1?h/c:h*Math.pow(2,1-f))*c>=2&&(s++,c/=2),s+f>=u?(a=0,s=u):s+f>=1?(a=(t*c-1)*Math.pow(2,i),s+=f):(a=t*Math.pow(2,f-1)*Math.pow(2,i),s=0));i>=8;e[r+v]=255&a,v+=l,a/=256,i-=8);for(s=s<0;e[r+v]=255&s,v+=l,s/=256,p-=8);e[r+v-l]|=128*d}},function(e,t){var r={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==r.call(e)}},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(){}return e.getDefaultInputFormat=function(){return s.getDefaultInputFormat()},e.getWaveFormatPCM=function(e,t,r){return new s(e,t,r)},e}();t.AudioStreamFormat=o;var s=function(e){function t(t,r,n){void 0===t&&(t=16e3),void 0===r&&(r=16),void 0===n&&(n=1);var i=e.call(this)||this;i.setString=function(e,t,r){for(var n=0;ne.byteLength)return r.set(this.privLastChunkView.slice(0,e.byteLength)),this.privLastChunkView=this.privLastChunkView.slice(e.byteLength),o.PromiseHelper.fromResult(e.byteLength);r.set(this.privLastChunkView),n=this.privLastChunkView.length,this.privLastChunkView=void 0}var i=new o.Deferred,s=function(){ne.byteLength-n?(a=o.buffer.slice(0,e.byteLength-n),t.privLastChunkView=new Int8Array(o.buffer.slice(e.byteLength-n))):a=o.buffer,r.set(new Int8Array(a),n),n+=a.byteLength,s()}})):i.resolve(n)};return s(),i.promise()},t.prototype.write=function(e){s.Contracts.throwIfNullOrUndefined(this.privStream,"must set format before writing"),this.privStream.writeStreamChunk({buffer:e,isEnd:!1,timeReceived:Date.now()})},t.prototype.close=function(){this.privStream.close()},t}(p);t.PullAudioOutputStreamImpl=u;var f=function(e){function t(){return e.call(this)||this}return i(t,e),t.create=function(e){return new h(e)},t}(c);t.PushAudioOutputStream=f;var h=function(e){function t(t){var r=e.call(this)||this;return r.privId=o.createNoDashGuid(),r.privCallback=t,r}return i(t,e),Object.defineProperty(t.prototype,"format",{set:function(e){},enumerable:!0,configurable:!0}),t.prototype.write=function(e){this.privCallback.write&&this.privCallback.write(e)},t.prototype.close=function(){this.privCallback.close&&this.privCallback.close()},t.prototype.id=function(){return this.privId},t}(f);t.PushAudioOutputStreamImpl=h},function(e,t,r){"use strict";var n,i,o=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var s,a=r(45),c=r(42);!function(e){e[e.PCM=1]="PCM",e[e.MuLaw=2]="MuLaw",e[e.Siren=3]="Siren",e[e.MP3=4]="MP3",e[e.SILKSkype=5]="SILKSkype",e[e.Opus=6]="Opus"}(s=t.AudioFormatTag||(t.AudioFormatTag={}));var p=function(e){function t(t,r,n,i,o,s,a,c,p){var u=e.call(this,n,s,r)||this;return u.formatTag=t,u.avgBytesPerSec=i,u.blockAlign=o,u.priAudioFormatString=a,u.priRequestAudioFormatString=c,u.priHasHeader=p,u}return o(t,e),t.fromSpeechSynthesisOutputFormat=function(e){return void 0===e?t.getDefaultOutputFormat():t.fromSpeechSynthesisOutputFormatString(t.SpeechSynthesisOutputFormatToString[e])},t.fromSpeechSynthesisOutputFormatString=function(e){switch(e){case"raw-8khz-8bit-mono-mulaw":return new t(s.PCM,1,8e3,8e3,1,8,e,e,!1);case"riff-16khz-16kbps-mono-siren":return new t(s.Siren,1,16e3,2e3,40,0,e,"audio-16khz-16kbps-mono-siren",!0);case"audio-16khz-16kbps-mono-siren":return new t(s.Siren,1,16e3,2e3,40,0,e,e,!1);case"audio-16khz-32kbitrate-mono-mp3":return new t(s.MP3,1,16e3,4096,2,16,e,e,!1);case"audio-16khz-128kbitrate-mono-mp3":return new t(s.MP3,1,16e3,16384,2,16,e,e,!1);case"audio-16khz-64kbitrate-mono-mp3":return new t(s.MP3,1,16e3,8192,2,16,e,e,!1);case"audio-24khz-48kbitrate-mono-mp3":return new t(s.MP3,1,16e3,6144,2,16,e,e,!1);case"audio-24khz-96kbitrate-mono-mp3":return new t(s.MP3,1,16e3,12288,2,16,e,e,!1);case"audio-24khz-160kbitrate-mono-mp3":return new t(s.MP3,1,16e3,20480,2,16,e,e,!1);case"raw-16khz-16bit-mono-truesilk":return new t(s.SILKSkype,1,16e3,32e3,2,16,e,e,!1);case"riff-8khz-16bit-mono-pcm":return new t(s.PCM,1,8e3,16e3,2,16,e,"raw-8khz-16bit-mono-pcm",!0);case"riff-24khz-16bit-mono-pcm":return new t(s.PCM,1,24e3,48e3,2,16,e,"raw-24khz-16bit-mono-pcm",!0);case"riff-8khz-8bit-mono-mulaw":return new t(s.MuLaw,1,8e3,8e3,1,8,e,"raw-8khz-8bit-mono-mulaw",!0);case"raw-16khz-16bit-mono-pcm":return new t(s.PCM,1,16e3,32e3,2,16,e,"raw-16khz-16bit-mono-pcm",!1);case"raw-24khz-16bit-mono-pcm":return new t(s.PCM,1,24e3,48e3,2,16,e,"raw-24khz-16bit-mono-pcm",!1);case"raw-8khz-16bit-mono-pcm":return new t(s.PCM,1,8e3,16e3,2,16,e,"raw-8khz-16bit-mono-pcm",!1);case"ogg-16khz-16bit-mono-opus":return new t(s.Opus,1,16e3,8192,2,16,e,"ogg-16khz-16bit-mono-opus",!1);case"ogg-24khz-16bit-mono-opus":return new t(s.Opus,1,24e3,8192,2,16,e,"ogg-24khz-16bit-mono-opus",!1);case"riff-16khz-16bit-mono-pcm":default:return new t(s.PCM,1,16e3,32e3,2,16,"riff-16khz-16bit-mono-pcm","raw-16khz-16bit-mono-pcm",!0)}},t.getDefaultOutputFormat=function(){return t.fromSpeechSynthesisOutputFormatString("undefined"!=typeof window?"audio-24khz-48kbitrate-mono-mp3":"riff-16khz-16bit-mono-pcm")},Object.defineProperty(t.prototype,"hasHeader",{get:function(){return this.priHasHeader},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"header",{get:function(){if(this.hasHeader)return this.privHeader},enumerable:!0,configurable:!0}),t.prototype.updateHeader=function(e){this.priHasHeader&&new DataView(this.privHeader).setUint32(40,e,!0)},Object.defineProperty(t.prototype,"requestAudioFormatString",{get:function(){return this.priRequestAudioFormatString},enumerable:!0,configurable:!0}),t.SpeechSynthesisOutputFormatToString=((i={})[a.SpeechSynthesisOutputFormat.Raw8Khz8BitMonoMULaw]="raw-8khz-8bit-mono-mulaw",i[a.SpeechSynthesisOutputFormat.Riff16Khz16KbpsMonoSiren]="riff-16khz-16kbps-mono-siren",i[a.SpeechSynthesisOutputFormat.Audio16Khz16KbpsMonoSiren]="audio-16khz-16kbps-mono-siren",i[a.SpeechSynthesisOutputFormat.Audio16Khz32KBitRateMonoMp3]="audio-16khz-32kbitrate-mono-mp3",i[a.SpeechSynthesisOutputFormat.Audio16Khz128KBitRateMonoMp3]="audio-16khz-128kbitrate-mono-mp3",i[a.SpeechSynthesisOutputFormat.Audio16Khz64KBitRateMonoMp3]="audio-16khz-64kbitrate-mono-mp3",i[a.SpeechSynthesisOutputFormat.Audio24Khz48KBitRateMonoMp3]="audio-24khz-48kbitrate-mono-mp3",i[a.SpeechSynthesisOutputFormat.Audio24Khz96KBitRateMonoMp3]="audio-24khz-96kbitrate-mono-mp3",i[a.SpeechSynthesisOutputFormat.Audio24Khz160KBitRateMonoMp3]="audio-24khz-160kbitrate-mono-mp3",i[a.SpeechSynthesisOutputFormat.Raw16Khz16BitMonoTrueSilk]="raw-16khz-16bit-mono-truesilk",i[a.SpeechSynthesisOutputFormat.Riff16Khz16BitMonoPcm]="riff-16khz-16bit-mono-pcm",i[a.SpeechSynthesisOutputFormat.Riff8Khz16BitMonoPcm]="riff-8khz-16bit-mono-pcm",i[a.SpeechSynthesisOutputFormat.Riff24Khz16BitMonoPcm]="riff-24khz-16bit-mono-pcm",i[a.SpeechSynthesisOutputFormat.Riff8Khz8BitMonoMULaw]="riff-8khz-8bit-mono-mulaw",i[a.SpeechSynthesisOutputFormat.Raw16Khz16BitMonoPcm]="raw-16khz-16bit-mono-pcm",i[a.SpeechSynthesisOutputFormat.Raw24Khz16BitMonoPcm]="raw-24khz-16bit-mono-pcm",i[a.SpeechSynthesisOutputFormat.Raw8Khz16BitMonoPcm]="raw-8khz-16bit-mono-pcm",i[a.SpeechSynthesisOutputFormat.Ogg16Khz16BitMonoOpus]="ogg-16khz-16bit-mono-opus",i[a.SpeechSynthesisOutputFormat.Ogg24Khz16BitMonoOpus]="ogg-24khz-16bit-mono-opus",i),t}(c.AudioStreamFormatImpl);t.AudioOutputFormatImpl=p},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.Raw8Khz8BitMonoMULaw=0]="Raw8Khz8BitMonoMULaw",e[e.Riff16Khz16KbpsMonoSiren=1]="Riff16Khz16KbpsMonoSiren",e[e.Audio16Khz16KbpsMonoSiren=2]="Audio16Khz16KbpsMonoSiren",e[e.Audio16Khz32KBitRateMonoMp3=3]="Audio16Khz32KBitRateMonoMp3",e[e.Audio16Khz128KBitRateMonoMp3=4]="Audio16Khz128KBitRateMonoMp3",e[e.Audio16Khz64KBitRateMonoMp3=5]="Audio16Khz64KBitRateMonoMp3",e[e.Audio24Khz48KBitRateMonoMp3=6]="Audio24Khz48KBitRateMonoMp3",e[e.Audio24Khz96KBitRateMonoMp3=7]="Audio24Khz96KBitRateMonoMp3",e[e.Audio24Khz160KBitRateMonoMp3=8]="Audio24Khz160KBitRateMonoMp3",e[e.Raw16Khz16BitMonoTrueSilk=9]="Raw16Khz16BitMonoTrueSilk",e[e.Riff16Khz16BitMonoPcm=10]="Riff16Khz16BitMonoPcm",e[e.Riff8Khz16BitMonoPcm=11]="Riff8Khz16BitMonoPcm",e[e.Riff24Khz16BitMonoPcm=12]="Riff24Khz16BitMonoPcm",e[e.Riff8Khz8BitMonoMULaw=13]="Riff8Khz8BitMonoMULaw",e[e.Raw16Khz16BitMonoPcm=14]="Raw16Khz16BitMonoPcm",e[e.Raw24Khz16BitMonoPcm=15]="Raw24Khz16BitMonoPcm",e[e.Raw8Khz16BitMonoPcm=16]="Raw8Khz16BitMonoPcm",e[e.Ogg16Khz16BitMonoOpus=17]="Ogg16Khz16BitMonoOpus",e[e.Ogg24Khz16BitMonoOpus=18]="Ogg24Khz16BitMonoOpus"}(t.SpeechSynthesisOutputFormat||(t.SpeechSynthesisOutputFormat={}))},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.Error=0]="Error",e[e.EndOfStream=1]="EndOfStream"}(t.CancellationReason||(t.CancellationReason={}))},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){};t.PullAudioInputStreamCallback=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){};t.PushAudioOutputStreamCallback=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(33),i=function(){function e(){this.privDisposed=!1}return e.fromFile=function(e){throw n.Contracts.throwIfFileDoesNotExist(e,"fileName"),new Error("Not yet implemented.")},e.fromStream=function(e){throw n.Contracts.throwIfNull(e,"file"),new Error("Not yet implemented.")},e.prototype.close=function(){this.privDisposed||(this.privDisposed=!0)},e}();t.KeywordRecognitionModel=i},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e){this.privSessionId=e}return Object.defineProperty(e.prototype,"sessionId",{get:function(){return this.privSessionId},enumerable:!0,configurable:!0}),e}();t.SessionEventArgs=n},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t,r){var n=e.call(this,r)||this;return n.privOffset=t,n}return i(t,e),Object.defineProperty(t.prototype,"offset",{get:function(){return this.privOffset},enumerable:!0,configurable:!0}),t}(r(31).SessionEventArgs);t.RecognitionEventArgs=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.Simple=0]="Simple",e[e.Detailed=1]="Detailed"}(t.OutputFormat||(t.OutputFormat={}))},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t,r,n){var i=e.call(this,r,n)||this;return i.privResult=t,i}return i(t,e),Object.defineProperty(t.prototype,"result",{get:function(){return this.privResult},enumerable:!0,configurable:!0}),t}(r(31).RecognitionEventArgs);t.IntentRecognitionEventArgs=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t,r,n,i,o,s,a,c,p){this.privResultId=e,this.privReason=t,this.privText=r,this.privDuration=n,this.privOffset=i,this.privLanguage=o,this.privLanguageDetectionConfidence=s,this.privErrorDetails=a,this.privJson=c,this.privProperties=p}return Object.defineProperty(e.prototype,"resultId",{get:function(){return this.privResultId},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"reason",{get:function(){return this.privReason},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"text",{get:function(){return this.privText},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"duration",{get:function(){return this.privDuration},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"offset",{get:function(){return this.privOffset},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"language",{get:function(){return this.privLanguage},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"languageDetectionConfidence",{get:function(){return this.privLanguageDetectionConfidence},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"errorDetails",{get:function(){return this.privErrorDetails},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"json",{get:function(){return this.privJson},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"properties",{get:function(){return this.privProperties},enumerable:!0,configurable:!0}),e}();t.RecognitionResult=n},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t,r,n,i,o,s,a,c,p,u){return e.call(this,t,r,n,i,o,s,a,c,p,u)||this}return i(t,e),t}(r(31).RecognitionResult);t.SpeechRecognitionResult=o},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t,r,n,i,o,s,a,c,p,u,f){var h=e.call(this,r,n,i,o,s,a,c,p,u,f)||this;return h.privIntentId=t,h}return i(t,e),Object.defineProperty(t.prototype,"intentId",{get:function(){return this.privIntentId},enumerable:!0,configurable:!0}),t}(r(31).SpeechRecognitionResult);t.IntentRecognitionResult=o},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=r(33),s=function(){function e(){}return e.fromEndpoint=function(e){o.Contracts.throwIfNull(e,"uri"),o.Contracts.throwIfNullOrWhitespace(e.hostname,"uri");var t=new a,r=e.host.indexOf(".");if(-1===r)throw new Error("Could not determine region from endpoint");t.region=e.host.substr(0,r);var n=e.pathname.lastIndexOf("/")+1;if(-1===n)throw new Error("Could not determine appId from endpoint");if(t.appId=e.pathname.substr(n),t.subscriptionKey=e.searchParams.get("subscription-key"),void 0===t.subscriptionKey)throw new Error("Could not determine subscription key from endpoint");return t},e.fromAppId=function(e){o.Contracts.throwIfNullOrWhitespace(e,"appId");var t=new a;return t.appId=e,t},e.fromSubscription=function(e,t,r){o.Contracts.throwIfNullOrWhitespace(e,"subscriptionKey"),o.Contracts.throwIfNullOrWhitespace(t,"appId"),o.Contracts.throwIfNullOrWhitespace(r,"region");var n=new a;return n.appId=t,n.region=r,n.subscriptionKey=e,n},e}();t.LanguageUnderstandingModel=s;var a=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(s);t.LanguageUnderstandingModelImpl=a},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t,r,n){var i=e.call(this,r,n)||this;return i.privResult=t,i}return i(t,e),Object.defineProperty(t.prototype,"result",{get:function(){return this.privResult},enumerable:!0,configurable:!0}),t}(r(31).RecognitionEventArgs);t.SpeechRecognitionEventArgs=o},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t,r,n,i,o){var s=e.call(this,i,o)||this;return s.privReason=t,s.privErrorDetails=r,s.privErrorCode=n,s}return i(t,e),Object.defineProperty(t.prototype,"reason",{get:function(){return this.privReason},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"errorCode",{get:function(){return this.privErrorCode},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"errorDetails",{get:function(){return this.privErrorDetails},enumerable:!0,configurable:!0}),t}(r(31).RecognitionEventArgs);t.SpeechRecognitionCanceledEventArgs=o},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t,r,n){var i=e.call(this,r,n)||this;return i.privResult=t,i}return i(t,e),Object.defineProperty(t.prototype,"result",{get:function(){return this.privResult},enumerable:!0,configurable:!0}),t}(r(31).RecognitionEventArgs);t.TranslationRecognitionEventArgs=o},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t,r){var n=e.call(this,r)||this;return n.privResult=t,n}return i(t,e),Object.defineProperty(t.prototype,"result",{get:function(){return this.privResult},enumerable:!0,configurable:!0}),t}(r(31).SessionEventArgs);t.TranslationSynthesisEventArgs=o},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t,r,n,i,o,s,a,c,p){var u=e.call(this,r,n,i,o,s,void 0,void 0,a,c,p)||this;return u.privTranslations=t,u}return i(t,e),Object.defineProperty(t.prototype,"translations",{get:function(){return this.privTranslations},enumerable:!0,configurable:!0}),t}(r(31).SpeechRecognitionResult);t.TranslationRecognitionResult=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){this.privReason=e,this.privAudio=t}return Object.defineProperty(e.prototype,"audio",{get:function(){return this.privAudio},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"reason",{get:function(){return this.privReason},enumerable:!0,configurable:!0}),e}();t.TranslationSynthesisResult=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.NoMatch=0]="NoMatch",e[e.Canceled=1]="Canceled",e[e.RecognizingSpeech=2]="RecognizingSpeech",e[e.RecognizedSpeech=3]="RecognizedSpeech",e[e.RecognizingIntent=4]="RecognizingIntent",e[e.RecognizedIntent=5]="RecognizedIntent",e[e.TranslatingSpeech=6]="TranslatingSpeech",e[e.TranslatedSpeech=7]="TranslatedSpeech",e[e.SynthesizingAudio=8]="SynthesizingAudio",e[e.SynthesizingAudioCompleted=9]="SynthesizingAudioCompleted",e[e.SynthesizingAudioStarted=10]="SynthesizingAudioStarted",e[e.EnrollingVoiceProfile=11]="EnrollingVoiceProfile",e[e.EnrolledVoiceProfile=12]="EnrolledVoiceProfile",e[e.RecognizedSpeakers=13]="RecognizedSpeakers",e[e.RecognizedSpeaker=14]="RecognizedSpeaker",e[e.ResetVoiceProfile=15]="ResetVoiceProfile",e[e.DeletedVoiceProfile=16]="DeletedVoiceProfile"}(t.ResultReason||(t.ResultReason={}))},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=r(26),s=r(33),a=r(31),c=function(){function e(){}return e.fromSubscription=function(e,t){s.Contracts.throwIfNullOrWhitespace(e,"subscriptionKey"),s.Contracts.throwIfNullOrWhitespace(t,"region");var r=new p;return r.setProperty(a.PropertyId.SpeechServiceConnection_Region,t),r.setProperty(a.PropertyId.SpeechServiceConnection_IntentRegion,t),r.setProperty(a.PropertyId.SpeechServiceConnection_Key,e),r},e.fromEndpoint=function(e,t){s.Contracts.throwIfNull(e,"endpoint");var r=new p;return r.setProperty(a.PropertyId.SpeechServiceConnection_Endpoint,e.href),void 0!==t&&r.setProperty(a.PropertyId.SpeechServiceConnection_Key,t),r},e.fromHost=function(e,t){s.Contracts.throwIfNull(e,"hostName");var r=new p;return r.setProperty(a.PropertyId.SpeechServiceConnection_Host,e.protocol+"//"+e.hostname+(""===e.port?"":":"+e.port)),void 0!==t&&r.setProperty(a.PropertyId.SpeechServiceConnection_Key,t),r},e.fromAuthorizationToken=function(e,t){s.Contracts.throwIfNull(e,"authorizationToken"),s.Contracts.throwIfNullOrWhitespace(t,"region");var r=new p;return r.setProperty(a.PropertyId.SpeechServiceConnection_Region,t),r.setProperty(a.PropertyId.SpeechServiceConnection_IntentRegion,t),r.authorizationToken=e,r},e.prototype.close=function(){},e}();t.SpeechConfig=c;var p=function(e){function t(){var t=e.call(this)||this;return t.privProperties=new a.PropertyCollection,t.speechRecognitionLanguage="en-US",t.outputFormat=a.OutputFormat.Simple,t}return i(t,e),Object.defineProperty(t.prototype,"properties",{get:function(){return this.privProperties},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"endPoint",{get:function(){return new URL(this.privProperties.getProperty(a.PropertyId.SpeechServiceConnection_Endpoint))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"subscriptionKey",{get:function(){return this.privProperties.getProperty(a.PropertyId.SpeechServiceConnection_Key)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"region",{get:function(){return this.privProperties.getProperty(a.PropertyId.SpeechServiceConnection_Region)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"authorizationToken",{get:function(){return this.privProperties.getProperty(a.PropertyId.SpeechServiceAuthorization_Token)},set:function(e){this.privProperties.setProperty(a.PropertyId.SpeechServiceAuthorization_Token,e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"speechRecognitionLanguage",{get:function(){return this.privProperties.getProperty(a.PropertyId.SpeechServiceConnection_RecoLanguage)},set:function(e){this.privProperties.setProperty(a.PropertyId.SpeechServiceConnection_RecoLanguage,e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"autoDetectSourceLanguages",{get:function(){return this.privProperties.getProperty(a.PropertyId.SpeechServiceConnection_AutoDetectSourceLanguages)},set:function(e){this.privProperties.setProperty(a.PropertyId.SpeechServiceConnection_AutoDetectSourceLanguages,e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"outputFormat",{get:function(){return a.OutputFormat[this.privProperties.getProperty(o.OutputFormatPropertyName,void 0)]},set:function(e){this.privProperties.setProperty(o.OutputFormatPropertyName,a.OutputFormat[e])},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"endpointId",{get:function(){return this.privProperties.getProperty(a.PropertyId.SpeechServiceConnection_EndpointId)},set:function(e){this.privProperties.setProperty(a.PropertyId.SpeechServiceConnection_EndpointId,e)},enumerable:!0,configurable:!0}),t.prototype.setProperty=function(e,t){s.Contracts.throwIfNull(t,"value"),this.privProperties.setProperty(e,t)},t.prototype.getProperty=function(e,t){return this.privProperties.getProperty(e,t)},t.prototype.setProxy=function(e,t,r,n){this.setProperty(a.PropertyId[a.PropertyId.SpeechServiceConnection_ProxyHostName],e),this.setProperty(a.PropertyId[a.PropertyId.SpeechServiceConnection_ProxyPort],t),this.setProperty(a.PropertyId[a.PropertyId.SpeechServiceConnection_ProxyUserName],r),this.setProperty(a.PropertyId[a.PropertyId.SpeechServiceConnection_ProxyPassword],n)},t.prototype.setServiceProperty=function(e,t,r){var n=JSON.parse(this.privProperties.getProperty(o.ServicePropertiesPropertyName,"{}"));n[e]=t,this.privProperties.setProperty(o.ServicePropertiesPropertyName,JSON.stringify(n))},t.prototype.setProfanity=function(e){this.privProperties.setProperty(a.PropertyId.SpeechServiceResponse_ProfanityOption,a.ProfanityOption[e])},t.prototype.enableAudioLogging=function(){this.privProperties.setProperty(a.PropertyId.SpeechServiceConnection_EnableAudioLogging,"true")},t.prototype.requestWordLevelTimestamps=function(){this.privProperties.setProperty(a.PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps,"true")},t.prototype.enableDictation=function(){this.privProperties.setProperty(o.ForceDictationPropertyName,"true")},t.prototype.clone=function(){var e=new t;return e.privProperties=this.privProperties.clone(),e},Object.defineProperty(t.prototype,"speechSynthesisLanguage",{get:function(){return this.privProperties.getProperty(a.PropertyId.SpeechServiceConnection_SynthLanguage)},set:function(e){this.privProperties.setProperty(a.PropertyId.SpeechServiceConnection_SynthLanguage,e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"speechSynthesisVoiceName",{get:function(){return this.privProperties.getProperty(a.PropertyId.SpeechServiceConnection_SynthVoice)},set:function(e){this.privProperties.setProperty(a.PropertyId.SpeechServiceConnection_SynthVoice,e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"speechSynthesisOutputFormat",{get:function(){return a.SpeechSynthesisOutputFormat[this.privProperties.getProperty(a.PropertyId.SpeechServiceConnection_SynthOutputFormat,void 0)]},set:function(e){this.privProperties.setProperty(a.PropertyId.SpeechServiceConnection_SynthOutputFormat,a.SpeechSynthesisOutputFormat[e])},enumerable:!0,configurable:!0}),t}(c);t.SpeechConfigImpl=p},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=r(26),s=r(33),a=r(31),c=function(e){function t(){return e.call(this)||this}return i(t,e),t.fromSubscription=function(e,t){s.Contracts.throwIfNullOrWhitespace(e,"subscriptionKey"),s.Contracts.throwIfNullOrWhitespace(t,"region");var r=new p;return r.properties.setProperty(a.PropertyId.SpeechServiceConnection_Key,e),r.properties.setProperty(a.PropertyId.SpeechServiceConnection_Region,t),r},t.fromAuthorizationToken=function(e,t){s.Contracts.throwIfNullOrWhitespace(e,"authorizationToken"),s.Contracts.throwIfNullOrWhitespace(t,"region");var r=new p;return r.properties.setProperty(a.PropertyId.SpeechServiceAuthorization_Token,e),r.properties.setProperty(a.PropertyId.SpeechServiceConnection_Region,t),r},t.fromHost=function(e,t){s.Contracts.throwIfNull(e,"hostName");var r=new p;return r.setProperty(a.PropertyId.SpeechServiceConnection_Host,e.protocol+"//"+e.hostname+(""===e.port?"":":"+e.port)),void 0!==t&&r.setProperty(a.PropertyId.SpeechServiceConnection_Key,t),r},t.fromEndpoint=function(e,t){s.Contracts.throwIfNull(e,"endpoint"),s.Contracts.throwIfNull(t,"subscriptionKey");var r=new p;return r.properties.setProperty(a.PropertyId.SpeechServiceConnection_Endpoint,e.href),r.properties.setProperty(a.PropertyId.SpeechServiceConnection_Key,t),r},t}(a.SpeechConfig);t.SpeechTranslationConfig=c;var p=function(e){function t(){var t=e.call(this)||this;return t.privSpeechProperties=new a.PropertyCollection,t.outputFormat=a.OutputFormat.Simple,t}return i(t,e),Object.defineProperty(t.prototype,"authorizationToken",{set:function(e){s.Contracts.throwIfNullOrWhitespace(e,"value"),this.privSpeechProperties.setProperty(a.PropertyId.SpeechServiceAuthorization_Token,e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"speechRecognitionLanguage",{set:function(e){s.Contracts.throwIfNullOrWhitespace(e,"value"),this.privSpeechProperties.setProperty(a.PropertyId.SpeechServiceConnection_RecoLanguage,e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"subscriptionKey",{get:function(){return this.privSpeechProperties.getProperty(a.PropertyId[a.PropertyId.SpeechServiceConnection_Key])},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"outputFormat",{get:function(){return a.OutputFormat[this.privSpeechProperties.getProperty(o.OutputFormatPropertyName,void 0)]},set:function(e){this.privSpeechProperties.setProperty(o.OutputFormatPropertyName,a.OutputFormat[e])},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"endpointId",{get:function(){return this.privSpeechProperties.getProperty(a.PropertyId.SpeechServiceConnection_EndpointId)},set:function(e){this.privSpeechProperties.setProperty(a.PropertyId.SpeechServiceConnection_EndpointId,e)},enumerable:!0,configurable:!0}),t.prototype.addTargetLanguage=function(e){s.Contracts.throwIfNullOrWhitespace(e,"value");var t=this.targetLanguages;t.push(e),this.privSpeechProperties.setProperty(a.PropertyId.SpeechServiceConnection_TranslationToLanguages,t.join(","))},Object.defineProperty(t.prototype,"targetLanguages",{get:function(){return void 0!==this.privSpeechProperties.getProperty(a.PropertyId.SpeechServiceConnection_TranslationToLanguages,void 0)?this.privSpeechProperties.getProperty(a.PropertyId.SpeechServiceConnection_TranslationToLanguages).split(","):[]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"voiceName",{get:function(){return this.getProperty(a.PropertyId[a.PropertyId.SpeechServiceConnection_TranslationVoice])},set:function(e){s.Contracts.throwIfNullOrWhitespace(e,"value"),this.privSpeechProperties.setProperty(a.PropertyId.SpeechServiceConnection_TranslationVoice,e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"region",{get:function(){return this.privSpeechProperties.getProperty(a.PropertyId.SpeechServiceConnection_Region)},enumerable:!0,configurable:!0}),t.prototype.setProxy=function(e,t,r,n){this.setProperty(a.PropertyId[a.PropertyId.SpeechServiceConnection_ProxyHostName],e),this.setProperty(a.PropertyId[a.PropertyId.SpeechServiceConnection_ProxyPort],t),this.setProperty(a.PropertyId[a.PropertyId.SpeechServiceConnection_ProxyUserName],r),this.setProperty(a.PropertyId[a.PropertyId.SpeechServiceConnection_ProxyPassword],n)},t.prototype.getProperty=function(e,t){return this.privSpeechProperties.getProperty(e,t)},t.prototype.setProperty=function(e,t){this.privSpeechProperties.setProperty(e,t)},Object.defineProperty(t.prototype,"properties",{get:function(){return this.privSpeechProperties},enumerable:!0,configurable:!0}),t.prototype.close=function(){},t.prototype.setServiceProperty=function(e,t,r){var n=JSON.parse(this.privSpeechProperties.getProperty(o.ServicePropertiesPropertyName,"{}"));n[e]=t,this.privSpeechProperties.setProperty(o.ServicePropertiesPropertyName,JSON.stringify(n))},t.prototype.setProfanity=function(e){this.privSpeechProperties.setProperty(a.PropertyId.SpeechServiceResponse_ProfanityOption,a.ProfanityOption[e])},t.prototype.enableAudioLogging=function(){this.privSpeechProperties.setProperty(a.PropertyId.SpeechServiceConnection_EnableAudioLogging,"true")},t.prototype.requestWordLevelTimestamps=function(){this.privSpeechProperties.setProperty(a.PropertyId.SpeechServiceResponse_RequestWordLevelTimestamps,"true")},t.prototype.enableDictation=function(){this.privSpeechProperties.setProperty(o.ForceDictationPropertyName,"true")},Object.defineProperty(t.prototype,"speechSynthesisLanguage",{get:function(){return this.privSpeechProperties.getProperty(a.PropertyId.SpeechServiceConnection_SynthLanguage)},set:function(e){this.privSpeechProperties.setProperty(a.PropertyId.SpeechServiceConnection_SynthLanguage,e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"speechSynthesisVoiceName",{get:function(){return this.privSpeechProperties.getProperty(a.PropertyId.SpeechServiceConnection_SynthVoice)},set:function(e){this.privSpeechProperties.setProperty(a.PropertyId.SpeechServiceConnection_SynthVoice,e)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"speechSynthesisOutputFormat",{get:function(){return a.SpeechSynthesisOutputFormat[this.privSpeechProperties.getProperty(a.PropertyId.SpeechServiceConnection_SynthOutputFormat,void 0)]},set:function(e){this.privSpeechProperties.setProperty(a.PropertyId.SpeechServiceConnection_SynthOutputFormat,a.SpeechSynthesisOutputFormat[e])},enumerable:!0,configurable:!0}),t}(c);t.SpeechTranslationConfigImpl=p},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(31),i=function(){function e(){this.privKeys=[],this.privValues=[]}return e.prototype.getProperty=function(e,t){var r;r="string"==typeof e?e:n.PropertyId[e];for(var i=0;i0&&s!==r.me.displayName&&r.changeNicknameAsync(s)}}catch(t){}},r.onConversationExpiration=function(e,t){var n,i;try{(null===(n=r.privConversationTranslator)||void 0===n?void 0:n.conversationExpiration)&&(null===(i=r.privConversationTranslator)||void 0===i||i.conversationExpiration(r.privConversationTranslator,t))}catch(t){}},r.privProperties=new c.PropertyCollection,r.privManager=new s.ConversationManager,t.getProperty(c.PropertyId[c.PropertyId.SpeechServiceConnection_RecoLanguage])||t.setProperty(c.PropertyId[c.PropertyId.SpeechServiceConnection_RecoLanguage],s.ConversationConnectionConfig.defaultLanguageCode),r.privLanguage=t.getProperty(c.PropertyId[c.PropertyId.SpeechServiceConnection_RecoLanguage]),0===t.targetLanguages.length&&t.addTargetLanguage(r.privLanguage),t.getProperty(c.PropertyId[c.PropertyId.SpeechServiceResponse_ProfanityOption])||t.setProfanity(c.ProfanityOption.Masked);var n=t.getProperty(c.PropertyId[c.PropertyId.ConversationTranslator_Name]);(null==n||n.length<=1||n.length>50)&&(n="Host"),t.setProperty(c.PropertyId[c.PropertyId.ConversationTranslator_Name],n),r.privConfig=t;var i=t;return a.Contracts.throwIfNull(i,"speechConfig"),r.privProperties=i.properties.clone(),r.privIsConnected=!1,r.privParticipants=new s.InternalParticipants,r.privIsReady=!1,r.privTextMessageMaxLength=1e3,r}return i(t,e),Object.defineProperty(t.prototype,"conversationTranslator",{set:function(e){this.privConversationTranslator=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"room",{get:function(){return this.privRoom},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"connection",{get:function(){return this.privConversationRecognizer},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"authorizationToken",{get:function(){return this.privToken},set:function(e){a.Contracts.throwIfNullOrWhitespace(e,"authorizationToken"),this.privToken=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"config",{get:function(){return this.privConfig},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"conversationId",{get:function(){return this.privRoom?this.privRoom.roomId:""},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"properties",{get:function(){return this.privProperties},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"speechRecognitionLanguage",{get:function(){return this.privLanguage},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isMutedByHost",{get:function(){var e,t;return(null===(e=this.privParticipants.me)||void 0===e||!e.isHost)&&(null===(t=this.privParticipants.me)||void 0===t?void 0:t.isMuted)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isConnected",{get:function(){return this.privIsConnected&&this.privIsReady},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"participants",{get:function(){return this.toParticipants(!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"me",{get:function(){return this.toParticipant(this.privParticipants.me)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"host",{get:function(){return this.toParticipant(this.privParticipants.host)},enumerable:!0,configurable:!0}),t.prototype.createConversationAsync=function(e,t){var r=this;try{this.privConversationRecognizer&&this.handleError(new Error(this.privErrors.permissionDeniedStart),t),this.privManager.createOrJoin(this.privProperties,void 0,(function(n){n||r.handleError(new Error(r.privErrors.permissionDeniedConnect),t),r.privRoom=n,r.handleCallback(e,t)}),(function(e){r.handleError(e,t)}))}catch(e){this.handleError(e,t)}},t.prototype.startConversationAsync=function(e,t){var r=this;try{this.privConversationRecognizer&&this.handleError(new Error(this.privErrors.permissionDeniedStart),t),a.Contracts.throwIfNullOrUndefined(this.privRoom,this.privErrors.permissionDeniedConnect),this.privParticipants.meId=this.privRoom.participantId,this.privConversationRecognizer=new s.ConversationTranslatorRecognizer(this.privConfig),this.privConversationRecognizer.conversation=this.privRoom,this.privConversationRecognizerConnection=c.Connection.fromRecognizer(this.privConversationRecognizer),this.privConversationRecognizerConnection.connected=this.onConnected,this.privConversationRecognizerConnection.disconnected=this.onDisconnected,this.privConversationRecognizer.canceled=this.onCanceled,this.privConversationRecognizer.participantUpdateCommandReceived=this.onParticipantUpdateCommandReceived,this.privConversationRecognizer.lockRoomCommandReceived=this.onLockRoomCommandReceived,this.privConversationRecognizer.muteAllCommandReceived=this.onMuteAllCommandReceived,this.privConversationRecognizer.participantJoinCommandReceived=this.onParticipantJoinCommandReceived,this.privConversationRecognizer.participantLeaveCommandReceived=this.onParticipantLeaveCommandReceived,this.privConversationRecognizer.translationReceived=this.onTranslationReceived,this.privConversationRecognizer.participantsListReceived=this.onParticipantsListReceived,this.privConversationRecognizer.conversationExpiration=this.onConversationExpiration,this.privConversationRecognizer.connect(this.privRoom.token,(function(){r.handleCallback(e,t)}),(function(e){r.handleError(e,t)}))}catch(e){this.handleError(e,t)}},t.prototype.joinConversationAsync=function(e,t,r,n,i){var o=this;try{a.Contracts.throwIfNullOrWhitespace(e,this.privErrors.invalidArgs.replace("{arg}","conversationId")),a.Contracts.throwIfNullOrWhitespace(t,this.privErrors.invalidArgs.replace("{arg}","nickname")),a.Contracts.throwIfNullOrWhitespace(r,this.privErrors.invalidArgs.replace("{arg}","language")),this.privManager.createOrJoin(this.privProperties,e,(function(e){a.Contracts.throwIfNullOrUndefined(e,o.privErrors.permissionDeniedConnect),o.privRoom=e,o.privConfig.authorizationToken=e.cognitiveSpeechAuthToken,n&&n(e.cognitiveSpeechAuthToken)}),(function(e){o.handleError(e,i)}))}catch(e){this.handleError(e,i)}},t.prototype.deleteConversationAsync=function(e,t){var r=this;try{a.Contracts.throwIfNullOrUndefined(this.privProperties,this.privErrors.permissionDeniedConnect),a.Contracts.throwIfNullOrWhitespace(this.privRoom.token,this.privErrors.permissionDeniedConnect),this.privManager.leave(this.privProperties,this.privRoom.token,(function(){r.handleCallback(e,t)}),(function(e){r.handleError(e,t)})),this.dispose()}catch(e){this.handleError(e,t)}},t.prototype.endConversationAsync=function(e,t){try{this.close(!0),this.handleCallback(e,t)}catch(e){this.handleError(e,t)}},t.prototype.lockConversationAsync=function(e,t){var r,n=this;try{a.Contracts.throwIfDisposed(this.privIsDisposed),a.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed()),a.Contracts.throwIfNullOrUndefined(this.privRoom,this.privErrors.permissionDeniedSend),this.canSendAsHost||this.handleError(new Error(this.privErrors.permissionDeniedConversation.replace("{command}","lock")),t),null===(r=this.privConversationRecognizer)||void 0===r||r.sendLockRequest(!0,(function(){n.handleCallback(e,t)}),(function(e){n.handleError(e,t)}))}catch(e){this.handleError(e,t)}},t.prototype.muteAllParticipantsAsync=function(e,t){var r,n=this;try{a.Contracts.throwIfDisposed(this.privIsDisposed),a.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed()),a.Contracts.throwIfNullOrUndefined(this.privConversationRecognizer,this.privErrors.permissionDeniedSend),a.Contracts.throwIfNullOrUndefined(this.privRoom,this.privErrors.permissionDeniedSend),this.canSendAsHost||this.handleError(new Error(this.privErrors.permissionDeniedConversation.replace("{command}","mute")),t),null===(r=this.privConversationRecognizer)||void 0===r||r.sendMuteAllRequest(!0,(function(){n.handleCallback(e,t)}),(function(e){n.handleError(e,t)}))}catch(e){this.handleError(e,t)}},t.prototype.muteParticipantAsync=function(e,t,r){var n,i=this;try{a.Contracts.throwIfDisposed(this.privIsDisposed),a.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed()),a.Contracts.throwIfNullOrWhitespace(e,this.privErrors.invalidArgs.replace("{arg}","userId")),a.Contracts.throwIfNullOrUndefined(this.privRoom,this.privErrors.permissionDeniedSend),this.canSend||this.handleError(new Error(this.privErrors.permissionDeniedSend),r),this.me.isHost||this.me.id===e||this.handleError(new Error(this.privErrors.permissionDeniedParticipant.replace("{command}","mute")),r),-1===this.privParticipants.getParticipantIndex(e)&&this.handleError(new Error(this.privErrors.invalidParticipantRequest),r),null===(n=this.privConversationRecognizer)||void 0===n||n.sendMuteRequest(e,!0,(function(){i.handleCallback(t,r)}),(function(e){i.handleError(e,r)}))}catch(e){this.handleError(e,r)}},t.prototype.removeParticipantAsync=function(e,t,r){var n,i=this;try{a.Contracts.throwIfDisposed(this.privIsDisposed),a.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed()),a.Contracts.throwIfNullOrUndefined(this.privRoom,this.privErrors.permissionDeniedSend),this.canSendAsHost||this.handleError(new Error(this.privErrors.permissionDeniedParticipant.replace("{command}","remove")),r);var o="";if("string"==typeof e)o=e;else if(e.hasOwnProperty("id")){o=e.id}else if(e.hasOwnProperty("userId")){o=e.userId}a.Contracts.throwIfNullOrWhitespace(o,this.privErrors.invalidArgs.replace("{arg}","userId")),-1===this.participants.findIndex((function(e){return e.id===o}))&&this.handleError(new Error(this.privErrors.invalidParticipantRequest),r),null===(n=this.privConversationRecognizer)||void 0===n||n.sendEjectRequest(o,(function(){i.handleCallback(t,r)}),(function(e){i.handleError(e,r)}))}catch(e){this.handleError(e,r)}},t.prototype.unlockConversationAsync=function(e,t){var r,n=this;try{a.Contracts.throwIfDisposed(this.privIsDisposed),a.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed()),a.Contracts.throwIfNullOrUndefined(this.privRoom,this.privErrors.permissionDeniedSend),this.canSendAsHost||this.handleError(new Error(this.privErrors.permissionDeniedConversation.replace("{command}","unlock")),t),null===(r=this.privConversationRecognizer)||void 0===r||r.sendLockRequest(!1,(function(){n.handleCallback(e,t)}),(function(e){n.handleError(e,t)}))}catch(e){this.handleError(e,t)}},t.prototype.unmuteAllParticipantsAsync=function(e,t){var r,n=this;try{a.Contracts.throwIfDisposed(this.privIsDisposed),a.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed()),a.Contracts.throwIfNullOrUndefined(this.privRoom,this.privErrors.permissionDeniedSend),this.canSendAsHost||this.handleError(new Error(this.privErrors.permissionDeniedConversation.replace("{command}","unmute all")),t),null===(r=this.privConversationRecognizer)||void 0===r||r.sendMuteAllRequest(!1,(function(){n.handleCallback(e,t)}),(function(e){n.handleError(e,t)}))}catch(e){this.handleError(e,t)}},t.prototype.unmuteParticipantAsync=function(e,t,r){var n,i=this;try{a.Contracts.throwIfDisposed(this.privIsDisposed),a.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed()),a.Contracts.throwIfNullOrWhitespace(e,this.privErrors.invalidArgs.replace("{arg}","userId")),a.Contracts.throwIfNullOrUndefined(this.privRoom,this.privErrors.permissionDeniedSend),this.canSend||this.handleError(new Error(this.privErrors.permissionDeniedSend),r),this.me.isHost||this.me.id===e||this.handleError(new Error(this.privErrors.permissionDeniedParticipant.replace("{command}","mute")),r),-1===this.privParticipants.getParticipantIndex(e)&&this.handleError(new Error(this.privErrors.invalidParticipantRequest),r),null===(n=this.privConversationRecognizer)||void 0===n||n.sendMuteRequest(e,!1,(function(){i.handleCallback(t,r)}),(function(e){i.handleError(e,r)}))}catch(e){this.handleError(e,r)}},t.prototype.sendTextMessageAsync=function(e,t,r){var n,i=this;try{a.Contracts.throwIfDisposed(this.privIsDisposed),a.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed()),a.Contracts.throwIfNullOrWhitespace(e,this.privErrors.invalidArgs.replace("{arg}","message")),a.Contracts.throwIfNullOrUndefined(this.privRoom,this.privErrors.permissionDeniedSend),this.canSend||this.handleError(new Error(this.privErrors.permissionDeniedSend),r),e.length>this.privTextMessageMaxLength&&this.handleError(new Error(this.privErrors.invalidArgs.replace("{arg}","message length")),r),null===(n=this.privConversationRecognizer)||void 0===n||n.sendMessageRequest(e,(function(){i.handleCallback(t,r)}),(function(e){i.handleError(e,r)}))}catch(e){this.handleError(e,r)}},t.prototype.changeNicknameAsync=function(e,t,r){var n,i=this;try{a.Contracts.throwIfDisposed(this.privIsDisposed),a.Contracts.throwIfDisposed(this.privConversationRecognizer.isDisposed()),a.Contracts.throwIfNullOrWhitespace(e,this.privErrors.invalidArgs.replace("{arg}","nickname")),a.Contracts.throwIfNullOrUndefined(this.privRoom,this.privErrors.permissionDeniedSend),this.canSend||this.handleError(new Error(this.privErrors.permissionDeniedSend),r),null===(n=this.privConversationRecognizer)||void 0===n||n.sendChangeNicknameRequest(e,(function(){i.handleCallback(t,r)}),(function(e){i.handleError(e,r)}))}catch(e){this.handleError(e,r)}},t.prototype.isDisposed=function(){return this.privIsDisposed},t.prototype.dispose=function(e){var t;this.isDisposed||(this.privIsDisposed=!0,null===(t=this.config)||void 0===t||t.close(),this.privConversationRecognizerConnection&&(this.privConversationRecognizerConnection.closeConnection(),this.privConversationRecognizerConnection.close(),this.privConversationRecognizerConnection=void 0),this.privConfig=void 0,this.privLanguage=void 0,this.privProperties=void 0,this.privRoom=void 0,this.privToken=void 0,this.privManager=void 0,this.privConversationRecognizer=void 0,this.privIsConnected=!1,this.privIsReady=!1,this.privParticipants=void 0,this.privRoom=void 0)},t.prototype.close=function(e){var t,r,n;try{this.privIsConnected=!1,null===(t=this.privConversationRecognizerConnection)||void 0===t||t.closeConnection(),null===(r=this.privConversationRecognizerConnection)||void 0===r||r.close(),this.privConversationRecognizer.close(),this.privConversationRecognizerConnection=void 0,this.privConversationRecognizer=void 0,null===(n=this.privConversationTranslator)||void 0===n||n.dispose()}catch(e){}e&&this.dispose()},Object.defineProperty(t.prototype,"canSend",{get:function(){var e;return this.privIsConnected&&!(null===(e=this.privParticipants.me)||void 0===e?void 0:e.isMuted)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"canSendAsHost",{get:function(){var e;return this.privIsConnected&&(null===(e=this.privParticipants.me)||void 0===e?void 0:e.isHost)},enumerable:!0,configurable:!0}),t.prototype.handleCallback=function(e,t){if(e){try{e()}catch(e){t&&t(e)}e=void 0}},t.prototype.handleError=function(e,t){if(t)if(e instanceof Error){var r=e;t(r.name+": "+r.message)}else t(e)},t.prototype.toParticipants=function(e){var t=this,r=this.privParticipants.participants.map((function(e){return t.toParticipant(e)}));return e?r:r.filter((function(e){return!1===e.isHost}))},t.prototype.toParticipant=function(e){return new c.Participant(e.id,e.avatar,e.displayName,e.isHost,e.isMuted,e.isUsingTts,e.preferredLanguage)},t}(p);t.ConversationImpl=u},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t,r){var n=e.call(this,r)||this;return n.privExpirationTime=t,n}return i(t,e),Object.defineProperty(t.prototype,"expirationTime",{get:function(){return this.privExpirationTime},enumerable:!0,configurable:!0}),t}(r(31).SessionEventArgs);t.ConversationExpirationEventArgs=o},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t,r,n){var i=e.call(this,n)||this;return i.privReason=t,i.privParticipant=r,i}return i(t,e),Object.defineProperty(t.prototype,"reason",{get:function(){return this.privReason},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"participants",{get:function(){return this.privParticipant},enumerable:!0,configurable:!0}),t}(r(31).SessionEventArgs);t.ConversationParticipantsChangedEventArgs=o},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t,r,n,i,o){var s=e.call(this,i,o)||this;return s.privReason=t,s.privErrorDetails=r,s.privErrorCode=n,s}return i(t,e),Object.defineProperty(t.prototype,"reason",{get:function(){return this.privReason},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"errorCode",{get:function(){return this.privErrorCode},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"errorDetails",{get:function(){return this.privErrorDetails},enumerable:!0,configurable:!0}),t}(r(31).RecognitionEventArgs);t.ConversationTranslationCanceledEventArgs=o},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t,r,n){var i=e.call(this,r,n)||this;return i.privResult=t,i}return i(t,e),Object.defineProperty(t.prototype,"result",{get:function(){return this.privResult},enumerable:!0,configurable:!0}),t}(r(31).RecognitionEventArgs);t.ConversationTranslationEventArgs=o},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t,r,n,i,o,s,a,c,p,u,f){var h=e.call(this,r,i,o,s,a,c,p,u,f)||this;return h.privId=t,h.privOrigLang=n,h}return i(t,e),Object.defineProperty(t.prototype,"participantId",{get:function(){return this.privId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"originalLang",{get:function(){return this.privOrigLang},enumerable:!0,configurable:!0}),t}(r(62).TranslationRecognitionResult);t.ConversationTranslationResult=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n,i=r(26),o=r(33),s=r(31),a=r(112),c=r(111);!function(e){e[e.Inactive=0]="Inactive",e[e.Connecting=1]="Connecting",e[e.Connected=2]="Connected"}(n=t.SpeechState||(t.SpeechState={}));var p=function(){function e(e){var t=this;this.privIsDisposed=!1,this.privIsSpeaking=!1,this.privSpeechState=n.Inactive,this.privErrors=i.ConversationConnectionConfig.restErrors,this.privPlaceholderKey="abcdefghijklmnopqrstuvwxyz012345",this.privPlaceholderRegion="westus",this.onSpeechConnected=function(e){t.privSpeechState=n.Connected},this.onSpeechDisconnected=function(e){t.privSpeechState=n.Inactive,t.cancelSpeech()},this.onSpeechRecognized=function(e,r){var n;(null===(n=r.result)||void 0===n?void 0:n.errorDetails)&&(t.cancelSpeech(),t.fireCancelEvent(r.result.errorDetails))},this.onSpeechRecognizing=function(e,t){},this.onSpeechCanceled=function(e,r){if(t.privSpeechState!==n.Inactive)try{t.cancelSpeech()}catch(e){t.privSpeechState=n.Inactive}},this.onSpeechSessionStarted=function(e,r){t.privSpeechState=n.Connected},this.onSpeechSessionStopped=function(e,r){t.privSpeechState=n.Inactive},this.privProperties=new s.PropertyCollection,this.privAudioConfig=e}return Object.defineProperty(e.prototype,"properties",{get:function(){return this.privProperties},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"speechRecognitionLanguage",{get:function(){return this.privSpeechRecognitionLanguage},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"participants",{get:function(){var e;return null===(e=this.privConversation)||void 0===e?void 0:e.participants},enumerable:!0,configurable:!0}),e.prototype.joinConversationAsync=function(e,t,r,n,c){var p=this;try{if("string"==typeof e){o.Contracts.throwIfNullOrUndefined(e,this.privErrors.invalidArgs.replace("{arg}","conversation id")),o.Contracts.throwIfNullOrWhitespace(t,this.privErrors.invalidArgs.replace("{arg}","nickname")),this.privConversation&&this.handleError(new Error(this.privErrors.permissionDeniedStart),c);var u=r;null!=u&&""!==u||(u=i.ConversationConnectionConfig.defaultLanguageCode),this.privSpeechTranslationConfig=s.SpeechTranslationConfig.fromSubscription(this.privPlaceholderKey,this.privPlaceholderRegion),this.privSpeechTranslationConfig.setProfanity(s.ProfanityOption.Masked),this.privSpeechTranslationConfig.addTargetLanguage(u),this.privSpeechTranslationConfig.setProperty(s.PropertyId[s.PropertyId.SpeechServiceConnection_RecoLanguage],u),this.privSpeechTranslationConfig.setProperty(s.PropertyId[s.PropertyId.ConversationTranslator_Name],t);var f=this.privProperties.getProperty(s.PropertyId.ConversationTranslator_Host);f&&this.privSpeechTranslationConfig.setProperty(s.PropertyId[s.PropertyId.ConversationTranslator_Host],f);var h=this.privProperties.getProperty(s.PropertyId.SpeechServiceConnection_Host);h&&this.privSpeechTranslationConfig.setProperty(s.PropertyId[s.PropertyId.SpeechServiceConnection_Host],h),this.privConversation=new a.ConversationImpl(this.privSpeechTranslationConfig),this.privConversation.conversationTranslator=this,this.privConversation.joinConversationAsync(e,t,u,(function(e){e||p.handleError(new Error(p.privErrors.permissionDeniedConnect),c),p.privSpeechTranslationConfig.authorizationToken=e,p.privConversation.startConversationAsync((function(){p.handleCallback(n,c)}),(function(e){p.handleError(e,c)}))}),(function(e){p.handleError(e,c)}))}else"object"==typeof e?(o.Contracts.throwIfNullOrUndefined(e,this.privErrors.invalidArgs.replace("{arg}","conversation id")),o.Contracts.throwIfNullOrWhitespace(t,this.privErrors.invalidArgs.replace("{arg}","nickname")),this.privProperties.setProperty(s.PropertyId.ConversationTranslator_Name,t),this.privConversation=e,this.privConversation.conversationTranslator=this,o.Contracts.throwIfNullOrUndefined(this.privConversation,this.privErrors.permissionDeniedConnect),o.Contracts.throwIfNullOrUndefined(this.privConversation.room.token,this.privErrors.permissionDeniedConnect),this.privSpeechTranslationConfig=e.config,this.handleCallback(r,n)):this.handleError(new Error(this.privErrors.invalidArgs.replace("{arg}","invalid conversation type")),n)}catch(e){this.handleError(e,"string"==typeof r?c:n)}},e.prototype.leaveConversationAsync=function(e,t){var r=this;try{this.cancelSpeech(),this.privConversation.endConversationAsync((function(){r.privConversation.deleteConversationAsync((function(){r.handleCallback(e,t),r.dispose()}),(function(e){r.handleError(e,t)}))}),(function(e){r.handleError(e,t)}))}catch(e){this.handleError(e,t)}},e.prototype.sendTextMessageAsync=function(e,t,r){var n;try{o.Contracts.throwIfNullOrUndefined(this.privConversation,this.privErrors.permissionDeniedSend),o.Contracts.throwIfNullOrWhitespace(e,this.privErrors.invalidArgs.replace("{arg}",e)),null===(n=this.privConversation)||void 0===n||n.sendTextMessageAsync(e,t,r)}catch(e){this.handleError(e,r)}},e.prototype.startTranscribingAsync=function(e,t){var r=this;try{o.Contracts.throwIfNullOrUndefined(this.privConversation,this.privErrors.permissionDeniedSend),o.Contracts.throwIfNullOrUndefined(this.privConversation.room.token,this.privErrors.permissionDeniedConnect),this.canSpeak||this.handleError(new Error(this.privErrors.permissionDeniedSend),t),void 0===this.privTranslationRecognizer?this.connectTranslatorRecognizer((function(){r.startContinuousRecognition((function(){r.privIsSpeaking=!0,r.handleCallback(e,t)}),(function(e){r.privIsSpeaking=!1,r.cancelSpeech(),r.handleError(e,t)}))}),(function(e){r.handleError(e,t)})):this.startContinuousRecognition((function(){r.privIsSpeaking=!0,r.handleCallback(e,t)}),(function(e){r.privIsSpeaking=!1,r.cancelSpeech(),r.handleError(e,t)}))}catch(e){this.handleError(e,t),this.cancelSpeech()}},e.prototype.stopTranscribingAsync=function(e,t){var r,n=this;try{if(!this.privIsSpeaking)return this.cancelSpeech(),void this.handleCallback(e,t);this.privIsSpeaking=!1,null===(r=this.privTranslationRecognizer)||void 0===r||r.stopContinuousRecognitionAsync((function(){n.handleCallback(e,t)}),(function(e){n.handleError(e,t),n.cancelSpeech()}))}catch(e){this.handleError(e,t),this.cancelSpeech()}},e.prototype.isDisposed=function(){return this.privIsDisposed},e.prototype.dispose=function(e){var t,r;this.isDisposed&&!this.privIsSpeaking||(this.cancelSpeech(),this.privIsDisposed=!0,null===(t=this.privSpeechTranslationConfig)||void 0===t||t.close(),this.privSpeechRecognitionLanguage=void 0,this.privProperties=void 0,this.privAudioConfig=void 0,this.privSpeechTranslationConfig=void 0,null===(r=this.privConversation)||void 0===r||r.dispose(),this.privConversation=void 0)},e.prototype.connectTranslatorRecognizer=function(e,t){try{void 0===this.privAudioConfig&&(this.privAudioConfig=s.AudioConfig.fromDefaultMicrophoneInput()),this.privSpeechTranslationConfig.getProperty(s.PropertyId[s.PropertyId.SpeechServiceConnection_Key])===this.privPlaceholderKey&&this.privSpeechTranslationConfig.setProperty(s.PropertyId[s.PropertyId.SpeechServiceConnection_Key],"");var r=encodeURIComponent(this.privConversation.room.token),n=this.privSpeechTranslationConfig.getProperty(s.PropertyId[s.PropertyId.SpeechServiceConnection_Host],i.ConversationConnectionConfig.speechHost),o="wss://"+(n=n.replace("{region}",this.privConversation.room.cognitiveSpeechRegion))+i.ConversationConnectionConfig.speechPath+"?"+i.ConversationConnectionConfig.configParams.token+"="+r;this.privSpeechTranslationConfig.setProperty(s.PropertyId[s.PropertyId.SpeechServiceConnection_Endpoint],o),this.privTranslationRecognizer=new s.TranslationRecognizer(this.privSpeechTranslationConfig,this.privAudioConfig),this.privTranslationRecognizerConnection=s.Connection.fromRecognizer(this.privTranslationRecognizer),this.privTranslationRecognizerConnection.connected=this.onSpeechConnected,this.privTranslationRecognizerConnection.disconnected=this.onSpeechDisconnected,this.privTranslationRecognizer.recognized=this.onSpeechRecognized,this.privTranslationRecognizer.recognizing=this.onSpeechRecognizing,this.privTranslationRecognizer.canceled=this.onSpeechCanceled,this.privTranslationRecognizer.sessionStarted=this.onSpeechSessionStarted,this.privTranslationRecognizer.sessionStopped=this.onSpeechSessionStopped,this.handleCallback(e,t)}catch(e){this.handleError(e,t),this.cancelSpeech()}},e.prototype.startContinuousRecognition=function(e,t){this.privTranslationRecognizer.startContinuousRecognitionAsync(e,t)},e.prototype.fireCancelEvent=function(e){var t,r,n,i,o,a,p;try{if(this.canceled){var u=new c.ConversationTranslationCanceledEventArgs(null!=(r=null===(t=e)||void 0===t?void 0:t.reason)?r:s.CancellationReason.Error,null!=(i=null===(n=e)||void 0===n?void 0:n.errorDetails)?i:e,null!=(a=null===(o=e)||void 0===o?void 0:o.errorCode)?a:s.CancellationErrorCode.RuntimeError,void 0,null===(p=e)||void 0===p?void 0:p.sessionId);this.canceled(this,u)}}catch(e){}},e.prototype.cancelSpeech=function(){var e,t;try{this.privIsSpeaking=!1,null===(e=this.privTranslationRecognizer)||void 0===e||e.stopContinuousRecognitionAsync(),null===(t=this.privTranslationRecognizerConnection)||void 0===t||t.closeConnection(),this.privTranslationRecognizerConnection=void 0,this.privTranslationRecognizer=void 0,this.privSpeechState=n.Inactive}catch(e){}},Object.defineProperty(e.prototype,"canSpeak",{get:function(){return!!this.privConversation.isConnected&&(!this.privIsSpeaking&&this.privSpeechState!==n.Connected&&this.privSpeechState!==n.Connecting&&!this.privConversation.isMutedByHost)},enumerable:!0,configurable:!0}),e.prototype.handleCallback=function(e,t){if(e){try{e()}catch(e){t&&t(e)}e=void 0}},e.prototype.handleError=function(e,t){if(t)if(e instanceof Error){var r=e;t(r.name+": "+r.message)}else t(e)},e}();t.ConversationTranslator=p},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(31),i=function(){function e(e){this.privUserId=e}return Object.defineProperty(e.prototype,"userId",{get:function(){return this.privUserId},enumerable:!0,configurable:!0}),e}();t.User=i;var o=function(){function e(e,t,r,i,o,s,a){this.privId=e,this.privAvatar=t,this.privDisplayName=r,this.privIsHost=i,this.privIsMuted=o,this.privIsUsingTts=s,this.privPreferredLanguage=a,this.privPoperties=new n.PropertyCollection}return Object.defineProperty(e.prototype,"avatar",{get:function(){return this.privAvatar},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"displayName",{get:function(){return this.privDisplayName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return this.privId},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"preferredLanguage",{get:function(){return this.privPreferredLanguage},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isHost",{get:function(){return this.privIsHost},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isMuted",{get:function(){return this.privIsMuted},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isUsingTts",{get:function(){return this.privIsUsingTts},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"properties",{get:function(){return this.privPoperties},enumerable:!0,configurable:!0}),e}();t.Participant=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),function(e){e[e.JoinedConversation=0]="JoinedConversation",e[e.LeftConversation=1]="LeftConversation",e[e.Updated=2]="Updated"}(t.ParticipantChangedReason||(t.ParticipantChangedReason={}))},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(26),i=r(4),o=r(34),s=r(44),a=r(43),c=r(33),p=r(31),u=function(){function e(e,t){var r=e;c.Contracts.throwIfNull(r,"speechConfig"),null!==t&&(this.audioConfig=void 0!==t?t:p.AudioConfig.fromDefaultSpeakerOutput()),this.privProperties=r.properties.clone(),this.privDisposed=!1,this.privSynthesizing=!1,this.privConnectionFactory=new n.SpeechSynthesisConnectionFactory,this.synthesisRequestQueue=new i.Queue,this.implCommonSynthesizeSetup()}return Object.defineProperty(e.prototype,"authorizationToken",{get:function(){return this.properties.getProperty(p.PropertyId.SpeechServiceAuthorization_Token)},set:function(e){c.Contracts.throwIfNullOrWhitespace(e,"token"),this.properties.setProperty(p.PropertyId.SpeechServiceAuthorization_Token,e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"properties",{get:function(){return this.privProperties},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"autoDetectSourceLanguage",{get:function(){return this.properties.getProperty(p.PropertyId.SpeechServiceConnection_AutoDetectSourceLanguages)===n.AutoDetectSourceLanguagesOpenRangeOptionName},enumerable:!0,configurable:!0}),e.FromConfig=function(t,r,n){var i=t;return r.properties.mergeTo(i.properties),new e(t,n)},e.prototype.buildSsml=function(t){var r,n=((r={})["ar-EG"]="Microsoft Server Speech Text to Speech Voice (ar-EG, Hoda)",r["ar-SA"]="Microsoft Server Speech Text to Speech Voice (ar-SA, Naayf)",r["bg-BG"]="Microsoft Server Speech Text to Speech Voice (bg-BG, Ivan)",r["ca-ES"]="Microsoft Server Speech Text to Speech Voice (ca-ES, HerenaRUS)",r["cs-CZ"]="Microsoft Server Speech Text to Speech Voice (cs-CZ, Jakub)",r["da-DK"]="Microsoft Server Speech Text to Speech Voice (da-DK, HelleRUS)",r["de-AT"]="Microsoft Server Speech Text to Speech Voice (de-AT, Michael)",r["de-CH"]="Microsoft Server Speech Text to Speech Voice (de-CH, Karsten)",r["de-DE"]="Microsoft Server Speech Text to Speech Voice (de-DE, HeddaRUS)",r["el-GR"]="Microsoft Server Speech Text to Speech Voice (el-GR, Stefanos)",r["en-AU"]="Microsoft Server Speech Text to Speech Voice (en-AU, HayleyRUS)",r["en-CA"]="Microsoft Server Speech Text to Speech Voice (en-CA, HeatherRUS)",r["en-GB"]="Microsoft Server Speech Text to Speech Voice (en-GB, HazelRUS)",r["en-IE"]="Microsoft Server Speech Text to Speech Voice (en-IE, Sean)",r["en-IN"]="Microsoft Server Speech Text to Speech Voice (en-IN, PriyaRUS)",r["en-US"]="Microsoft Server Speech Text to Speech Voice (en-US, AriaRUS)",r["es-ES"]="Microsoft Server Speech Text to Speech Voice (es-ES, HelenaRUS)",r["es-MX"]="Microsoft Server Speech Text to Speech Voice (es-MX, HildaRUS)",r["fi-FI"]="Microsoft Server Speech Text to Speech Voice (fi-FI, HeidiRUS)",r["fr-CA"]="Microsoft Server Speech Text to Speech Voice (fr-CA, HarmonieRUS)",r["fr-CH"]="Microsoft Server Speech Text to Speech Voice (fr-CH, Guillaume)",r["fr-FR"]="Microsoft Server Speech Text to Speech Voice (fr-FR, HortenseRUS)",r["he-IL"]="Microsoft Server Speech Text to Speech Voice (he-IL, Asaf)",r["hi-IN"]="Microsoft Server Speech Text to Speech Voice (hi-IN, Kalpana)",r["hr-HR"]="Microsoft Server Speech Text to Speech Voice (hr-HR, Matej)",r["hu-HU"]="Microsoft Server Speech Text to Speech Voice (hu-HU, Szabolcs)",r["id-ID"]="Microsoft Server Speech Text to Speech Voice (id-ID, Andika)",r["it-IT"]="Microsoft Server Speech Text to Speech Voice (it-IT, LuciaRUS)",r["ja-JP"]="Microsoft Server Speech Text to Speech Voice (ja-JP, HarukaRUS)",r["ko-KR"]="Microsoft Server Speech Text to Speech Voice (ko-KR, HeamiRUS)",r["ms-MY"]="Microsoft Server Speech Text to Speech Voice (ms-MY, Rizwan)",r["nb-NO"]="Microsoft Server Speech Text to Speech Voice (nb-NO, HuldaRUS)",r["nl-NL"]="Microsoft Server Speech Text to Speech Voice (nl-NL, HannaRUS)",r["pl-PL"]="Microsoft Server Speech Text to Speech Voice (pl-PL, PaulinaRUS)",r["pt-BR"]="Microsoft Server Speech Text to Speech Voice (pt-BR, HeloisaRUS)",r["pt-PT"]="Microsoft Server Speech Text to Speech Voice (pt-PT, HeliaRUS)",r["ro-RO"]="Microsoft Server Speech Text to Speech Voice (ro-RO, Andrei)",r["ru-RU"]="Microsoft Server Speech Text to Speech Voice (ru-RU, EkaterinaRUS)",r["sk-SK"]="Microsoft Server Speech Text to Speech Voice (sk-SK, Filip)",r["sl-SI"]="Microsoft Server Speech Text to Speech Voice (sl-SI, Lado)",r["sv-SE"]="Microsoft Server Speech Text to Speech Voice (sv-SE, HedvigRUS)",r["ta-IN"]="Microsoft Server Speech Text to Speech Voice (ta-IN, Valluvar)",r["te-IN"]="Microsoft Server Speech Text to Speech Voice (te-IN, Chitra)",r["th-TH"]="Microsoft Server Speech Text to Speech Voice (th-TH, Pattara)",r["tr-TR"]="Microsoft Server Speech Text to Speech Voice (tr-TR, SedaRUS)",r["vi-VN"]="Microsoft Server Speech Text to Speech Voice (vi-VN, An)",r["zh-CN"]="Microsoft Server Speech Text to Speech Voice (zh-CN, HuihuiRUS)",r["zh-HK"]="Microsoft Server Speech Text to Speech Voice (zh-HK, TracyRUS)",r["zh-TW"]="Microsoft Server Speech Text to Speech Voice (zh-TW, HanHanRUS)",r),i=this.properties.getProperty(p.PropertyId.SpeechServiceConnection_SynthLanguage,"en-US"),o=this.properties.getProperty(p.PropertyId.SpeechServiceConnection_SynthVoice,""),s=e.XMLEncode(t);return this.autoDetectSourceLanguage?i="en-US":o=o||n[i],o&&(s=""+s+""),s=""+s+""},e.prototype.speakTextAsync=function(e,t,r,n){this.speakImpl(e,!1,t,r,n)},e.prototype.speakSsmlAsync=function(e,t,r,n){this.speakImpl(e,!0,t,r,n)},e.prototype.close=function(){c.Contracts.throwIfDisposed(this.privDisposed),this.dispose(!0)},Object.defineProperty(e.prototype,"internalData",{get:function(){return this.privAdapter},enumerable:!0,configurable:!0}),e.prototype.dispose=function(e){this.privDisposed||(e&&this.privAdapter&&this.privAdapter.dispose(),this.privDisposed=!0)},e.prototype.createSynthesizerConfig=function(e){return new n.SynthesizerConfig(e,this.privProperties)},e.prototype.createSynthesisAdapter=function(e,t,r,i){return new n.SynthesisAdapterBase(e,t,i,this,this.audioConfig)},e.prototype.implCommonSynthesizeSetup=function(){var e=this,t="undefined"!=typeof window?"Browser":"Node",r="unknown",o="unknown";"undefined"!=typeof navigator&&(t=t+"/"+navigator.platform,r=navigator.userAgent,o=navigator.appVersion);var a=this.createSynthesizerConfig(new n.SpeechServiceConfig(new n.Context(new n.OS(t,r,o)))),c=this.privProperties.getProperty(p.PropertyId.SpeechServiceConnection_Key,void 0),u=c&&""!==c?new n.CognitiveSubscriptionKeyAuthentication(c):new n.CognitiveTokenAuthentication((function(t){var r=e.privProperties.getProperty(p.PropertyId.SpeechServiceAuthorization_Token,void 0);return i.PromiseHelper.fromResult(r)}),(function(t){var r=e.privProperties.getProperty(p.PropertyId.SpeechServiceAuthorization_Token,void 0);return i.PromiseHelper.fromResult(r)}));this.privAdapter=this.createSynthesisAdapter(u,this.privConnectionFactory,this.audioConfig,a),this.privAdapter.audioOutputFormat=s.AudioOutputFormatImpl.fromSpeechSynthesisOutputFormat(p.SpeechSynthesisOutputFormat[this.properties.getProperty(p.PropertyId.SpeechServiceConnection_SynthOutputFormat,void 0)])},e.prototype.speakImpl=function(e,t,r,n,s){var u=this;try{c.Contracts.throwIfDisposed(this.privDisposed);var h=i.createNoDashGuid(),v=void 0;v=s instanceof p.PushAudioOutputStreamCallback?new a.PushAudioOutputStreamImpl(s):s instanceof p.PullAudioOutputStream?s:void 0!==s?new o.AudioFileWriter(s):void 0,this.synthesisRequestQueue.enqueue(new f(h,e,t,(function(e){if(u.privSynthesizing=!1,r)try{r(e)}catch(e){n&&n(e)}r=void 0,u.adapterSpeak()}),(function(e){n&&n(e)}),v)),this.adapterSpeak()}catch(e){if(n)if(e instanceof Error){var l=e;n(l.name+": "+l.message)}else n(e);this.dispose(!0)}},e.prototype.adapterSpeak=function(){var e=this;return this.privDisposed||this.privSynthesizing?i.PromiseHelper.fromResult(!0):(this.privSynthesizing=!0,this.synthesisRequestQueue.dequeue().onSuccessContinueWithPromise((function(t){return e.privAdapter.Speak(t.text,t.isSSML,t.requestId,t.cb,t.err,t.dataStream)})))},e.XMLEncode=function(e){return e.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")},e}();t.SpeechSynthesizer=u;var f=function(e,t,r,n,i,o){this.requestId=e,this.text=t,this.isSSML=r,this.cb=n,this.err=i,this.dataStream=o};t.SynthesisRequest=f},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t,r,n,i){this.privResultId=e,this.privReason=t,this.privAudioData=r,this.privErrorDetails=n,this.privProperties=i}return Object.defineProperty(e.prototype,"resultId",{get:function(){return this.privResultId},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"reason",{get:function(){return this.privReason},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"audioData",{get:function(){return this.privAudioData},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"errorDetails",{get:function(){return this.privErrorDetails},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"properties",{get:function(){return this.privProperties},enumerable:!0,configurable:!0}),e}();t.SpeechSynthesisResult=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e){this.privResult=e}return Object.defineProperty(e.prototype,"result",{get:function(){return this.privResult},enumerable:!0,configurable:!0}),e}();t.SpeechSynthesisEventArgs=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t,r,n){this.privAduioOffset=e,this.privText=t,this.privWordLength=r,this.privTextOffset=n}return Object.defineProperty(e.prototype,"audioOffset",{get:function(){return this.privAduioOffset},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"text",{get:function(){return this.privText},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"wordLength",{get:function(){return this.privWordLength},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"textOffset",{get:function(){return this.privTextOffset},enumerable:!0,configurable:!0}),e}();t.SpeechSynthesisWordBoundaryEventArgs=n},function(e,t,r){"use strict";var n;Object.defineProperty(t,"__esModule",{value:!0});var i=r(26),o=r(4),s=r(44),a=r(43),c=((n={})[s.AudioFormatTag.PCM]="audio/wav",n[s.AudioFormatTag.MP3]="audio/mpeg",n[s.AudioFormatTag.Opus]="audio/ogg",n),p=function(){function e(e){this.privPlaybackStarted=!1,this.privAppendingToBuffer=!1,this.privMediaSourceOpened=!1,this.privBytesReceived=0,this.privId=e||o.createNoDashGuid(),this.privIsPaused=!1,this.privIsClosed=!1}return e.prototype.id=function(){return this.privId},e.prototype.write=function(e){void 0!==this.privAudioBuffer?(this.privAudioBuffer.push(e),this.updateSourceBuffer()):void 0!==this.privAudioOutputStream&&(this.privAudioOutputStream.write(e),this.privBytesReceived+=e.byteLength)},e.prototype.close=function(){if(this.privIsClosed=!0,void 0!==this.privSourceBuffer)this.handleSourceBufferUpdateEnd();else if(void 0!==this.privAudioOutputStream){var e=new ArrayBuffer(this.privBytesReceived);this.privAudioOutputStream.read(e),this.privFormat.hasHeader&&(e=i.SynthesisAdapterBase.addHeader(e,this.privFormat));var t=new Blob([e],{type:c[this.privFormat.formatTag]});this.privAudio.src=window.URL.createObjectURL(t),this.notifyPlayback()}},Object.defineProperty(e.prototype,"format",{set:function(e){var t=this;if("undefined"!=typeof AudioContext||void 0!==window.webkitAudioContext){this.privFormat=e;var r=c[this.privFormat.formatTag];void 0===r?console.warn("Unknown mimeType for format "+s.AudioFormatTag[this.privFormat.formatTag]+"."):"undefined"!=typeof MediaSource&&MediaSource.isTypeSupported(r)?(this.privAudio=new Audio,this.privAudioBuffer=[],this.privMediaSource=new MediaSource,this.privAudio.src=URL.createObjectURL(this.privMediaSource),this.privAudio.load(),this.privMediaSource.onsourceopen=function(e){t.privMediaSourceOpened=!0,t.privMediaSource.duration=1800,t.privSourceBuffer=t.privMediaSource.addSourceBuffer(r),t.privSourceBuffer.onupdate=function(e){t.updateSourceBuffer()},t.privSourceBuffer.onupdateend=function(e){t.handleSourceBufferUpdateEnd()},t.privSourceBuffer.onupdatestart=function(e){t.privAppendingToBuffer=!1}},this.updateSourceBuffer()):(console.warn("Format "+s.AudioFormatTag[this.privFormat.formatTag]+" could not be played by MSE, streaming playback is not enabled."),this.privAudioOutputStream=new a.PullAudioOutputStreamImpl,this.privAudioOutputStream.format=this.privFormat,this.privAudio=new Audio)}},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isClosed",{get:function(){return this.privIsClosed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"currentTime",{get:function(){return void 0!==this.privAudio?this.privAudio.currentTime:-1},enumerable:!0,configurable:!0}),e.prototype.pause=function(){this.privIsPaused||void 0===this.privAudio||(this.privAudio.pause(),this.privIsPaused=!0)},e.prototype.resume=function(){this.privIsPaused&&void 0!==this.privAudio&&(this.privAudio.play(),this.privIsPaused=!1)},Object.defineProperty(e.prototype,"internalAudio",{get:function(){return this.privAudio},enumerable:!0,configurable:!0}),e.prototype.updateSourceBuffer=function(){if(void 0!==this.privAudioBuffer&&this.privAudioBuffer.length>0&&this.sourceBufferAvailable()){this.privAppendingToBuffer=!0;var e=this.privAudioBuffer.shift();try{this.privSourceBuffer.appendBuffer(e)}catch(t){return this.privAudioBuffer.unshift(e),void console.log("buffer filled, pausing addition of binaries until space is made")}this.notifyPlayback()}else this.canEndStream()&&this.handleSourceBufferUpdateEnd()},e.prototype.handleSourceBufferUpdateEnd=function(){this.canEndStream()&&this.sourceBufferAvailable()&&(this.privMediaSource.endOfStream(),this.notifyPlayback())},e.prototype.notifyPlayback=function(){var e=this;this.privPlaybackStarted||void 0===this.privAudio||(this.privAudio.onended=function(){e.onAudioEnd&&e.onAudioEnd(e)},this.privIsPaused||this.privAudio.play(),this.privPlaybackStarted=!0)},e.prototype.canEndStream=function(){return this.isClosed&&void 0!==this.privSourceBuffer&&0===this.privAudioBuffer.length&&this.privMediaSourceOpened&&!this.privAppendingToBuffer&&"open"===this.privMediaSource.readyState},e.prototype.sourceBufferAvailable=function(){return void 0!==this.privSourceBuffer&&!this.privSourceBuffer.updating},e}();t.SpeakerAudioDestination=p},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=r(4),s=function(e){function t(t,r,n,i){void 0===i&&(i=o.EventType.Info);var s=e.call(this,t,i)||this;return s.privRequestId=r,s.privSessionId=n,s}return i(t,e),Object.defineProperty(t.prototype,"requestId",{get:function(){return this.privRequestId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"sessionId",{get:function(){return this.privSessionId},enumerable:!0,configurable:!0}),t}(o.PlatformEvent);t.SpeechRecognitionEvent=s;var a=function(e){function t(t,r,n,i){var o=e.call(this,"RecognitionTriggeredEvent",t,r)||this;return o.privAudioSourceId=n,o.privAudioNodeId=i,o}return i(t,e),Object.defineProperty(t.prototype,"audioSourceId",{get:function(){return this.privAudioSourceId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"audioNodeId",{get:function(){return this.privAudioNodeId},enumerable:!0,configurable:!0}),t}(s);t.RecognitionTriggeredEvent=a;var c=function(e){function t(t,r,n,i){var o=e.call(this,"ListeningStartedEvent",t,r)||this;return o.privAudioSourceId=n,o.privAudioNodeId=i,o}return i(t,e),Object.defineProperty(t.prototype,"audioSourceId",{get:function(){return this.privAudioSourceId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"audioNodeId",{get:function(){return this.privAudioNodeId},enumerable:!0,configurable:!0}),t}(s);t.ListeningStartedEvent=c;var p=function(e){function t(t,r,n){var i=e.call(this,"ConnectingToServiceEvent",t,n)||this;return i.privAuthFetchEventid=r,i}return i(t,e),Object.defineProperty(t.prototype,"authFetchEventid",{get:function(){return this.privAuthFetchEventid},enumerable:!0,configurable:!0}),t}(s);t.ConnectingToServiceEvent=p;var u,f=function(e){function t(t,r,n,i,o){var s=e.call(this,"RecognitionStartedEvent",t,o)||this;return s.privAudioSourceId=r,s.privAudioNodeId=n,s.privAuthFetchEventId=i,s}return i(t,e),Object.defineProperty(t.prototype,"audioSourceId",{get:function(){return this.privAudioSourceId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"audioNodeId",{get:function(){return this.privAudioNodeId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"authFetchEventId",{get:function(){return this.privAuthFetchEventId},enumerable:!0,configurable:!0}),t}(s);t.RecognitionStartedEvent=f,function(e){e[e.Success=0]="Success",e[e.AudioSourceError=1]="AudioSourceError",e[e.AudioSourceTimeout=2]="AudioSourceTimeout",e[e.AuthTokenFetchError=3]="AuthTokenFetchError",e[e.AuthTokenFetchTimeout=4]="AuthTokenFetchTimeout",e[e.UnAuthorized=5]="UnAuthorized",e[e.ConnectTimeout=6]="ConnectTimeout",e[e.ConnectError=7]="ConnectError",e[e.ClientRecognitionActivityTimeout=8]="ClientRecognitionActivityTimeout",e[e.UnknownError=9]="UnknownError"}(u=t.RecognitionCompletionStatus||(t.RecognitionCompletionStatus={}));var h=function(e){function t(t,r,n,i,s,a,c,p){var f=e.call(this,"RecognitionEndedEvent",t,s,c===u.Success?o.EventType.Info:o.EventType.Error)||this;return f.privAudioSourceId=r,f.privAudioNodeId=n,f.privAuthFetchEventId=i,f.privStatus=c,f.privError=p,f.privServiceTag=a,f}return i(t,e),Object.defineProperty(t.prototype,"audioSourceId",{get:function(){return this.privAudioSourceId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"audioNodeId",{get:function(){return this.privAudioNodeId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"authFetchEventId",{get:function(){return this.privAuthFetchEventId},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"serviceTag",{get:function(){return this.privServiceTag},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"status",{get:function(){return this.privStatus},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"error",{get:function(){return this.privError},enumerable:!0,configurable:!0}),t}(s);t.RecognitionEndedEvent=h},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(2),i=r(4),o=r(31),s=r(26),a=r(128),c=function(){function e(t,r,n,c,p){var u=this;if(this.privSetTimeout=setTimeout,this.recognizeOverride=void 0,this.disconnectOverride=void 0,this.sendTelemetryData=function(){var t=u.privRequestSession.getTelemetry();if(!0!==e.telemetryDataEnabled||u.privIsDisposed||null===t)return i.PromiseHelper.fromResult(!0);if(e.telemetryData)try{e.telemetryData(t)}catch(e){}return u.fetchConnection().onSuccessContinueWith((function(e){return e.send(new a.SpeechConnectionMessage(i.MessageType.Text,"telemetry",u.privRequestSession.requestId,"application/json",t))}))},this.receiveMessageOverride=void 0,this.receiveMessage=function(){return u.fetchConnection().on((function(e){return e.read().onSuccessContinueWithPromise((function(e){if(void 0!==u.receiveMessageOverride)return u.receiveMessageOverride();if(u.privIsDisposed)return i.PromiseHelper.fromResult(void 0);if(!e)return u.privRequestSession.isRecognizing?u.receiveMessage():i.PromiseHelper.fromResult(!0);u.privServiceHasSentMessage=!0;var t=a.SpeechConnectionMessage.fromConnectionMessage(e);if(t.requestId.toLowerCase()===u.privRequestSession.requestId.toLowerCase())switch(t.path.toLowerCase()){case"turn.start":u.privMustReportEndOfStream=!0,u.privRequestSession.onServiceTurnStartResponse();break;case"speech.startdetected":var r=s.SpeechDetected.fromJSON(t.textBody),n=new o.RecognitionEventArgs(r.Offset,u.privRequestSession.sessionId);u.privRecognizer.speechStartDetected&&u.privRecognizer.speechStartDetected(u.privRecognizer,n);break;case"speech.enddetected":var c=void 0;c=t.textBody.length>0?t.textBody:"{ Offset: 0 }";var p=s.SpeechDetected.fromJSON(c);u.privRecognizerConfig.isContinuousRecognition&&u.privRequestSession.onServiceRecognized(p.Offset+u.privRequestSession.currentTurnAudioOffset);var f=new o.RecognitionEventArgs(p.Offset+u.privRequestSession.currentTurnAudioOffset,u.privRequestSession.sessionId);u.privRecognizer.speechEndDetected&&u.privRecognizer.speechEndDetected(u.privRecognizer,f);break;case"turn.end":u.sendTelemetryData(),u.privRequestSession.isSpeechEnded&&u.privMustReportEndOfStream&&(u.privMustReportEndOfStream=!1,u.cancelRecognitionLocal(o.CancellationReason.EndOfStream,o.CancellationErrorCode.NoError,void 0));var h=new o.SessionEventArgs(u.privRequestSession.sessionId);if(u.privRequestSession.onServiceTurnEndResponse(u.privRecognizerConfig.isContinuousRecognition),!u.privRecognizerConfig.isContinuousRecognition||u.privRequestSession.isSpeechEnded||!u.privRequestSession.isRecognizing)return u.privRecognizer.sessionStopped&&u.privRecognizer.sessionStopped(u.privRecognizer,h),i.PromiseHelper.fromResult(!0);u.fetchConnection().onSuccessContinueWith((function(e){u.sendSpeechContext(e),u.sendWaveHeader(e)}));break;default:u.processTypeSpecificMessages(t)||u.privServiceEvents&&u.serviceEvents.onEvent(new i.ServiceEvent(t.path.toLowerCase(),t.textBody))}return u.receiveMessage()}))}),(function(e){}))},this.sendSpeechContext=function(e){var t=u.speechContext.toJSON();return t?e.send(new a.SpeechConnectionMessage(i.MessageType.Text,"speech.context",u.privRequestSession.requestId,"application/json",t)):i.PromiseHelper.fromResult(!0)},this.connectImplOverride=void 0,this.configConnectionOverride=void 0,this.fetchConnectionOverride=void 0,this.sendSpeechServiceConfig=function(t,r,n){if(!0!==e.telemetryDataEnabled){var o={context:{system:JSON.parse(n).context.system}};n=JSON.stringify(o)}return n?t.send(new a.SpeechConnectionMessage(i.MessageType.Text,"speech.config",r.requestId,"application/json",n)):i.PromiseHelper.fromResult(!0)},this.sendAudio=function(e){return u.audioSource.format.onSuccessContinueWithPromise((function(t){var r=new i.Deferred,n=Date.now(),o=u.privRecognizerConfig.parameters.getProperty("SPEECH-TransmitLengthBeforThrottleMs","5000"),s=t.avgBytesPerSec/1e3*parseInt(o,10),c=u.privRequestSession.recogNumber,p=function(){u.privIsDisposed||u.privRequestSession.isSpeechEnded||!u.privRequestSession.isRecognizing||u.privRequestSession.recogNumber!==c||u.fetchConnection().on((function(o){e.read().on((function(e){var c,f;u.privRequestSession.isSpeechEnded?r.resolve(!0):(!e||e.isEnd?(c=null,f=0):(c=e.buffer,u.privRequestSession.onAudioSent(c.byteLength),f=s>=u.privRequestSession.bytesSent?0:Math.max(0,n-Date.now())),u.privSetTimeout((function(){var s;null!==c&&(n=Date.now()+1e3*c.byteLength/(2*t.avgBytesPerSec));var f=o.send(new a.SpeechConnectionMessage(i.MessageType.Binary,"audio",u.privRequestSession.requestId,null,c));(null===(s=e)||void 0===s?void 0:s.isEnd)?(u.privRequestSession.onSpeechEnded(),r.resolve(!0)):f.continueWith((function(e){p()}))}),f))}),(function(e){u.privRequestSession.isSpeechEnded?r.resolve(!0):r.reject(e)}))}),(function(e){r.reject(e)}))};return p(),r.promise()}))},this.fetchConnection=function(){return void 0!==u.fetchConnectionOverride?u.fetchConnectionOverride():u.configureConnection()},!t)throw new i.ArgumentNullError("authentication");if(!r)throw new i.ArgumentNullError("connectionFactory");if(!n)throw new i.ArgumentNullError("audioSource");if(!c)throw new i.ArgumentNullError("recognizerConfig");this.privMustReportEndOfStream=!1,this.privAuthentication=t,this.privConnectionFactory=r,this.privAudioSource=n,this.privRecognizerConfig=c,this.privIsDisposed=!1,this.privRecognizer=p,this.privRequestSession=new s.RequestSession(this.privAudioSource.id()),this.privConnectionEvents=new i.EventSource,this.privServiceEvents=new i.EventSource,this.privDynamicGrammar=new s.DynamicGrammarBuilder,this.privSpeechContext=new s.SpeechContext(this.privDynamicGrammar),this.privAgentConfig=new s.AgentConfig,"undefined"!=typeof Blob&&"undefined"!=typeof Worker&&(this.privSetTimeout=i.Timeout.setTimeout)}return Object.defineProperty(e.prototype,"audioSource",{get:function(){return this.privAudioSource},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"speechContext",{get:function(){return this.privSpeechContext},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"dynamicGrammar",{get:function(){return this.privDynamicGrammar},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"agentConfig",{get:function(){return this.privAgentConfig},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"conversationTranslatorToken",{set:function(e){this.privRecognizerConfig.parameters.setProperty(o.PropertyId.ConversationTranslator_Token,e)},enumerable:!0,configurable:!0}),e.prototype.isDisposed=function(){return this.privIsDisposed},e.prototype.dispose=function(e){this.privIsDisposed=!0,this.privConnectionConfigurationPromise&&this.privConnectionConfigurationPromise.onSuccessContinueWith((function(t){t.dispose(e)}))},Object.defineProperty(e.prototype,"connectionEvents",{get:function(){return this.privConnectionEvents},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"serviceEvents",{get:function(){return this.privServiceEvents},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"recognitionMode",{get:function(){return this.privRecognizerConfig.recognitionMode},enumerable:!0,configurable:!0}),e.prototype.recognize=function(e,t,r){var s=this;return void 0!==this.recognizeOverride?this.recognizeOverride(e,t,r):(this.privConnectionConfigurationPromise=null,this.privRecognizerConfig.recognitionMode=e,this.privSuccessCallback=t,this.privErrorCallback=r,this.privRequestSession.startNewRecognition(),this.privRequestSession.listenForServiceTelemetry(this.privAudioSource.events),this.connectImpl(),this.audioSource.attach(this.privRequestSession.audioNodeId).onSuccessContinueWithPromise((function(e){var t;return s.audioSource.format.onSuccessContinueWithPromise((function(r){return t=new n.ReplayableAudioNode(e,r.avgBytesPerSec),s.privRequestSession.onAudioSourceAttachCompleted(t,!1),s.audioSource.deviceInfo.onSuccessContinueWithPromise((function(e){return s.privRecognizerConfig.SpeechServiceConfig.Context.audio={source:e},s.configureConnection().continueWithPromise((function(e){if(e.isError)return s.cancelRecognitionLocal(o.CancellationReason.Error,o.CancellationErrorCode.ConnectionFailure,e.error),i.PromiseHelper.fromError(e.error);var r=new o.SessionEventArgs(s.privRequestSession.sessionId);s.privRecognizer.sessionStarted&&s.privRecognizer.sessionStarted(s.privRecognizer,r);s.receiveMessage();return s.sendAudio(t).on((function(e){}),(function(e){s.cancelRecognitionLocal(o.CancellationReason.Error,o.CancellationErrorCode.RuntimeError,e)})),i.PromiseHelper.fromResult(!0)}))}))}))})))},e.prototype.stopRecognizing=function(){var e=this;return this.privRequestSession.isRecognizing?(this.audioSource.turnOff(),this.sendFinalAudio().onSuccessContinueWithPromise((function(t){return e.privRequestSession.onStopRecognizing(),e.privRequestSession.turnCompletionPromise.onSuccessContinueWith((function(t){return e.privRequestSession.onStopRecognizing(),e.privRequestSession.dispose(),!0}))}))):i.PromiseHelper.fromResult(!0)},e.prototype.connect=function(){this.connectImpl().result()},e.prototype.connectAsync=function(e,t){this.connectImpl().continueWith((function(r){try{r.isError?t&&t(r.error):r.isCompleted&&e&&e()}catch(e){t&&t(e)}}))},e.prototype.disconnect=function(){void 0===this.disconnectOverride?(this.cancelRecognitionLocal(o.CancellationReason.Error,o.CancellationErrorCode.NoError,"Disconnecting"),this.privConnectionPromise.result().isCompleted?this.privConnectionPromise.result().isError||(this.privConnectionPromise.result().result.dispose(),this.privConnectionPromise=null):this.privConnectionPromise.onSuccessContinueWith((function(e){e.dispose()}))):this.disconnectOverride()},e.prototype.disconnectAsync=function(e,t){try{if(void 0!==this.disconnectOverride)return this.disconnectOverride(),void(e&&e());this.cancelRecognitionLocal(o.CancellationReason.Error,o.CancellationErrorCode.NoError,"Disconnecting"),this.privConnectionPromise.continueWith((function(r){try{r.isError?t&&t(r.error):r.isCompleted&&(r.result.dispose(),e&&e())}catch(e){t&&t(e)}}))}catch(e){t&&t(e)}},e.prototype.sendMessage=function(e){},e.prototype.sendNetworkMessage=function(e,t,r,n){var o=this,s="string"==typeof t?i.MessageType.Text:i.MessageType.Binary,c="string"==typeof t?"application/json":"";this.fetchConnection().on((function(i){i.send(new a.SpeechConnectionMessage(s,e,o.privRequestSession.requestId,c,t)).on((function(){r&&r()}),(function(e){n&&n(e)}))}),(function(e){n&&n(e)}))},Object.defineProperty(e.prototype,"activityTemplate",{get:function(){return this.privActivityTemplate},set:function(e){this.privActivityTemplate=e},enumerable:!0,configurable:!0}),e.prototype.cancelRecognitionLocal=function(e,t,r){this.privRequestSession.isRecognizing&&(this.privRequestSession.onStopRecognizing(),this.cancelRecognition(this.privRequestSession.sessionId,this.privRequestSession.requestId,e,t,r))},e.prototype.sendWaveHeader=function(e){var t=this;return this.audioSource.format.onSuccessContinueWithPromise((function(r){return e.send(new a.SpeechConnectionMessage(i.MessageType.Binary,"audio",t.privRequestSession.requestId,"audio/x-wav",r.header))}))},e.prototype.connectImpl=function(e){var t=this;if(void 0===e&&(e=!1),void 0!==this.connectImplOverride)return this.connectImplOverride(e);if(this.privConnectionPromise)return this.privConnectionPromise.result().isCompleted&&(this.privConnectionPromise.result().isError||this.privConnectionPromise.result().result.state()===i.ConnectionState.Disconnected)&&!0===this.privServiceHasSentMessage?(this.privConnectionId=null,this.privConnectionPromise=null,this.privServiceHasSentMessage=!1,this.connectImpl()):this.privConnectionPromise;this.privAuthFetchEventId=i.createNoDashGuid(),this.privConnectionId=i.createNoDashGuid(),this.privRequestSession.onPreConnectionStart(this.privAuthFetchEventId,this.privConnectionId);var r=e?this.privAuthentication.fetchOnExpiry(this.privAuthFetchEventId):this.privAuthentication.fetch(this.privAuthFetchEventId);return this.privConnectionPromise=r.continueWithPromise((function(r){if(r.isError)throw t.privRequestSession.onAuthCompleted(!0,r.error),new Error(r.error);t.privRequestSession.onAuthCompleted(!1);var n=t.privConnectionFactory.create(t.privRecognizerConfig,r.result,t.privConnectionId);return t.privRequestSession.listenForServiceTelemetry(n.events),n.events.attach((function(e){t.connectionEvents.onEvent(e)})),n.open().onSuccessContinueWithPromise((function(r){return 200===r.statusCode?(t.privRequestSession.onPreConnectionStart(t.privAuthFetchEventId,t.privConnectionId),t.privRequestSession.onConnectionEstablishCompleted(r.statusCode),i.PromiseHelper.fromResult(n)):403!==r.statusCode||e?(t.privRequestSession.onConnectionEstablishCompleted(r.statusCode,r.reason),i.PromiseHelper.fromError("Unable to contact server. StatusCode: "+r.statusCode+", "+t.privRecognizerConfig.parameters.getProperty(o.PropertyId.SpeechServiceConnection_Endpoint)+" Reason: "+r.reason)):t.connectImpl(!0)}))})),this.privConnectionPromise},e.prototype.writeBufferToConsole=function(e){var t="Buffer Size: ";if(null===e)t+="null";else{var r=new Uint8Array(e);t+=e.byteLength+"\r\n";for(var n=0;n0&&(o=e.parseHeaders(a[0]),a.length>1&&(s=a[1]))}r.resolve(new n.ConnectionMessage(t.messageType,s,o,t.id))}else if(t.messageType===n.MessageType.Binary){var c=t.binaryContent;if(o={},s=null,!c||c.byteLength<2)throw new Error("Invalid binary message format. Header length missing.");var p=new DataView(c),u=p.getInt16(0);if(c.byteLengthu+2&&(s=c.slice(2+u)),r.resolve(new n.ConnectionMessage(t.messageType,s,o,t.id))}}catch(e){r.reject("Error formatting the message. Error: "+e)}return r.promise()},this.fromConnectionMessage=function(t){var r=new n.Deferred;try{if(t.messageType===n.MessageType.Text){var o=""+e.makeHeaders(t)+i+(t.textBody?t.textBody:"");r.resolve(new n.RawWebsocketMessage(n.MessageType.Text,o,t.id))}else if(t.messageType===n.MessageType.Binary){var s=e.makeHeaders(t),a=t.binaryBody,c=new Int8Array(e.stringToArrayBuffer(s)),p=(o=new ArrayBuffer(2+c.byteLength+(a?a.byteLength:0)),new DataView(o));p.setInt16(0,c.length);for(var u=0;u0?o.substr(0,s).trim().toLowerCase():o,c=s>0&&o.length>s+1?o.substr(s+1).trim():"";t[a]=c}}}return t},this.stringToArrayBuffer=function(e){for(var t=new ArrayBuffer(e.length),r=new DataView(t),n=0;n0&&e.push({PhraseLatencyMs:o.privPhraseLatencies}),o.privHypothesisLatencies.length>0&&e.push({FirstHypothesisLatencyMs:o.privHypothesisLatencies});var t={Metrics:e,ReceivedMessages:o.privReceivedMessages},r=JSON.stringify(t);return o.privReceivedMessages={},o.privListeningTriggerMetric=null,o.privMicMetric=null,o.privConnectionEstablishMetric=null,o.privPhraseLatencies=[],o.privHypothesisLatencies=[],r},this.dispose=function(){o.privIsDisposed=!0},this.getConnectionError=function(e){switch(e){case 400:case 1002:case 1003:case 1005:case 1007:case 1008:case 1009:return"BadRequest";case 401:return"Unauthorized";case 403:return"Forbidden";case 503:case 1001:return"ServerUnavailable";case 500:case 1011:return"ServerError";case 408:case 504:return"Timeout";default:return"statuscode:"+e.toString()}},this.privRequestId=e,this.privAudioSourceId=t,this.privAudioNodeId=r,this.privReceivedMessages={},this.privPhraseLatencies=[],this.privHypothesisLatencies=[]}return e.prototype.phraseReceived=function(e){e>0&&this.privPhraseLatencies.push(Date.now()-e)},e.prototype.hypothesisReceived=function(e){e>0&&this.privHypothesisLatencies.push(Date.now()-e)},Object.defineProperty(e.prototype,"hasTelemetry",{get:function(){return 0!==Object.keys(this.privReceivedMessages).length||null!==this.privListeningTriggerMetric||null!==this.privMicMetric||null!==this.privConnectionEstablishMetric||0!==this.privPhraseLatencies.length||0!==this.privHypothesisLatencies.length},enumerable:!0,configurable:!0}),e}();t.ServiceTelemetryListener=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e){this.privContext={},this.privDynamicGrammar=e}return e.prototype.setSection=function(e,t){this.privContext[e]=t},e.prototype.toJSON=function(){var e=this.privDynamicGrammar.generateGrammarObject();return this.setSection("dgi",e),JSON.stringify(this.privContext)},e}();t.SpeechContext=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(){}return e.prototype.addPhrase=function(e){this.privPhrases||(this.privPhrases=[]),e instanceof Array?this.privPhrases=this.privPhrases.concat(e):this.privPhrases.push(e)},e.prototype.clearPhrases=function(){this.privPhrases=void 0},e.prototype.addReferenceGrammar=function(e){this.privGrammars||(this.privGrammars=[]),e instanceof Array?this.privGrammars=this.privGrammars.concat(e):this.privGrammars.push(e)},e.prototype.clearGrammars=function(){this.privGrammars=void 0},e.prototype.generateGrammarObject=function(){if(void 0!==this.privGrammars||void 0!==this.privPhrases){var e={};if(e.ReferenceGrammars=this.privGrammars,void 0!==this.privPhrases&&0!==this.privPhrases.length){var t=[];this.privPhrases.forEach((function(e,r,n){t.push({Text:e})})),e.Groups=[{Type:"Generic",Items:t}]}return e}},e}();t.DynamicGrammarBuilder=n},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=r(2),s=r(4),a=r(31),c=r(152),p=r(26),u=r(154),f=r(128),h=function(e){function t(t,r,n,i,u){var h=e.call(this,t,r,n,i,u)||this;return h.sendMessage=function(e){var t=s.createGuid(),r=s.createNoDashGuid(),n={context:{interactionId:t},messagePayload:JSON.parse(e),version:.5},i=JSON.stringify(n);h.fetchDialogConnection().onSuccessContinueWith((function(e){e.send(new f.SpeechConnectionMessage(s.MessageType.Text,"agent",r,"application/json",i))}))},h.listenOnce=function(e,t,r){return h.privRecognizerConfig.recognitionMode=e,h.privSuccessCallback=t,h.privErrorCallback=r,h.privDialogRequestSession.startNewRecognition(),h.privDialogRequestSession.listenForServiceTelemetry(h.privDialogAudioSource.events),h.dialogConnectImpl(),h.sendPreAudioMessages(),h.privDialogAudioSource.attach(h.privDialogRequestSession.audioNodeId).continueWithPromise((function(e){var t;return e.isError?(h.cancelRecognition(h.privDialogRequestSession.sessionId,h.privDialogRequestSession.requestId,a.CancellationReason.Error,a.CancellationErrorCode.ConnectionFailure,e.error),s.PromiseHelper.fromError(e.error)):h.privDialogAudioSource.format.onSuccessContinueWithPromise((function(r){return t=new o.ReplayableAudioNode(e.result,r.avgBytesPerSec),h.privDialogRequestSession.onAudioSourceAttachCompleted(t,!1),h.privDialogAudioSource.deviceInfo.onSuccessContinueWithPromise((function(e){return h.privRecognizerConfig.SpeechServiceConfig.Context.audio={source:e},h.configConnection().continueWithPromise((function(e){if(e.isError)return h.cancelRecognitionLocal(a.CancellationReason.Error,a.CancellationErrorCode.ConnectionFailure,e.error),s.PromiseHelper.fromError(e.error);var r=new a.SessionEventArgs(h.privDialogRequestSession.sessionId);return h.privRecognizer.sessionStarted&&h.privRecognizer.sessionStarted(h.privRecognizer,r),h.sendAudio(t).on((function(e){}),(function(e){h.cancelRecognition(h.privDialogRequestSession.sessionId,h.privDialogRequestSession.requestId,a.CancellationReason.Error,a.CancellationErrorCode.RuntimeError,e)})),s.PromiseHelper.fromResult(!0)}))}))}))}))},h.sendAudio=function(e){return h.privDialogAudioSource.format.onSuccessContinueWithPromise((function(t){var r=new s.Deferred,n=Date.now(),i=h.privRecognizerConfig.parameters.getProperty("SPEECH-TransmitLengthBeforThrottleMs","5000"),o=t.avgBytesPerSec/1e3*parseInt(i,10),a=h.privDialogRequestSession.recogNumber,c=function(){h.privDialogIsDisposed||h.privDialogRequestSession.isSpeechEnded||!h.privDialogRequestSession.isRecognizing||h.privDialogRequestSession.recogNumber!==a||h.fetchDialogConnection().on((function(i){e.read().on((function(e){var a,p;h.privDialogRequestSession.isSpeechEnded?r.resolve(!0):(!e||e.isEnd?(a=null,p=0):(a=e.buffer,h.privDialogRequestSession.onAudioSent(a.byteLength),p=o>=h.privDialogRequestSession.bytesSent?0:Math.max(0,n-Date.now())),setTimeout((function(){null!==a&&(n=Date.now()+1e3*a.byteLength/(2*t.avgBytesPerSec));var o=i.send(new f.SpeechConnectionMessage(s.MessageType.Binary,"audio",h.privDialogRequestSession.requestId,null,a));e&&!e.isEnd?o.continueWith((function(e){c()})):(h.privDialogRequestSession.onSpeechEnded(),r.resolve(!0))}),p))}),(function(e){h.privDialogRequestSession.isSpeechEnded?r.resolve(!0):r.reject(e)}))}),(function(e){r.reject(e)}))};return c(),r.promise()}))},h.receiveDialogMessageOverride=function(){var e=new s.Deferred;return h.fetchDialogConnection().on((function(t){return t.read().onSuccessContinueWithPromise((function(t){var r=h.isDisposed(),n=!h.isDisposed()&&h.terminateMessageLoop;if(r||n)return e.resolve(void 0),s.PromiseHelper.fromResult(void 0);if(!t)return h.receiveDialogMessageOverride();var i=f.SpeechConnectionMessage.fromConnectionMessage(t);switch(i.path.toLowerCase()){case"turn.start":var o=i.requestId.toUpperCase();o!==h.privDialogRequestSession.requestId.toUpperCase()?h.privTurnStateManager.StartTurn(o):h.privDialogRequestSession.onServiceTurnStartResponse();break;case"speech.startdetected":var c=p.SpeechDetected.fromJSON(i.textBody),u=new a.RecognitionEventArgs(c.Offset,h.privDialogRequestSession.sessionId);h.privRecognizer.speechStartDetected&&h.privRecognizer.speechStartDetected(h.privRecognizer,u);break;case"speech.enddetected":var v=void 0;v=i.textBody.length>0?i.textBody:"{ Offset: 0 }";var l=p.SpeechDetected.fromJSON(v);h.privDialogRequestSession.onServiceRecognized(l.Offset+h.privDialogRequestSession.currentTurnAudioOffset);var d=new a.RecognitionEventArgs(l.Offset+h.privDialogRequestSession.currentTurnAudioOffset,h.privDialogRequestSession.sessionId);h.privRecognizer.speechEndDetected&&h.privRecognizer.speechEndDetected(h.privRecognizer,d);break;case"turn.end":var g=i.requestId.toUpperCase();if(g!==h.privDialogRequestSession.requestId.toUpperCase())h.privTurnStateManager.CompleteTurn(g);else{var y=new a.SessionEventArgs(h.privDialogRequestSession.sessionId);if(h.privDialogRequestSession.onServiceTurnEndResponse(!1),h.privDialogRequestSession.isSpeechEnded&&h.privRecognizer.sessionStopped&&h.privRecognizer.sessionStopped(h.privRecognizer,y),h.privSuccessCallback&&h.privLastResult){try{h.privSuccessCallback(h.privLastResult),h.privLastResult=null}catch(e){h.privErrorCallback&&h.privErrorCallback(e)}h.privSuccessCallback=void 0,h.privErrorCallback=void 0}}break;default:h.processTypeSpecificMessages(i)||h.serviceEvents&&h.serviceEvents.onEvent(new s.ServiceEvent(i.path.toLowerCase(),i.textBody))}return h.receiveDialogMessageOverride()}))}),(function(t){return h.terminateMessageLoop=!0,e.resolve(void 0),s.PromiseHelper.fromResult(void 0)})),e.promise()},h.fetchDialogConnection=function(){return h.configConnection()},h.sendAgentConfig=function(e){if(h.agentConfig&&!h.agentConfigSent){if("custom_commands"===h.privRecognizerConfig.parameters.getProperty(a.PropertyId.Conversation_DialogType)){var t=h.agentConfig.get();t.botInfo.commandsCulture=h.privRecognizerConfig.parameters.getProperty(a.PropertyId.SpeechServiceConnection_RecoLanguage,"en-us"),h.agentConfig.set(t)}var r=h.agentConfig.toJsonString();return h.agentConfigSent=!0,e.send(new f.SpeechConnectionMessage(s.MessageType.Text,"agent.config",h.privDialogRequestSession.requestId,"application/json",r))}return s.PromiseHelper.fromResult(!0)},h.sendAgentContext=function(e){var t=s.createGuid(),r=h.privDialogServiceConnector.properties.getProperty(a.PropertyId.Conversation_Speech_Activity_Template),n={channelData:"",context:{interactionId:t},messagePayload:void 0===typeof r?void 0:r,version:.5},i=JSON.stringify(n);return e.send(new f.SpeechConnectionMessage(s.MessageType.Text,"speech.agent.context",h.privDialogRequestSession.requestId,"application/json",i))},h.privDialogServiceConnector=u,h.privDialogAuthentication=t,h.receiveMessageOverride=h.receiveDialogMessageOverride,h.privTurnStateManager=new c.DialogServiceTurnStateManager,h.recognizeOverride=h.listenOnce,h.connectImplOverride=h.dialogConnectImpl,h.configConnectionOverride=h.configConnection,h.fetchConnectionOverride=h.fetchDialogConnection,h.disconnectOverride=h.privDisconnect,h.privDialogAudioSource=n,h.privDialogRequestSession=new p.RequestSession(n.id()),h.privDialogConnectionFactory=r,h.privDialogIsDisposed=!1,h.agentConfigSent=!1,h.privLastResult=null,h}return i(t,e),t.prototype.isDisposed=function(){return this.privDialogIsDisposed},t.prototype.dispose=function(e){this.privDialogIsDisposed=!0,this.privConnectionConfigPromise&&this.privConnectionConfigPromise.onSuccessContinueWith((function(t){t.dispose(e)}))},t.prototype.privDisconnect=function(){this.cancelRecognition(this.privDialogRequestSession.sessionId,this.privDialogRequestSession.requestId,a.CancellationReason.Error,a.CancellationErrorCode.NoError,"Disconnecting"),this.terminateMessageLoop=!0,this.agentConfigSent=!1,this.privDialogConnectionPromise.result().isCompleted?this.privDialogConnectionPromise.result().isError||(this.privDialogConnectionPromise.result().result.dispose(),this.privDialogConnectionPromise=null):this.privDialogConnectionPromise.onSuccessContinueWith((function(e){e.dispose()}))},t.prototype.processTypeSpecificMessages=function(e){var t,r,n=new a.PropertyCollection;switch(e.messageType===s.MessageType.Text&&n.setProperty(a.PropertyId.SpeechServiceResponse_JsonResult,e.textBody),e.path.toLowerCase()){case"speech.phrase":var i=p.SimpleSpeechPhrase.fromJSON(e.textBody);if(this.privDialogRequestSession.onPhraseRecognized(this.privDialogRequestSession.currentTurnAudioOffset+i.Offset+i.Duration),i.RecognitionStatus===p.RecognitionStatus.Success){var o=this.fireEventForResult(i,n);if(this.privLastResult=o.result,this.privDialogServiceConnector.recognized)try{this.privDialogServiceConnector.recognized(this.privDialogServiceConnector,o)}catch(e){}}r=!0;break;case"speech.hypothesis":var c=p.SpeechHypothesis.fromJSON(e.textBody),f=c.Offset+this.privDialogRequestSession.currentTurnAudioOffset;t=new a.SpeechRecognitionResult(this.privDialogRequestSession.requestId,a.ResultReason.RecognizingSpeech,c.Text,c.Duration,f,c.Language,c.LanguageDetectionConfidence,void 0,e.textBody,n),this.privDialogRequestSession.onHypothesis(f);var h=new a.SpeechRecognitionEventArgs(t,c.Duration,this.privDialogRequestSession.sessionId);if(this.privDialogServiceConnector.recognizing)try{this.privDialogServiceConnector.recognizing(this.privDialogServiceConnector,h)}catch(e){}r=!0;break;case"audio":var v=e.requestId.toUpperCase(),l=this.privTurnStateManager.GetTurn(v);try{e.binaryBody?l.audioStream.write(e.binaryBody):l.endAudioStream()}catch(e){}r=!0;break;case"response":var d=e.requestId.toUpperCase(),g=u.ActivityPayloadResponse.fromJSON(e.textBody);l=this.privTurnStateManager.GetTurn(d);if(g.conversationId){var y=this.agentConfig.get();y.botInfo.conversationId=g.conversationId,this.agentConfig.set(y)}var m=l.processActivityPayload(g,a.SpeechSynthesisOutputFormat[this.privDialogServiceConnector.properties.getProperty(a.PropertyId.SpeechServiceConnection_SynthOutputFormat,void 0)]),S=new a.ActivityReceivedEventArgs(g.messagePayload,m);if(this.privDialogServiceConnector.activityReceived)try{this.privDialogServiceConnector.activityReceived(this.privDialogServiceConnector,S)}catch(e){}r=!0}return r},t.prototype.cancelRecognition=function(e,t,r,n,i){if(this.terminateMessageLoop=!0,this.privDialogRequestSession.isRecognizing&&this.privDialogRequestSession.onStopRecognizing(),this.privDialogServiceConnector.canceled){var o=new a.PropertyCollection;o.setProperty(p.CancellationErrorCodePropertyName,a.CancellationErrorCode[n]);var s=new a.SpeechRecognitionCanceledEventArgs(r,i,n,void 0,e);try{this.privDialogServiceConnector.canceled(this.privDialogServiceConnector,s)}catch(e){}if(this.privSuccessCallback){var c=new a.SpeechRecognitionResult(void 0,a.ResultReason.Canceled,void 0,void 0,void 0,void 0,void 0,i,void 0,o);try{this.privSuccessCallback(c),this.privSuccessCallback=void 0}catch(e){}}}},t.prototype.sendWaveHeader=function(e){var t=this;return this.audioSource.format.onSuccessContinueWithPromise((function(r){return e.send(new f.SpeechConnectionMessage(s.MessageType.Binary,"audio",t.privDialogRequestSession.requestId,"audio/x-wav",r.header))}))},t.prototype.dialogConnectImpl=function(e){var t=this;if(void 0===e&&(e=!1),this.privDialogConnectionPromise)return this.privDialogConnectionPromise.result().isCompleted&&(this.privDialogConnectionPromise.result().isError||this.privDialogConnectionPromise.result().result.state()===s.ConnectionState.Disconnected)?(this.agentConfigSent=!1,this.privDialogConnectionPromise=null,this.terminateMessageLoop=!0,this.configConnection()):this.privDialogConnectionPromise;this.privDialogAuthFetchEventId=s.createNoDashGuid(),void 0===this.privConnectionId&&(this.privConnectionId=s.createNoDashGuid()),this.privDialogRequestSession.onPreConnectionStart(this.privDialogAuthFetchEventId,this.privConnectionId);var r=e?this.privDialogAuthentication.fetchOnExpiry(this.privDialogAuthFetchEventId):this.privDialogAuthentication.fetch(this.privDialogAuthFetchEventId);return this.privDialogConnectionPromise=r.continueWithPromise((function(r){if(r.isError)throw t.privDialogRequestSession.onAuthCompleted(!0,r.error),new Error(r.error);t.privDialogRequestSession.onAuthCompleted(!1);var n=t.privDialogConnectionFactory.create(t.privRecognizerConfig,r.result,t.privConnectionId);return t.privDialogRequestSession.listenForServiceTelemetry(n.events),n.events.attach((function(e){t.connectionEvents.onEvent(e)})),n.open().onSuccessContinueWithPromise((function(r){return 200===r.statusCode?(t.privDialogRequestSession.onPreConnectionStart(t.privDialogAuthFetchEventId,t.privConnectionId),t.privDialogRequestSession.onConnectionEstablishCompleted(r.statusCode),s.PromiseHelper.fromResult(n)):403!==r.statusCode||e?(t.privDialogRequestSession.onConnectionEstablishCompleted(r.statusCode,r.reason),s.PromiseHelper.fromError("Unable to contact server. StatusCode: "+r.statusCode+", "+t.privRecognizerConfig.parameters.getProperty(a.PropertyId.SpeechServiceConnection_Endpoint)+" Reason: "+r.reason)):t.dialogConnectImpl(!0)}))})),this.privConnectionLoop=this.startMessageLoop(),this.privDialogConnectionPromise},t.prototype.startMessageLoop=function(){var e=this;return this.terminateMessageLoop=!1,this.receiveDialogMessageOverride().on((function(e){return!0}),(function(t){e.cancelRecognition(e.privDialogRequestSession.sessionId,e.privDialogRequestSession.requestId,a.CancellationReason.Error,a.CancellationErrorCode.RuntimeError,t)}))},t.prototype.configConnection=function(){var e=this;return this.privConnectionConfigPromise?this.privConnectionConfigPromise.result().isCompleted&&(this.privConnectionConfigPromise.result().isError||this.privConnectionConfigPromise.result().result.state()===s.ConnectionState.Disconnected)?(this.privConnectionConfigPromise=null,this.configConnection()):this.privConnectionConfigPromise:this.terminateMessageLoop?(this.terminateMessageLoop=!1,s.PromiseHelper.fromError("Connection to service terminated.")):(this.privConnectionConfigPromise=this.dialogConnectImpl().onSuccessContinueWithPromise((function(t){return e.sendSpeechServiceConfig(t,e.privDialogRequestSession,e.privRecognizerConfig.SpeechServiceConfig.serialize()).onSuccessContinueWithPromise((function(r){return e.sendAgentConfig(t).onSuccessContinueWith((function(e){return t}))}))})),this.privConnectionConfigPromise)},t.prototype.sendPreAudioMessages=function(){var e=this;this.fetchDialogConnection().onSuccessContinueWith((function(t){e.sendAgentContext(t),e.sendWaveHeader(t)}))},t.prototype.fireEventForResult=function(e,t){var r=p.EnumTranslation.implTranslateRecognitionResult(e.RecognitionStatus),n=e.Offset+this.privDialogRequestSession.currentTurnAudioOffset,i=new a.SpeechRecognitionResult(this.privDialogRequestSession.requestId,r,e.DisplayText,e.Duration,n,e.Language,e.LanguageDetectionConfidence,void 0,JSON.stringify(e),t);return new a.SpeechRecognitionEventArgs(i,n,this.privDialogRequestSession.sessionId)},t}(p.ServiceRecognizerBase);t.DialogServiceAdapter=h},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(10),i=r(153),o=function(){function e(){this.privTurnMap=new Map}return e.prototype.StartTurn=function(e){if(this.privTurnMap.has(e))throw new n.InvalidOperationError("Service error: There is already a turn with id:"+e);var t=new i.DialogServiceTurnState(this,e);return this.privTurnMap.set(e,t),this.privTurnMap.get(e)},e.prototype.GetTurn=function(e){return this.privTurnMap.get(e)},e.prototype.CompleteTurn=function(e){if(!this.privTurnMap.has(e))throw new n.InvalidOperationError("Service error: Received turn end for an unknown turn id:"+e);var t=this.privTurnMap.get(e);return t.complete(),this.privTurnMap.delete(e),t},e}();t.DialogServiceTurnStateManager=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(44),i=r(43),o=r(154),s=function(){function e(e,t){this.privRequestId=t,this.privIsCompleted=!1,this.privAudioStream=null,this.privTurnManager=e,this.resetTurnEndTimeout()}return Object.defineProperty(e.prototype,"audioStream",{get:function(){return this.resetTurnEndTimeout(),this.privAudioStream},enumerable:!0,configurable:!0}),e.prototype.processActivityPayload=function(e,t){return e.messageDataStreamType===o.MessageDataStreamType.TextToSpeechAudio&&(this.privAudioStream=i.AudioOutputStream.createPullStream(),this.privAudioStream.format=void 0!==t?t:n.AudioOutputFormatImpl.getDefaultOutputFormat()),this.privAudioStream},e.prototype.endAudioStream=function(){null===this.privAudioStream||this.privAudioStream.isClosed||this.privAudioStream.close()},e.prototype.complete=function(){void 0!==this.privTimeoutToken&&clearTimeout(this.privTimeoutToken),this.endAudioStream()},e.prototype.resetTurnEndTimeout=function(){var e=this;void 0!==this.privTimeoutToken&&clearTimeout(this.privTimeoutToken),this.privTimeoutToken=setTimeout((function(){e.privTurnManager.CompleteTurn(e.privRequestId)}),2e3)},e}();t.DialogServiceTurnState=s},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e){this.privActivityResponse=JSON.parse(e)}return e.fromJSON=function(t){return new e(t)},Object.defineProperty(e.prototype,"conversationId",{get:function(){return this.privActivityResponse.conversationId},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"messageDataStreamType",{get:function(){return this.privActivityResponse.messageDataStreamType},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"messagePayload",{get:function(){return this.privActivityResponse.messagePayload},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"version",{get:function(){return this.privActivityResponse.version},enumerable:!0,configurable:!0}),e}();t.ActivityPayloadResponse=n,function(e){e[e.None=0]="None",e[e.TextToSpeechAudio=1]="TextToSpeechAudio"}(t.MessageDataStreamType||(t.MessageDataStreamType={}))},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(){}return e.prototype.toJsonString=function(){return JSON.stringify(this.iPrivConfig)},e.prototype.get=function(){return this.iPrivConfig},e.prototype.set=function(e){this.iPrivConfig=e},e}();t.AgentConfig=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(157);t.ConversationManager=n.ConversationManager;var i=r(161);t.ConversationTranslatorRecognizer=i.ConversationTranslatorRecognizer;var o=r(158);t.ConversationConnectionConfig=o.ConversationConnectionConfig;var s=r(167);t.ConversationReceivedTranslationEventArgs=s.ConversationReceivedTranslationEventArgs,t.LockRoomEventArgs=s.LockRoomEventArgs,t.MuteAllEventArgs=s.MuteAllEventArgs,t.ParticipantAttributeEventArgs=s.ParticipantAttributeEventArgs,t.ParticipantEventArgs=s.ParticipantEventArgs,t.ParticipantsListEventArgs=s.ParticipantsListEventArgs;var a=r(168);t.ConversationTranslatorCommandTypes=a.ConversationTranslatorCommandTypes,t.ConversationTranslatorMessageTypes=a.ConversationTranslatorMessageTypes,t.InternalParticipants=a.InternalParticipants},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(33),i=r(31),o=r(158),s=r(160),a=function(){function e(){this.privRequestParams=o.ConversationConnectionConfig.configParams,this.privErrors=o.ConversationConnectionConfig.restErrors,this.privHost=o.ConversationConnectionConfig.host,this.privApiVersion=o.ConversationConnectionConfig.apiVersion,this.privRestPath=o.ConversationConnectionConfig.restPath}return e.prototype.createOrJoin=function(e,t,r,a){var c=this;try{n.Contracts.throwIfNullOrUndefined(e,"args");var p=e.getProperty(i.PropertyId.SpeechServiceConnection_RecoLanguage,o.ConversationConnectionConfig.defaultLanguageCode),u=e.getProperty(i.PropertyId.ConversationTranslator_Name),f=e.getProperty(i.PropertyId.ConversationTranslator_Host,this.privHost),h=e.getProperty(i.PropertyId.ConversationTranslator_CorrelationId),v=e.getProperty(i.PropertyId.SpeechServiceConnection_Key),l=e.getProperty(i.PropertyId.SpeechServiceConnection_Region),d=e.getProperty(i.PropertyId.SpeechServiceAuthorization_Token);n.Contracts.throwIfNullOrWhitespace(p,"languageCode"),n.Contracts.throwIfNullOrWhitespace(u,"nickname"),n.Contracts.throwIfNullOrWhitespace(f,"endpointHost");var g={};g[this.privRequestParams.apiVersion]=this.privApiVersion,g[this.privRequestParams.languageCode]=p,g[this.privRequestParams.nickname]=u;var y={};h&&(y[this.privRequestParams.correlationId]=h),y[this.privRequestParams.clientAppId]=o.ConversationConnectionConfig.clientAppId,void 0!==t?g[this.privRequestParams.roomId]=t:(n.Contracts.throwIfNullOrUndefined(l,this.privErrors.authInvalidSubscriptionRegion),y[this.privRequestParams.subscriptionRegion]=l,v?y[this.privRequestParams.subscriptionKey]=v:d?y[this.privRequestParams.authorization]="Bearer "+d:n.Contracts.throwIfNullOrUndefined(v,this.privErrors.authInvalidSubscriptionKey));var m={};m.headers=y;var S="https://"+f+this.privRestPath;s.request("post",S,g,null,m,(function(e){var t=s.extractHeaderValue(c.privRequestParams.requestId,e.headers);if(e.ok){var n=JSON.parse(e.data);if(n&&(n.requestId=t),r){try{r(n)}catch(e){a&&a(e)}r=void 0}}else if(a){var i=c.privErrors.invalidCreateJoinConversationResponse.replace("{status}",e.status.toString()),o=void 0;try{i+=" ["+(o=JSON.parse(e.data)).error.code+": "+o.error.message+"]"}catch(t){i+=" ["+e.data+"]"}t&&(i+=" "+t),a(i)}}))}catch(e){if(a)if(e instanceof Error){var C=e;a(C.name+": "+C.message)}else a(e)}},e.prototype.leave=function(e,t,r,o){try{n.Contracts.throwIfNullOrUndefined(e,this.privErrors.invalidArgs.replace("{arg}","config")),n.Contracts.throwIfNullOrWhitespace(t,this.privErrors.invalidArgs.replace("{arg}","token"));var a=e.getProperty(i.PropertyId.ConversationTranslator_Host,this.privHost),c=e.getProperty(i.PropertyId.ConversationTranslator_CorrelationId),p={};p[this.privRequestParams.apiVersion]=this.privApiVersion,p[this.privRequestParams.sessionToken]=t;var u={};c&&(u[this.privRequestParams.correlationId]=c);var f={};f.headers=u;var h="https://"+a+this.privRestPath;s.request("delete",h,p,null,f,(function(e){if(e.ok,r){try{r()}catch(e){o&&o(e)}r=void 0}}))}catch(e){if(o)if(e instanceof Error){var v=e;o(v.name+": "+v.message)}else o(e)}},e}();t.ConversationManager=a},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),Object.defineProperty(t,"host",{get:function(){return t.privHost},enumerable:!0,configurable:!0}),Object.defineProperty(t,"apiVersion",{get:function(){return t.privApiVersion},enumerable:!0,configurable:!0}),Object.defineProperty(t,"clientAppId",{get:function(){return t.privClientAppId},enumerable:!0,configurable:!0}),Object.defineProperty(t,"defaultLanguageCode",{get:function(){return t.privDefaultLanguageCode},enumerable:!0,configurable:!0}),Object.defineProperty(t,"restPath",{get:function(){return t.privRestPath},enumerable:!0,configurable:!0}),Object.defineProperty(t,"webSocketPath",{get:function(){return t.privWebSocketPath},enumerable:!0,configurable:!0}),Object.defineProperty(t,"speechHost",{get:function(){return t.privSpeechHost},enumerable:!0,configurable:!0}),Object.defineProperty(t,"speechPath",{get:function(){return t.privSpeechPath},enumerable:!0,configurable:!0}),t.privHost="dev.microsofttranslator.com",t.privRestPath="/capito/room",t.privApiVersion="2.0",t.privDefaultLanguageCode="en-US",t.privClientAppId="FC539C22-1767-4F1F-84BC-B4D811114F15",t.privWebSocketPath="/capito/translate",t.privSpeechHost="{region}.s2s.speech.microsoft.com",t.privSpeechPath="/speech/translation/cognitiveservices/v1",t}(r(159).RestConfigBase);t.ConversationConnectionConfig=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(){}return Object.defineProperty(e,"requestOptions",{get:function(){return e.privDefaultRequestOptions},enumerable:!0,configurable:!0}),Object.defineProperty(e,"configParams",{get:function(){return e.privDefaultParams},enumerable:!0,configurable:!0}),Object.defineProperty(e,"restErrors",{get:function(){return e.privRestErrors},enumerable:!0,configurable:!0}),e.privDefaultRequestOptions={headers:{Accept:"application/json"},ignoreCache:!1,timeout:1e4},e.privRestErrors={authInvalidSubscriptionKey:"You must specify either an authentication token to use, or a Cognitive Speech subscription key.",authInvalidSubscriptionRegion:"You must specify the Cognitive Speech region to use.",invalidArgs:"Required input not found: {arg}.",invalidCreateJoinConversationResponse:"Creating/Joining conversation failed with HTTP {status}.",invalidParticipantRequest:"The requested participant was not found.",permissionDeniedConnect:"Required credentials not found.",permissionDeniedConversation:"Invalid operation: only the host can {command} the conversation.",permissionDeniedParticipant:"Invalid operation: only the host can {command} a participant.",permissionDeniedSend:"Invalid operation: the conversation is not in a connected state.",permissionDeniedStart:"Invalid operation: there is already an active conversation."},e.privDefaultParams={apiVersion:"api-version",authorization:"Authorization",clientAppId:"X-ClientAppId",contentTypeKey:"Content-Type",correlationId:"X-CorrelationId",languageCode:"language",nickname:"nickname",profanity:"profanity",requestId:"X-RequestId",roomId:"roomid",sessionToken:"token",subscriptionKey:"Ocp-Apim-Subscription-Key",subscriptionRegion:"Ocp-Apim-Subscription-Region",token:"X-CapitoToken"},e}();t.RestConfigBase=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(159);function i(e,t){void 0===t&&(t={});var r=function(e){return void 0===e&&(e={}),Object.keys(e).map((function(t){return encodeURIComponent(t)+"="+encodeURIComponent(e[t])})).join("&")}(t);return r?e+(-1===e.indexOf("?")?"?":"&")+r:e}function o(e,t){return void 0===t&&(t=null),{data:t||e.statusText,headers:e.getAllResponseHeaders(),json:function(){return JSON.parse(t||'"'+e.statusText+'"')},ok:!1,status:e.status,statusText:e.statusText}}t.extractHeaderValue=function(e,t){var r="";try{var n=t.trim().split(/[\r\n]+/),i={};n.forEach((function(e){var t=e.split(": "),r=t.shift().toLowerCase(),n=t.join(": ");i[r]=n})),r=i[e.toLowerCase()]}catch(e){}return r},t.request=function(e,t,r,s,a,c){void 0===r&&(r={}),void 0===s&&(s=null),void 0===a&&(a={});var p=n.RestConfigBase.requestOptions,u=a.ignoreCache||p.ignoreCache,f=a.headers||p.headers,h=a.timeout||p.timeout,v=new XMLHttpRequest;v.open(e,i(t,r),!0),f&&Object.keys(f).forEach((function(e){return v.setRequestHeader(e,f[e])})),u&&v.setRequestHeader("Cache-Control","no-cache"),v.timeout=h,v.onload=function(e){c(function(e){return{data:e.responseText,headers:e.getAllResponseHeaders(),json:function(){return JSON.parse(e.responseText)},ok:e.status>=200&&e.status<300,status:e.status,statusText:e.statusText}}(v))},v.onerror=function(e){c(o(v,"Failed to make request."))},v.ontimeout=function(e){c(o(v,"Request took longer than expected."))},"post"===e&&s?(v.setRequestHeader("Content-Type","application/json"),v.send(JSON.stringify(s))):v.send()},t.PromiseToEmptyCallback=function(e,t,r){e?e.continueWith((function(e){try{e.isError?r&&r(e.error):t&&t()}catch(t){r&&r("'Unhandled error on promise callback: "+t+". InnerError: "+e.error+"'")}})):r&&r("Null promise")}},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=r(26),s=r(33),a=r(31),c=r(162),p=r(165),u=r(168),f=r(160),h=function(e){function t(t,r){var n=this,i=t;return s.Contracts.throwIfNull(i,"speechConfig"),(n=e.call(this,r,i.properties,new c.ConversationConnectionFactory)||this).privIsDisposed=!1,n.privProperties=i.properties.clone(),n}return i(t,e),Object.defineProperty(t.prototype,"conversation",{set:function(e){this.privRoom=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"speechRecognitionLanguage",{get:function(){return this.privSpeechRecognitionLanguage},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"properties",{get:function(){return this.privProperties},enumerable:!0,configurable:!0}),t.prototype.isDisposed=function(){return this.privIsDisposed},t.prototype.connect=function(e,t,r){try{s.Contracts.throwIfDisposed(this.privIsDisposed),s.Contracts.throwIfNullOrWhitespace(e,"token"),this.privReco.conversationTranslatorToken=e,this.privReco.connectAsync(t,r)}catch(e){if(r)if(e instanceof Error){var n=e;r(n.name+": "+n.message)}else r(e)}},t.prototype.disconnect=function(e,t){try{s.Contracts.throwIfDisposed(this.privIsDisposed),this.privRoom=void 0,this.privReco.disconnectAsync(e,t)}catch(e){if(t)if(e instanceof Error){var r=e;t(r.name+": "+r.message)}else t(e);this.dispose(!0)}},t.prototype.sendMessageRequest=function(e,t,r){try{s.Contracts.throwIfDisposed(this.privIsDisposed),s.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId,"conversationId"),s.Contracts.throwIfNullOrWhitespace(this.privRoom.participantId,"participantId"),s.Contracts.throwIfNullOrWhitespace(e,"message");var n={participantId:this.privRoom.participantId,roomId:this.privRoom.roomId,text:e,type:u.ConversationTranslatorMessageTypes.instantMessage};this.sendMessage(JSON.stringify(n),t,r)}catch(e){if(r)if(e instanceof Error){var i=e;r(i.name+": "+i.message)}else r(e);this.dispose(!0)}},t.prototype.sendLockRequest=function(e,t,r){try{s.Contracts.throwIfDisposed(this.privIsDisposed),s.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId,"conversationId"),s.Contracts.throwIfNullOrWhitespace(this.privRoom.participantId,"participantId"),s.Contracts.throwIfNullOrUndefined(e,"isLocked");var n={command:u.ConversationTranslatorCommandTypes.setLockState,participantId:this.privRoom.participantId,roomid:this.privRoom.roomId,type:u.ConversationTranslatorMessageTypes.participantCommand,value:e};this.sendMessage(JSON.stringify(n),t,r)}catch(e){if(r)if(e instanceof Error){var i=e;r(i.name+": "+i.message)}else r(e);this.dispose(!0)}},t.prototype.sendMuteAllRequest=function(e,t,r){try{s.Contracts.throwIfDisposed(this.privIsDisposed),s.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId,"conversationId"),s.Contracts.throwIfNullOrWhitespace(this.privRoom.participantId,"participantId"),s.Contracts.throwIfNullOrUndefined(e,"isMuted");var n={command:u.ConversationTranslatorCommandTypes.setMuteAll,participantId:this.privRoom.participantId,roomid:this.privRoom.roomId,type:u.ConversationTranslatorMessageTypes.participantCommand,value:e};this.sendMessage(JSON.stringify(n),t,r)}catch(e){if(r)if(e instanceof Error){var i=e;r(i.name+": "+i.message)}else r(e);this.dispose(!0)}},t.prototype.sendMuteRequest=function(e,t,r,n){try{s.Contracts.throwIfDisposed(this.privIsDisposed),s.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId,"conversationId"),s.Contracts.throwIfNullOrWhitespace(e,"participantId"),s.Contracts.throwIfNullOrUndefined(t,"isMuted");var i={command:u.ConversationTranslatorCommandTypes.setMute,participantId:e,roomid:this.privRoom.roomId,type:u.ConversationTranslatorMessageTypes.participantCommand,value:t};this.sendMessage(JSON.stringify(i),r,n)}catch(e){if(n)if(e instanceof Error){var o=e;n(o.name+": "+o.message)}else n(e);this.dispose(!0)}},t.prototype.sendEjectRequest=function(e,t,r){try{s.Contracts.throwIfDisposed(this.privIsDisposed),s.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId,"conversationId"),s.Contracts.throwIfNullOrWhitespace(e,"participantId");var n={command:u.ConversationTranslatorCommandTypes.ejectParticipant,participantId:e,roomid:this.privRoom.roomId,type:u.ConversationTranslatorMessageTypes.participantCommand};if(this.sendMessage(JSON.stringify(n),t,r),t)try{t()}catch(e){r&&r(e)}}catch(e){if(r)if(e instanceof Error){var i=e;r(i.name+": "+i.message)}else r(e);this.dispose(!0)}},t.prototype.sendChangeNicknameRequest=function(e,t,r){try{s.Contracts.throwIfDisposed(this.privIsDisposed),s.Contracts.throwIfNullOrWhitespace(this.privRoom.roomId,"conversationId"),s.Contracts.throwIfNullOrWhitespace(e,"nickname");var n={command:u.ConversationTranslatorCommandTypes.changeNickname,nickname:e,participantId:this.privRoom.participantId,roomid:this.privRoom.roomId,type:u.ConversationTranslatorMessageTypes.participantCommand,value:e};this.sendMessage(JSON.stringify(n),t,r)}catch(e){if(r)if(e instanceof Error){var i=e;r(i.name+": "+i.message)}else r(e);this.dispose(!0)}},t.prototype.close=function(){s.Contracts.throwIfDisposed(this.privIsDisposed),this.dispose(!0)},t.prototype.dispose=function(t){this.privIsDisposed||t&&(this.privIsDisposed=!0,e.prototype.dispose.call(this,t))},t.prototype.createRecognizerConfig=function(e){return new o.RecognizerConfig(e,this.privProperties)},t.prototype.createServiceRecognizer=function(e,t,r,n){var i=r;return new p.ConversationServiceAdapter(e,t,i,n,this)},t.prototype.sendMessage=function(e,t,r){var n=this.privReco;f.PromiseToEmptyCallback(n.sendMessageAsync(e),t,r)},t}(a.Recognizer);t.ConversationTranslatorRecognizer=h},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=r(2),s=r(4),a=r(33),c=r(31),p=r(72),u=r(158),f=r(163),h=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t.prototype.create=function(e,t,r){var n=e.parameters.getProperty(c.PropertyId.ConversationTranslator_Host,u.ConversationConnectionConfig.host),i=e.parameters.getProperty(c.PropertyId.ConversationTranslator_CorrelationId,s.createGuid()),p="wss://"+n+u.ConversationConnectionConfig.webSocketPath,h=e.parameters.getProperty(c.PropertyId.ConversationTranslator_Token,void 0);a.Contracts.throwIfNullOrUndefined(h,"token");var v={};return v[u.ConversationConnectionConfig.configParams.apiVersion]=u.ConversationConnectionConfig.apiVersion,v[u.ConversationConnectionConfig.configParams.token]=h,v[u.ConversationConnectionConfig.configParams.correlationId]=i,new o.WebsocketConnection(p,v,{},new f.ConversationWebsocketMessageFormatter,o.ProxyInfo.fromRecognizerConfig(e),r)},t}(p.ConnectionFactoryBase);t.ConversationConnectionFactory=h},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(4),i=r(164),o=function(){this.toConnectionMessage=function(e){var t=new n.Deferred;try{if(e.messageType===n.MessageType.Text){var r=new i.ConversationConnectionMessage(e.messageType,e.textContent,{},e.id);t.resolve(r)}else e.messageType===n.MessageType.Binary&&t.resolve(new i.ConversationConnectionMessage(e.messageType,e.binaryContent,void 0,e.id))}catch(e){t.reject("Error formatting the message. Error: "+e)}return t.promise()},this.fromConnectionMessage=function(e){var t=new n.Deferred;try{if(e.messageType===n.MessageType.Text){var r=""+(e.textBody?e.textBody:"");t.resolve(new n.RawWebsocketMessage(n.MessageType.Text,r,e.id))}}catch(e){t.reject("Error formatting the message. "+e)}return t.promise()}};t.ConversationWebsocketMessageFormatter=o},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=function(e){function t(t,r,n,i){var o=e.call(this,t,r,n,i)||this,s=JSON.parse(o.textBody);return void 0!==s.type&&(o.privConversationMessageType=s.type),o}return i(t,e),Object.defineProperty(t.prototype,"conversationMessageType",{get:function(){return this.privConversationMessageType},enumerable:!0,configurable:!0}),t}(r(4).ConnectionMessage);t.ConversationConnectionMessage=o},function(e,t,r){"use strict";var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0});var o=r(4),s=r(16),a=r(31),c=r(26),p=r(164),u=r(166),f=r(167),h=r(168),v=r(169),l=function(e){function t(t,r,n,i,c){var l=e.call(this,t,r,n,i,c)||this;return l.privLastPartialUtteranceId="",l.sendMessageAsync=function(e){var t=new s.Sink;return l.fetchConversationConnection().continueWith((function(r){try{r.isError?t.reject(r.error):r.result.send(new p.ConversationConnectionMessage(o.MessageType.Text,e)).continueWith((function(e){try{e.isError?t.reject(e.error):t.resolve(e.result)}catch(e){t.reject("Unhandled inner error: "+e)}}))}catch(e){t.reject("Unhandled error: "+e)}})),new o.Promise(t)},l.noOp=function(){},l.receiveConversationMessageOverride=function(e,t){var r=new o.Deferred;return l.fetchConversationConnection().on((function(e){return e.read().onSuccessContinueWithPromise((function(e){var t=l.isDisposed(),n=!l.isDisposed()&&l.terminateMessageLoop,i=l.privConversationRequestSession.sessionId,s=!1;if(t||n)return r.resolve(void 0),o.PromiseHelper.fromResult(void 0);if(!e)return l.receiveConversationMessageOverride();try{switch(e.conversationMessageType.toLowerCase()){case"info":case"participant_command":case"command":var c=v.CommandResponsePayload.fromJSON(e.textBody);switch(c.command.toLowerCase()){case"participantlist":var p=v.ParticipantsListPayloadResponse.fromJSON(e.textBody),u=p.participants.map((function(e){return{avatar:e.avatar,displayName:e.nickname,id:e.participantId,isHost:e.ishost,isMuted:e.ismuted,isUsingTts:e.usetts,preferredLanguage:e.locale}}));l.privConversationServiceConnector.participantsListReceived&&l.privConversationServiceConnector.participantsListReceived(l.privConversationServiceConnector,new f.ParticipantsListEventArgs(p.roomid,p.token,p.translateTo,p.profanityFilter,p.roomProfanityFilter,p.roomLocked,p.muteAll,u,i));break;case"settranslatetolanguages":l.privConversationServiceConnector.participantUpdateCommandReceived&&l.privConversationServiceConnector.participantUpdateCommandReceived(l.privConversationServiceConnector,new f.ParticipantAttributeEventArgs(c.participantId,h.ConversationTranslatorCommandTypes.setTranslateToLanguages,c.value,i));break;case"setprofanityfiltering":l.privConversationServiceConnector.participantUpdateCommandReceived&&l.privConversationServiceConnector.participantUpdateCommandReceived(l.privConversationServiceConnector,new f.ParticipantAttributeEventArgs(c.participantId,h.ConversationTranslatorCommandTypes.setProfanityFiltering,c.value,i));break;case"setmute":l.privConversationServiceConnector.participantUpdateCommandReceived&&l.privConversationServiceConnector.participantUpdateCommandReceived(l.privConversationServiceConnector,new f.ParticipantAttributeEventArgs(c.participantId,h.ConversationTranslatorCommandTypes.setMute,c.value,i));break;case"setmuteall":l.privConversationServiceConnector.muteAllCommandReceived&&l.privConversationServiceConnector.muteAllCommandReceived(l.privConversationServiceConnector,new f.MuteAllEventArgs(c.value,i));break;case"roomexpirationwarning":l.privConversationServiceConnector.conversationExpiration&&l.privConversationServiceConnector.conversationExpiration(l.privConversationServiceConnector,new a.ConversationExpirationEventArgs(c.value,l.privConversationRequestSession.sessionId));break;case"setusetts":l.privConversationServiceConnector.participantUpdateCommandReceived&&l.privConversationServiceConnector.participantUpdateCommandReceived(l.privConversationServiceConnector,new f.ParticipantAttributeEventArgs(c.participantId,h.ConversationTranslatorCommandTypes.setUseTTS,c.value,i));break;case"setlockstate":l.privConversationServiceConnector.lockRoomCommandReceived&&l.privConversationServiceConnector.lockRoomCommandReceived(l.privConversationServiceConnector,new f.LockRoomEventArgs(c.value,i));break;case"changenickname":l.privConversationServiceConnector.participantUpdateCommandReceived&&l.privConversationServiceConnector.participantUpdateCommandReceived(l.privConversationServiceConnector,new f.ParticipantAttributeEventArgs(c.participantId,h.ConversationTranslatorCommandTypes.changeNickname,c.nickname,i));break;case"joinsession":var d=v.ParticipantPayloadResponse.fromJSON(e.textBody),g={avatar:d.avatar,displayName:d.nickname,id:d.participantId,isHost:d.ishost,isMuted:d.ismuted,isUsingTts:d.usetts,preferredLanguage:d.locale};l.privConversationServiceConnector.participantJoinCommandReceived&&l.privConversationServiceConnector.participantJoinCommandReceived(l.privConversationServiceConnector,new f.ParticipantEventArgs(g,i));break;case"leavesession":var y={id:c.participantId};l.privConversationServiceConnector.participantLeaveCommandReceived&&l.privConversationServiceConnector.participantLeaveCommandReceived(l.privConversationServiceConnector,new f.ParticipantEventArgs(y,i));break;case"disconnectsession":c.participantId}break;case"partial":case"final":var m=v.SpeechResponsePayload.fromJSON(e.textBody),S=new a.ConversationTranslationResult(m.participantId,l.getTranslations(m.translations),m.language,void 0,void 0,m.recognition,void 0,void 0,e.textBody,void 0);m.isFinal?(void 0!==S.text&&S.text.length>0?s=!0:m.id===l.privLastPartialUtteranceId&&(s=!0),s&&l.privConversationServiceConnector.translationReceived&&l.privConversationServiceConnector.translationReceived(l.privConversationServiceConnector,new f.ConversationReceivedTranslationEventArgs(h.ConversationTranslatorMessageTypes.final,S,i))):void 0!==S.text&&(l.privLastPartialUtteranceId=m.id,l.privConversationServiceConnector.translationReceived&&l.privConversationServiceConnector.translationReceived(l.privConversationServiceConnector,new f.ConversationReceivedTranslationEventArgs(h.ConversationTranslatorMessageTypes.partial,S,i)));break;case"translated_message":var C=v.TextResponsePayload.fromJSON(e.textBody),P=new a.ConversationTranslationResult(C.participantId,l.getTranslations(C.translations),C.language,void 0,void 0,C.originalText,void 0,void 0,void 0,e.textBody,void 0);l.privConversationServiceConnector.translationReceived&&l.privConversationServiceConnector.translationReceived(l.privConversationServiceConnector,new f.ConversationReceivedTranslationEventArgs(h.ConversationTranslatorMessageTypes.instantMessage,P,i))}}catch(e){}return l.receiveConversationMessageOverride()}))}),(function(e){l.terminateMessageLoop=!0})),r.promise()},l.fetchConversationConnection=function(){return l.configConnection()},l.privConversationServiceConnector=c,l.privConversationAuthentication=t,l.receiveMessageOverride=l.receiveConversationMessageOverride,l.recognizeOverride=l.noOp,l.connectImplOverride=l.conversationConnectImpl,l.configConnectionOverride=l.configConnection,l.fetchConnectionOverride=l.fetchConversationConnection,l.disconnectOverride=l.privDisconnect,l.privConversationRequestSession=new u.ConversationRequestSession(o.createNoDashGuid()),l.privConversationConnectionFactory=r,l.privConversationIsDisposed=!1,l}return i(t,e),t.prototype.isDisposed=function(){return this.privConversationIsDisposed},t.prototype.dispose=function(e){this.privConversationIsDisposed=!0,this.privConnectionConfigPromise&&this.privConnectionConfigPromise.onSuccessContinueWith((function(t){t.dispose(e)}))},t.prototype.sendMessage=function(e){this.fetchConversationConnection().onSuccessContinueWith((function(t){t.send(new p.ConversationConnectionMessage(o.MessageType.Text,e))}))},t.prototype.privDisconnect=function(){this.terminateMessageLoop||(this.cancelRecognition(this.privConversationRequestSession.sessionId,this.privConversationRequestSession.requestId,a.CancellationReason.Error,a.CancellationErrorCode.NoError,"Disconnecting"),this.terminateMessageLoop=!0,this.privConversationConnectionPromise.result().isCompleted?this.privConversationConnectionPromise.result().isError||(this.privConversationConnectionPromise.result().result.dispose(),this.privConversationConnectionPromise=null):this.privConversationConnectionPromise.onSuccessContinueWith((function(e){e.dispose()})))},t.prototype.processTypeSpecificMessages=function(e,t,r){return!0},t.prototype.cancelRecognition=function(e,t,r,n,i){this.terminateMessageLoop=!0;var o=new a.ConversationTranslationCanceledEventArgs(r,i,n,void 0,e);try{this.privConversationServiceConnector.canceled&&this.privConversationServiceConnector.canceled(this.privConversationServiceConnector,o)}catch(e){}},t.prototype.conversationConnectImpl=function(e){var t=this;if(void 0===e&&(e=!1),this.privConversationConnectionPromise)return this.privConversationConnectionPromise.result().isCompleted&&(this.privConversationConnectionPromise.result().isError||this.privConversationConnectionPromise.result().result.state()===o.ConnectionState.Disconnected)?(this.privConnectionId=null,this.privConversationConnectionPromise=null,this.terminateMessageLoop=!0,this.conversationConnectImpl()):this.privConversationConnectionPromise;this.privConversationAuthFetchEventId=o.createNoDashGuid(),void 0===this.privConnectionId&&(this.privConnectionId=o.createNoDashGuid()),this.privConversationRequestSession.onPreConnectionStart(this.privConversationAuthFetchEventId,this.privConnectionId);var r=e?this.privConversationAuthentication.fetchOnExpiry(this.privConversationAuthFetchEventId):this.privConversationAuthentication.fetch(this.privConversationAuthFetchEventId);return this.privConversationConnectionPromise=r.continueWithPromise((function(r){if(r.isError)throw t.privConversationRequestSession.onAuthCompleted(!0,r.error),new Error(r.error);t.privConversationRequestSession.onAuthCompleted(!1);var n=t.privConversationConnectionFactory.create(t.privRecognizerConfig,r.result,t.privConnectionId);return n.events.attach((function(e){t.connectionEvents.onEvent(e)})),n.open().onSuccessContinueWithPromise((function(r){if(200===r.statusCode){t.privConversationRequestSession.onPreConnectionStart(t.privConversationAuthFetchEventId,t.privConnectionId),t.privConversationRequestSession.onConnectionEstablishCompleted(r.statusCode);var i=new a.SessionEventArgs(t.privConversationRequestSession.sessionId);return t.privConversationServiceConnector.connectionOpened&&t.privConversationServiceConnector.connectionOpened(t.privConversationServiceConnector,i),o.PromiseHelper.fromResult(n)}return 403!==r.statusCode||e?(t.privConversationRequestSession.onConnectionEstablishCompleted(r.statusCode,r.reason),o.PromiseHelper.fromError("Unable to contact server. StatusCode: "+r.statusCode+", "+t.privRecognizerConfig.parameters.getProperty(a.PropertyId.SpeechServiceConnection_Endpoint)+" Reason: "+r.reason)):t.conversationConnectImpl(!0)}))})),this.privConnectionLoop=this.startMessageLoop(),this.privConversationConnectionPromise},t.prototype.startMessageLoop=function(){var e=this;return this.terminateMessageLoop=!1,this.receiveConversationMessageOverride().on((function(e){return!0}),(function(t){e.cancelRecognition(e.privRequestSession?e.privRequestSession.sessionId:"",e.privRequestSession?e.privRequestSession.requestId:"",a.CancellationReason.Error,a.CancellationErrorCode.RuntimeError,t)}))},t.prototype.configConnection=function(){return this.privConnectionConfigPromise?this.privConnectionConfigPromise.result().isCompleted&&(this.privConnectionConfigPromise.result().isError||this.privConnectionConfigPromise.result().result.state()===o.ConnectionState.Disconnected)?(this.privConnectionConfigPromise=null,this.configConnection()):this.privConnectionConfigPromise:this.terminateMessageLoop?o.PromiseHelper.fromResult(void 0):(this.privConnectionConfigPromise=this.conversationConnectImpl().onSuccessContinueWith((function(e){return e})),this.privConnectionConfigPromise)},t.prototype.getTranslations=function(e){var t;if(void 0!==e){t=new a.Translations;for(var r=0,n=e;r-1?this.participants.splice(t,1,e):this.participants.push(e),this.getParticipant(e.id)}},e.prototype.getParticipantIndex=function(e){return this.participants.findIndex((function(t){return t.id===e}))},e.prototype.getParticipant=function(e){return this.participants.find((function(t){return t.id===e}))},e.prototype.deleteParticipant=function(e){this.participants=this.participants.filter((function(t){return t.id!==e}))},Object.defineProperty(e.prototype,"host",{get:function(){return this.participants.find((function(e){return!0===e.isHost}))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"me",{get:function(){return this.getParticipant(this.meId)},enumerable:!0,configurable:!0}),e}();t.InternalParticipants=n,t.ConversationTranslatorMessageTypes={command:"command",final:"final",info:"info",instantMessage:"instant_message",partial:"partial",participantCommand:"participant_command",translatedMessage:"translated_message"},t.ConversationTranslatorCommandTypes={changeNickname:"ChangeNickname",disconnectSession:"DisconnectSession",ejectParticipant:"EjectParticipant",instant_message:"instant_message",joinSession:"JoinSession",leaveSession:"LeaveSession",participantList:"ParticipantList",roomExpirationWarning:"RoomExpirationWarning",setLockState:"SetLockState",setMute:"SetMute",setMuteAll:"SetMuteAll",setProfanityFiltering:"SetProfanityFiltering",setTranslateToLanguages:"SetTranslateToLanguages",setUseTTS:"SetUseTTS"}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(170);t.CommandResponsePayload=n.CommandResponsePayload;var i=r(171);t.ParticipantsListPayloadResponse=i.ParticipantsListPayloadResponse,t.ParticipantPayloadResponse=i.ParticipantPayloadResponse;var o=r(172);t.SpeechResponsePayload=o.SpeechResponsePayload,t.TextResponsePayload=o.TextResponsePayload},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e){this.privCommandResponse=JSON.parse(e)}return e.fromJSON=function(t){return new e(t)},Object.defineProperty(e.prototype,"type",{get:function(){return this.privCommandResponse.type},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"command",{get:function(){return this.privCommandResponse.command},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return this.privCommandResponse.id},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"nickname",{get:function(){return this.privCommandResponse.nickname},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"participantId",{get:function(){return this.privCommandResponse.participantId},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"roomid",{get:function(){return this.privCommandResponse.roomid},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.privCommandResponse.value},enumerable:!0,configurable:!0}),e}();t.CommandResponsePayload=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e){this.privParticipantsPayloadResponse=JSON.parse(e)}return e.fromJSON=function(t){return new e(t)},Object.defineProperty(e.prototype,"roomid",{get:function(){return this.privParticipantsPayloadResponse.roomid},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return this.privParticipantsPayloadResponse.id},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"command",{get:function(){return this.privParticipantsPayloadResponse.command},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"participants",{get:function(){return this.privParticipantsPayloadResponse.participants},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"token",{get:function(){return this.privParticipantsPayloadResponse.token},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"translateTo",{get:function(){return this.privParticipantsPayloadResponse.translateTo},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"profanityFilter",{get:function(){return this.privParticipantsPayloadResponse.profanityFilter},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"roomProfanityFilter",{get:function(){return this.privParticipantsPayloadResponse.roomProfanityFilter},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"roomLocked",{get:function(){return this.privParticipantsPayloadResponse.roomLocked},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"muteAll",{get:function(){return this.privParticipantsPayloadResponse.muteAll},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"type",{get:function(){return this.privParticipantsPayloadResponse.type},enumerable:!0,configurable:!0}),e}();t.ParticipantsListPayloadResponse=n;var i=function(){function e(e){this.privParticipantPayloadResponse=JSON.parse(e)}return e.fromJSON=function(t){return new e(t)},Object.defineProperty(e.prototype,"nickname",{get:function(){return this.privParticipantPayloadResponse.nickname},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"locale",{get:function(){return this.privParticipantPayloadResponse.locale},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"usetts",{get:function(){return this.privParticipantPayloadResponse.usetts},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"ismuted",{get:function(){return this.privParticipantPayloadResponse.ismuted},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"ishost",{get:function(){return this.privParticipantPayloadResponse.ishost},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"participantId",{get:function(){return this.privParticipantPayloadResponse.participantId},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"avatar",{get:function(){return this.privParticipantPayloadResponse.avatar},enumerable:!0,configurable:!0}),e}();t.ParticipantPayloadResponse=i},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e){this.privSpeechResponse=JSON.parse(e)}return e.fromJSON=function(t){return new e(t)},Object.defineProperty(e.prototype,"recognition",{get:function(){return this.privSpeechResponse.recognition},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"translations",{get:function(){return this.privSpeechResponse.translations},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return this.privSpeechResponse.id},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"language",{get:function(){return this.privSpeechResponse.language},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"nickname",{get:function(){return this.privSpeechResponse.nickname},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"participantId",{get:function(){return this.privSpeechResponse.participantId},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"roomid",{get:function(){return this.privSpeechResponse.roomid},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"timestamp",{get:function(){return this.privSpeechResponse.timestamp},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"type",{get:function(){return this.privSpeechResponse.type},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isFinal",{get:function(){return"final"===this.privSpeechResponse.type},enumerable:!0,configurable:!0}),e}();t.SpeechResponsePayload=n;var i=function(){function e(e){this.privTextResponse=JSON.parse(e)}return e.fromJSON=function(t){return new e(t)},Object.defineProperty(e.prototype,"originalText",{get:function(){return this.privTextResponse.originalText},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"translations",{get:function(){return this.privTextResponse.translations},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return this.privTextResponse.id},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"language",{get:function(){return this.privTextResponse.language},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"nickname",{get:function(){return this.privTextResponse.nickname},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"participantId",{get:function(){return this.privTextResponse.participantId},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"roomid",{get:function(){return this.privTextResponse.roomid},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"timestamp",{get:function(){return this.privTextResponse.timestamp},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"type",{get:function(){return this.privTextResponse.type},enumerable:!0,configurable:!0}),e}();t.TextResponsePayload=i},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e){this.privSynthesisAudioMetadata=JSON.parse(e)}return e.fromJSON=function(t){return new e(t)},Object.defineProperty(e.prototype,"Metadata",{get:function(){return this.privSynthesisAudioMetadata.Metadata},enumerable:!0,configurable:!0}),e}();t.SynthesisAudioMetadata=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(4),i=r(43),o=r(175),s=r(176),a=function(){function e(){var e=this;this.privIsDisposed=!1,this.privIsSynthesizing=!1,this.privIsSynthesisEnded=!1,this.privBytesReceived=0,this.privTextOffset=0,this.privNextSearchTextIndex=0,this.onPreConnectionStart=function(t,r){e.privAuthFetchEventId=t,e.onEvent(new s.ConnectingToSynthesisServiceEvent(e.privRequestId,e.privAuthFetchEventId))},this.onAuthCompleted=function(t,r){t&&e.onComplete()},this.onConnectionEstablishCompleted=function(t,r){if(200===t)return e.onEvent(new s.SynthesisStartedEvent(e.requestId,e.privAuthFetchEventId)),void(e.privBytesReceived=0);403===t&&e.onComplete()},this.onServiceResponseMessage=function(t){var r=JSON.parse(t);e.streamId=r.audio.streamId},this.onServiceTurnEndResponse=function(){e.privTurnDeferral.resolve(!0),e.onComplete()},this.onServiceTurnStartResponse=function(){e.privTurnDeferral.state()===n.PromiseState.None&&e.privTurnDeferral.reject("Another turn started before current completed."),e.privTurnDeferral=new n.Deferred},this.dispose=function(t){e.privIsDisposed||(e.privIsDisposed=!0)},this.onEvent=function(e){n.Events.instance.onEvent(e)},this.onComplete=function(){e.privIsSynthesizing&&(e.privIsSynthesizing=!1,e.privIsSynthesisEnded=!0,e.privAudioOutputStream.close(),void 0!==e.privTurnAudioDestination&&(e.privTurnAudioDestination.close(),e.privTurnAudioDestination=void 0))},this.privRequestId=n.createNoDashGuid(),this.privTurnDeferral=new n.Deferred,this.privTurnDeferral.resolve(!0)}return Object.defineProperty(e.prototype,"requestId",{get:function(){return this.privRequestId},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"streamId",{get:function(){return this.privStreamId},set:function(e){this.privStreamId=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"audioOutputFormat",{get:function(){return this.privAudioOutputFormat},set:function(e){this.privAudioOutputFormat=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"turnCompletionPromise",{get:function(){return this.privTurnDeferral.promise()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isSynthesisEnded",{get:function(){return this.privIsSynthesisEnded},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isSynthesizing",{get:function(){return this.privIsSynthesizing},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"currentTextOffset",{get:function(){return this.privTextOffset},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bytesReceived",{get:function(){return this.privBytesReceived},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"allReceivedAudio",{get:function(){return this.privReceivedAudio?this.privReceivedAudio:this.privIsSynthesisEnded?(this.readAllAudioFromStream(),this.allReceivedAudio):null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"allReceivedAudioWithHeader",{get:function(){return this.privReceivedAudioWithHeader?this.privReceivedAudioWithHeader:this.privIsSynthesisEnded?this.audioOutputFormat.hasHeader?(this.privReceivedAudioWithHeader=o.SynthesisAdapterBase.addHeader(this.allReceivedAudio,this.audioOutputFormat),this.allReceivedAudioWithHeader):this.allReceivedAudio:null},enumerable:!0,configurable:!0}),e.prototype.startNewSynthesis=function(e,t,r,n){this.privIsSynthesisEnded=!1,this.privIsSynthesizing=!0,this.privRequestId=e,this.privRawText=t,this.privIsSSML=r,this.privAudioOutputStream=new i.PullAudioOutputStreamImpl,this.privAudioOutputStream.format=this.privAudioOutputFormat,this.privReceivedAudio=null,this.privReceivedAudioWithHeader=null,this.privBytesReceived=0,this.privTextOffset=0,this.privNextSearchTextIndex=0,void 0!==n&&(this.privTurnAudioDestination=n,this.privTurnAudioDestination.format=this.privAudioOutputFormat),this.onEvent(new s.SynthesisTriggeredEvent(this.requestId,void 0,void 0===n?void 0:n.id()))},e.prototype.onAudioChunkReceived=function(e){this.isSynthesizing&&(this.privAudioOutputStream.write(e),this.privBytesReceived+=e.byteLength,void 0!==this.privTurnAudioDestination&&this.privTurnAudioDestination.write(e))},e.prototype.onWordBoundaryEvent=function(e){this.updateTextOffset(e)},e.prototype.onStopSynthesizing=function(){this.onComplete()},e.prototype.updateTextOffset=function(e){this.privTextOffset>=0&&(this.privTextOffset=this.privRawText.indexOf(e,this.privNextSearchTextIndex),this.privTextOffset>=0&&(this.privNextSearchTextIndex=this.privTextOffset+e.length),this.privIsSSML&&this.privRawText.indexOf("<",this.privTextOffset+1)>this.privRawText.indexOf(">",this.privTextOffset+1)&&this.updateTextOffset(e))},e.prototype.readAllAudioFromStream=function(){if(this.privIsSynthesisEnded){this.privReceivedAudio=new ArrayBuffer(this.bytesReceived);try{this.privAudioOutputStream.read(this.privReceivedAudio)}catch(e){this.privReceivedAudio=new ArrayBuffer(0)}}},e}();t.SynthesisTurn=a},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(4),i=r(31),o=r(26),s=r(128),a=function(){function e(t,r,a,c,p){var u=this;if(this.speakOverride=void 0,this.receiveMessageOverride=void 0,this.connectImplOverride=void 0,this.configConnectionOverride=void 0,this.fetchConnectionOverride=void 0,this.receiveMessage=function(){return u.fetchConnection().on((function(t){return t.read().onSuccessContinueWithPromise((function(t){if(void 0!==u.receiveMessageOverride)return u.receiveMessageOverride();if(u.privIsDisposed)return n.PromiseHelper.fromResult(void 0);if(!t)return u.privSynthesisTurn.isSynthesizing?u.receiveMessage():n.PromiseHelper.fromResult(!0);u.privServiceHasSentMessage=!0;var r=s.SpeechConnectionMessage.fromConnectionMessage(t);if(r.requestId.toLowerCase()===u.privSynthesisTurn.requestId.toLowerCase())switch(r.path.toLowerCase()){case"turn.start":u.privSynthesisTurn.onServiceTurnStartResponse();break;case"response":u.privSynthesisTurn.onServiceResponseMessage(r.textBody);break;case"audio":if(u.privSynthesisTurn.streamId.toLowerCase()===r.streamId.toLowerCase()&&r.binaryBody){if(u.privSynthesisTurn.onAudioChunkReceived(r.binaryBody),u.privSpeechSynthesizer.synthesizing)try{var a=e.addHeader(r.binaryBody,u.privSynthesisTurn.audioOutputFormat),c=new i.SpeechSynthesisEventArgs(new i.SpeechSynthesisResult(u.privSynthesisTurn.requestId,i.ResultReason.SynthesizingAudio,a));u.privSpeechSynthesizer.synthesizing(u.privSpeechSynthesizer,c)}catch(e){}void 0!==u.privSessionAudioDestination&&u.privSessionAudioDestination.write(r.binaryBody)}break;case"audio.metadata":for(var p=0,f=o.SynthesisAudioMetadata.fromJSON(r.textBody).Metadata;p=32e3;)e<<=1,r>>=1;return t.createScriptProcessor(e,1,1)}}(),s=new n.RiffPcmEncoder(t.sampleRate,16e3);o.onaudioprocess=function(e){var t=e.inputBuffer.getChannelData(0);if(i&&!i.isClosed){var r=s.encode(t);r&&(i.writeStreamChunk({buffer:r,isEnd:!1,timeReceived:Date.now()}),!1)}};var a=t.createMediaStreamSource(r);e.privSpeechProcessorScript&&t.audioWorklet?t.audioWorklet.addModule(e.privSpeechProcessorScript).then((function(){var n=new AudioWorkletNode(t,"speech-processor");n.port.onmessage=function(e){var t=e.data;if(i&&!i.isClosed){var r=s.encode(t);r&&(i.writeStreamChunk({buffer:r,isEnd:!1,timeReceived:Date.now()}),!1)}},a.connect(n),n.connect(t.destination),e.privMediaResources={scriptProcessorNode:n,source:a,stream:r}})).catch((function(){a.connect(o),o.connect(t.destination),e.privMediaResources={scriptProcessorNode:o,source:a,stream:r}})):(a.connect(o),o.connect(t.destination),e.privMediaResources={scriptProcessorNode:o,source:a,stream:r})},this.releaseMediaResources=function(t){e.privMediaResources&&(e.privMediaResources.scriptProcessorNode&&(e.privMediaResources.scriptProcessorNode.disconnect(t.destination),e.privMediaResources.scriptProcessorNode=null),e.privMediaResources.source&&(e.privMediaResources.source.disconnect(),e.privMediaResources.stream.getTracks().forEach((function(e){return e.stop()})),e.privMediaResources.source=null))}}return e.prototype.setWorkletUrl=function(e){this.privSpeechProcessorScript=e},e}();t.PcmRecorder=i},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(4),i=r(184),o=function(){function e(e,t,r,o,s,a){var c=this;if(this.privIsDisposed=!1,this.dispose=function(){c.privIsDisposed=!0,c.privConnectionMessageAdapter&&c.privConnectionMessageAdapter.close()},this.isDisposed=function(){return c.privIsDisposed},this.state=function(){return c.privConnectionMessageAdapter.state},this.open=function(){return c.privConnectionMessageAdapter.open()},this.send=function(e){return c.privConnectionMessageAdapter.send(e)},this.read=function(){return c.privConnectionMessageAdapter.read()},!e)throw new n.ArgumentNullError("uri");if(!o)throw new n.ArgumentNullError("messageFormatter");this.privMessageFormatter=o;var p="",u=0;if(t)for(var f in t){if(f)p+=0===u&&-1===e.indexOf("?")?"?":"&",p+=f+"="+encodeURIComponent(t[f]),u++}if(r)for(var h in r){if(h)p+=0===u&&-1===e.indexOf("?")?"?":"&",p+=h+"="+encodeURIComponent(r[h]),u++}this.privUri=e+p,this.privId=a||n.createNoDashGuid(),this.privConnectionMessageAdapter=new i.WebsocketMessageAdapter(this.privUri,this.id,this.privMessageFormatter,s,r)}return Object.defineProperty(e.prototype,"id",{get:function(){return this.privId},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"events",{get:function(){return this.privConnectionMessageAdapter.events},enumerable:!0,configurable:!0}),e}();t.WebsocketConnection=o},function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var i=r(4),o=n(r(185)),s=r(186),a=function(){function e(t,r,n,a,c){var p=this;if(this.open=function(){if(p.privConnectionState===i.ConnectionState.Disconnected)return i.PromiseHelper.fromError("Cannot open a connection that is in "+p.privConnectionState+" state");if(p.privConnectionEstablishDeferral)return p.privConnectionEstablishDeferral.promise();p.privConnectionEstablishDeferral=new i.Deferred,p.privCertificateValidatedDeferral=new i.Deferred,p.privConnectionState=i.ConnectionState.Connecting;try{if("undefined"==typeof WebSocket||e.forceNpmWebSocket){var t={headers:p.privHeaders};p.privCertificateValidatedDeferral.resolve(!0);var r=new s.CertCheckAgent(p.proxyInfo);t.agent=r.GetAgent(),p.privWebsocketClient=new o.default(p.privUri,t)}else p.privCertificateValidatedDeferral.resolve(!0),p.privWebsocketClient=new WebSocket(p.privUri);p.privWebsocketClient.binaryType="arraybuffer",p.privReceivingMessageQueue=new i.Queue,p.privDisconnectDeferral=new i.Deferred,p.privSendMessageQueue=new i.Queue,p.processSendQueue()}catch(e){return p.privConnectionEstablishDeferral.resolve(new i.ConnectionOpenResponse(500,e)),p.privConnectionEstablishDeferral.promise()}return p.onEvent(new i.ConnectionStartEvent(p.privConnectionId,p.privUri)),p.privWebsocketClient.onopen=function(e){p.privCertificateValidatedDeferral.promise().on((function(){p.privConnectionState=i.ConnectionState.Connected,p.onEvent(new i.ConnectionEstablishedEvent(p.privConnectionId)),p.privConnectionEstablishDeferral.resolve(new i.ConnectionOpenResponse(200,""))}),(function(e){p.privConnectionEstablishDeferral.reject(e)}))},p.privWebsocketClient.onerror=function(e){p.onEvent(new i.ConnectionErrorEvent(p.privConnectionId,e.message,e.type)),p.privLastErrorReceived=e.message},p.privWebsocketClient.onclose=function(e){p.privConnectionState===i.ConnectionState.Connecting?(p.privConnectionState=i.ConnectionState.Disconnected,p.privConnectionEstablishDeferral.resolve(new i.ConnectionOpenResponse(e.code,e.reason+" "+p.privLastErrorReceived))):(p.privConnectionState=i.ConnectionState.Disconnected,p.onEvent(new i.ConnectionClosedEvent(p.privConnectionId,e.code,e.reason))),p.onClose(e.code,e.reason)},p.privWebsocketClient.onmessage=function(e){var t=(new Date).toISOString();if(p.privConnectionState===i.ConnectionState.Connected){var r=new i.Deferred;if(p.privReceivingMessageQueue.enqueueFromPromise(r.promise()),e.data instanceof ArrayBuffer){var n=new i.RawWebsocketMessage(i.MessageType.Binary,e.data);p.privMessageFormatter.toConnectionMessage(n).on((function(e){p.onEvent(new i.ConnectionMessageReceivedEvent(p.privConnectionId,t,e)),r.resolve(e)}),(function(e){r.reject("Invalid binary message format. Error: "+e)}))}else{n=new i.RawWebsocketMessage(i.MessageType.Text,e.data);p.privMessageFormatter.toConnectionMessage(n).on((function(e){p.onEvent(new i.ConnectionMessageReceivedEvent(p.privConnectionId,t,e)),r.resolve(e)}),(function(e){r.reject("Invalid text message format. Error: "+e)}))}}},p.privConnectionEstablishDeferral.promise()},this.send=function(e){if(p.privConnectionState!==i.ConnectionState.Connected)return i.PromiseHelper.fromError("Cannot send on connection that is in "+p.privConnectionState+" state");var t=new i.Deferred,r=new i.Deferred;return p.privSendMessageQueue.enqueueFromPromise(r.promise()),p.privMessageFormatter.fromConnectionMessage(e).on((function(n){r.resolve({Message:e,RawWebsocketMessage:n,sendStatusDeferral:t})}),(function(e){r.reject("Error formatting the message. "+e)})),t.promise()},this.read=function(){return p.privConnectionState!==i.ConnectionState.Connected?i.PromiseHelper.fromError("Cannot read on connection that is in "+p.privConnectionState+" state"):p.privReceivingMessageQueue.dequeue()},this.close=function(e){if(!p.privWebsocketClient){var t=new i.Deferred;return t.resolve(!0),t.promise()}return p.privConnectionState!==i.ConnectionState.Disconnected&&p.privWebsocketClient.close(1e3,e||"Normal closure by client"),p.privDisconnectDeferral.promise()},this.sendRawMessage=function(e){try{return e?(p.onEvent(new i.ConnectionMessageSentEvent(p.privConnectionId,(new Date).toISOString(),e.Message)),p.isWebsocketOpen?(p.privWebsocketClient.send(e.RawWebsocketMessage.payload),i.PromiseHelper.fromResult(!0)):i.PromiseHelper.fromError("websocket send error: Websocket not ready")):i.PromiseHelper.fromResult(!0)}catch(e){return i.PromiseHelper.fromError("websocket send error: "+e)}},this.onClose=function(e,t){var r="Connection closed. "+e+": "+t;p.privConnectionState=i.ConnectionState.Disconnected,p.privDisconnectDeferral.resolve(!0),p.privReceivingMessageQueue.dispose(t),p.privReceivingMessageQueue.drainAndDispose((function(e){}),r),p.privSendMessageQueue.drainAndDispose((function(e){e.sendStatusDeferral.reject(r)}),r)},this.processSendQueue=function(){p.privSendMessageQueue.dequeue().on((function(e){e&&p.sendRawMessage(e).on((function(t){e.sendStatusDeferral.resolve(t),p.processSendQueue()}),(function(t){e.sendStatusDeferral.reject(t),p.processSendQueue()}))}),(function(e){}))},this.onEvent=function(e){p.privConnectionEvents.onEvent(e),i.Events.instance.onEvent(e)},!t)throw new i.ArgumentNullError("uri");if(!n)throw new i.ArgumentNullError("messageFormatter");this.proxyInfo=a,this.privConnectionEvents=new i.EventSource,this.privConnectionId=r,this.privMessageFormatter=n,this.privConnectionState=i.ConnectionState.None,this.privUri=t,this.privHeaders=c,this.privHeaders["X-ConnectionId"]=this.privConnectionId,this.privLastErrorReceived=""}return Object.defineProperty(e.prototype,"state",{get:function(){return this.privConnectionState},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"events",{get:function(){return this.privConnectionEvents},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isWebsocketOpen",{get:function(){return this.privWebsocketClient&&this.privWebsocketClient.readyState===this.privWebsocketClient.OPEN},enumerable:!0,configurable:!0}),e.forceNpmWebSocket=!1,e}();t.WebsocketMessageAdapter=a},function(e,t){},function(e,t,r){"use strict";(function(e,n){var i=this&&this.__assign||function(){return(i=Object.assign||function(e){for(var t,r=1,n=arguments.length;r0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]0){t.privProxyInfo=this.privProxyInfo}return t},t.GetProxyAgent=function(e){var t={host:e.HostName,port:e.Port};return e.UserName?t.headers={"Proxy-Authentication":"Basic "+new n(e.UserName+":"+(void 0===e.Password)?"":e.Password).toString("base64")}:t.headers={},t.headers.requestOCSP="true",new d.default(t)},t.OCSPCheck=function(e,r){return o(this,void 0,void 0,(function(){var n,i,a,c,p,u=this;return s(this,(function(v){switch(v.label){case 0:return a=!1,[4,e];case 1:return(c=v.sent()).cork(),p=c,[2,new Promise((function(e,v){c.on("OCSPResponse",(function(e){e&&(u.onEvent(new h.OCSPStapleReceivedEvent),i=e)})),c.on("error",(function(e){a||(a=!0,c.destroy(),v(e))})),p.on("secure",(function(){return o(u,void 0,void 0,(function(){var o,u,h,l,d;return s(this,(function(s){switch(s.label){case 0:o=p.getPeerCertificate(!0),s.label=1;case 1:return s.trys.push([1,6,,7]),[4,this.GetIssuer(o)];case 2:return u=s.sent(),n=f.request.generate(o.raw,u.raw),h=n.id.toString("hex"),i?[3,4]:[4,t.GetResponseFromCache(h,n,r)];case 3:l=s.sent(),i=l,s.label=4;case 4:return[4,this.VerifyOCSPResponse(i,n,r)];case 5:return s.sent(),c.uncork(),a=!0,e(c),[3,7];case 6:return d=s.sent(),c.destroy(),a=!0,v(d),[3,7];case 7:return[2]}}))}))}))}))]}}))}))},t.GetIssuer=function(e){return e.issuerCertificate?Promise.resolve(e.issuerCertificate):new Promise((function(t,r){new f.Agent({}).fetchIssuer(e,null,(function(e,n){e?r(e):t(n)}))}))},t.GetResponseFromCache=function(e,r,n){return o(this,void 0,void 0,(function(){var i,o,a,c,p,u,v,l=this;return s(this,(function(s){switch(s.label){case 0:if((i=t.privMemCache[e])&&this.onEvent(new h.OCSPMemoryCacheHitEvent(e)),i)return[3,4];s.label=1;case 1:return s.trys.push([1,3,,4]),[4,t.privDiskCache.get(e)];case 2:return(o=s.sent()).isCached&&(t.onEvent(new h.OCSPDiskCacheHitEvent(e)),t.StoreMemoryCacheEntry(e,o.value),i=o.value),[3,4];case 3:return s.sent(),i=null,[3,4];case 4:if(!i)return[2,i];try{if(a=f.utils.parseResponse(i),(c=a.value.tbsResponseData).responses.length<1)return this.onEvent(new h.OCSPCacheFetchErrorEvent(e,"Not enough data in cached response")),[2];p=c.responses[0].thisUpdate,(u=c.responses[0].nextUpdate)1)for(var r=1;r",'"',"`"," ","\r","\n","\t"]),u=["'"].concat(p),f=["%","/","?",";","#"].concat(u),h=["/","?","#"],v=/^[+a-z0-9A-Z_-]{0,63}$/,l=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,d={javascript:!0,"javascript:":!0},g={javascript:!0,"javascript:":!0},y={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},m=r(193);function S(e,t,r){if(e&&i.isObject(e)&&e instanceof o)return e;var n=new o;return n.parse(e,t,r),n}o.prototype.parse=function(e,t,r){if(!i.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var o=e.indexOf("?"),a=-1!==o&&o127?j+="x":j+=M[k];if(!j.match(v)){var x=A.slice(0,E),z=A.slice(E+1),L=M.match(l);L&&(x.push(L[1]),z.unshift(L[2])),z.length&&(S="/"+z.join(".")+S),this.hostname=x.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),_||(this.hostname=n.toASCII(this.hostname));var B=this.port?":"+this.port:"",F=this.hostname||"";this.host=F+B,this.href+=this.host,_&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==S[0]&&(S="/"+S))}if(!d[b])for(E=0,D=u.length;E0)&&r.host.split("@"))&&(r.auth=_.shift(),r.host=r.hostname=_.shift());return r.search=e.search,r.query=e.query,i.isNull(r.pathname)&&i.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.href=r.format(),r}if(!R.length)return r.pathname=null,r.search?r.path="/"+r.search:r.path=null,r.href=r.format(),r;for(var O=R.slice(-1)[0],w=(r.host||e.host||R.length>1)&&("."===O||".."===O)||""===O,E=0,T=R.length;T>=0;T--)"."===(O=R[T])?R.splice(T,1):".."===O?(R.splice(T,1),E++):E&&(R.splice(T,1),E--);if(!P&&!b)for(;E--;E)R.unshift("..");!P||""===R[0]||R[0]&&"/"===R[0].charAt(0)||R.unshift(""),w&&"/"!==R.join("/").substr(-1)&&R.push("");var _,A=""===R[0]||R[0]&&"/"===R[0].charAt(0);I&&(r.hostname=r.host=A?"":R.length?R.shift():"",(_=!!(r.host&&r.host.indexOf("@")>0)&&r.host.split("@"))&&(r.auth=_.shift(),r.host=r.hostname=_.shift()));return(P=P||r.host&&R.length)&&!A&&R.unshift(""),R.length?r.pathname=R.join("/"):(r.pathname=null,r.path=null),i.isNull(r.pathname)&&i.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.auth=e.auth||r.auth,r.slashes=r.slashes||e.slashes,r.href=r.format(),r},o.prototype.parseHost=function(){var e=this.host,t=a.exec(e);t&&(":"!==(t=t[0])&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)}},function(e,t,r){(function(e,n){var i;/*! https://mths.be/punycode v1.4.1 by @mathias */!function(o){t&&t.nodeType,e&&e.nodeType;var s="object"==typeof n&&n;s.global!==s&&s.window!==s&&s.self;var a,c=2147483647,p=36,u=1,f=26,h=38,v=700,l=72,d=128,g="-",y=/^xn--/,m=/[^\x20-\x7E]/,S=/[\x2E\u3002\uFF0E\uFF61]/g,C={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},P=p-u,b=Math.floor,R=String.fromCharCode;function I(e){throw new RangeError(C[e])}function O(e,t){for(var r=e.length,n=[];r--;)n[r]=t(e[r]);return n}function w(e,t){var r=e.split("@"),n="";return r.length>1&&(n=r[0]+"@",e=r[1]),n+O((e=e.replace(S,".")).split("."),t).join(".")}function E(e){for(var t,r,n=[],i=0,o=e.length;i=55296&&t<=56319&&i65535&&(t+=R((e-=65536)>>>10&1023|55296),e=56320|1023&e),t+=R(e)})).join("")}function _(e,t){return e+22+75*(e<26)-((0!=t)<<5)}function A(e,t,r){var n=0;for(e=r?b(e/v):e>>1,e+=b(e/t);e>P*f>>1;n+=p)e=b(e/P);return b(n+(P+1)*e/(e+h))}function D(e){var t,r,n,i,o,s,a,h,v,y,m,S=[],C=e.length,P=0,R=d,O=l;for((r=e.lastIndexOf(g))<0&&(r=0),n=0;n=128&&I("not-basic"),S.push(e.charCodeAt(n));for(i=r>0?r+1:0;i=C&&I("invalid-input"),((h=(m=e.charCodeAt(i++))-48<10?m-22:m-65<26?m-65:m-97<26?m-97:p)>=p||h>b((c-P)/s))&&I("overflow"),P+=h*s,!(h<(v=a<=O?u:a>=O+f?f:a-O));a+=p)s>b(c/(y=p-v))&&I("overflow"),s*=y;O=A(P-o,t=S.length+1,0==o),b(P/t)>c-R&&I("overflow"),R+=b(P/t),P%=t,S.splice(P++,0,R)}return T(S)}function M(e){var t,r,n,i,o,s,a,h,v,y,m,S,C,P,O,w=[];for(S=(e=E(e)).length,t=d,r=0,o=l,s=0;s=t&&mb((c-r)/(C=n+1))&&I("overflow"),r+=(a-t)*C,t=a,s=0;sc&&I("overflow"),m==t){for(h=r,v=p;!(h<(y=v<=o?u:v>=o+f?f:v-o));v+=p)O=h-y,P=p-y,w.push(R(_(y+O%P,0))),h=b(O/P);w.push(R(_(h,0))),o=A(r,C,n==i),r=0,++n}++r,++t}return w.join("")}a={version:"1.4.1",ucs2:{decode:E,encode:T},decode:D,encode:M,toASCII:function(e){return w(e,(function(e){return m.test(e)?"xn--"+M(e):e}))},toUnicode:function(e){return w(e,(function(e){return y.test(e)?D(e.slice(4).toLowerCase()):e}))}},void 0===(i=function(){return a}.call(t,r,t,e))||(e.exports=i)}()}).call(this,r(191)(e),r(38))},function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,r){"use strict";e.exports={isString:function(e){return"string"==typeof e},isObject:function(e){return"object"==typeof e&&null!==e},isNull:function(e){return null===e},isNullOrUndefined:function(e){return null==e}}},function(e,t,r){"use strict";t.decode=t.parse=r(194),t.encode=t.stringify=r(195)},function(e,t,r){"use strict";function n(e,t){return Object.prototype.hasOwnProperty.call(e,t)}e.exports=function(e,t,r,o){t=t||"&",r=r||"=";var s={};if("string"!=typeof e||0===e.length)return s;var a=/\+/g;e=e.split(t);var c=1e3;o&&"number"==typeof o.maxKeys&&(c=o.maxKeys);var p=e.length;c>0&&p>c&&(p=c);for(var u=0;u=0?(f=d.substr(0,g),h=d.substr(g+1)):(f=d,h=""),v=decodeURIComponent(f),l=decodeURIComponent(h),n(s,v)?i(s[v])?s[v].push(l):s[v]=[s[v],l]:s[v]=l}return s};var i=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}},function(e,t,r){"use strict";var n=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};e.exports=function(e,t,r,a){return t=t||"&",r=r||"=",null===e&&(e=void 0),"object"==typeof e?o(s(e),(function(s){var a=encodeURIComponent(n(s))+r;return i(e[s])?o(e[s],(function(e){return a+encodeURIComponent(n(e))})).join(t):a+encodeURIComponent(n(e[s]))})).join(t):a?encodeURIComponent(n(a))+r+encodeURIComponent(n(e)):""};var i=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};function o(e,t){if(e.map)return e.map(t);for(var r=[],n=0;n=this.privBuffers[i].chunk.buffer.byteLength;)r-=this.privBuffers[i++].chunk.buffer.byteLength;var s=this.privBuffers[i].chunk.buffer.slice(r);return this.privReplayOffset+=s.byteLength/this.privBytesPerSecond*1e7,i===this.privBuffers.length-1&&(this.privReplay=!1),n.PromiseHelper.fromResult({buffer:s,isEnd:!1,timeReceived:this.privBuffers[i].chunk.timeReceived})}return this.privAudioNode.read().onSuccessContinueWith((function(t){return t&&t.buffer&&(e.privBuffers.push(new o(t,e.privBufferSerial++,e.privBufferedBytes)),e.privBufferedBytes+=t.buffer.byteLength),t}))},e.prototype.detach=function(){this.privAudioNode.detach(),this.privBuffers=void 0},e.prototype.replay=function(){this.privBuffers&&0!==this.privBuffers.length&&(this.privReplay=!0,this.privReplayOffset=this.privLastShrinkOffset)},e.prototype.shrinkBuffers=function(e){if(void 0!==this.privBuffers){this.privLastShrinkOffset=e;for(var t=e-this.privBufferStartOffset,r=Math.round(t*this.privBytesPerSecond*1e-7),n=0;n=this.privBuffers[n].chunk.buffer.byteLength;)r-=this.privBuffers[n++].chunk.buffer.byteLength;this.privBufferStartOffset=Math.round(e-r/this.privBytesPerSecond*1e7),this.privBuffers=this.privBuffers.slice(n)}},e.prototype.findTimeAtOffset=function(e){if(e=i&&e<=o)return n.chunk.timeReceived}return 0},e}();t.ReplayableAudioNode=i;var o=function(e,t,r){this.chunk=e,this.serial=t,this.byteOffset=r}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(31),i=function(){function e(e,t,r,n){this.privProxyHostName=e,this.privProxyPort=t,this.privProxyUserName=r,this.privProxyPassword=n}return e.fromParameters=function(t){return new e(t.getProperty(n.PropertyId.SpeechServiceConnection_ProxyHostName),parseInt(t.getProperty(n.PropertyId.SpeechServiceConnection_ProxyPort),10),t.getProperty(n.PropertyId.SpeechServiceConnection_ProxyUserName),t.getProperty(n.PropertyId.SpeechServiceConnection_ProxyPassword))},e.fromRecognizerConfig=function(e){return this.fromParameters(e.parameters)},Object.defineProperty(e.prototype,"HostName",{get:function(){return this.privProxyHostName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Port",{get:function(){return this.privProxyPort},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"UserName",{get:function(){return this.privProxyUserName},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"Password",{get:function(){return this.privProxyPassword},enumerable:!0,configurable:!0}),e}();t.ProxyInfo=i},function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(t,"__esModule",{value:!0});var i,o=r(4),s=n(r(203));!function(e){e.Get="get",e.Post="post",e.Delete="delete",e.File="file"}(i=t.RestRequestType||(t.RestRequestType={}));var a=function(){function e(e,t){if(!e)throw new o.ArgumentNullError("configParams");this.privHeaders=e.headers,this.privTimeout=e.timeout,this.privIgnoreCache=e.ignoreCache}return e.prototype.setHeaders=function(e,t){this.privHeaders[e]=t},e.prototype.request=function(e,t,r,n,a){var c=this;void 0===r&&(r={}),void 0===n&&(n=null),void 0===a&&(a=null);var p,u=new o.Deferred;p="undefined"==typeof XMLHttpRequest?new s.XMLHttpRequest:new XMLHttpRequest;var f=e===i.File?"post":e;return p.open(f,this.withQuery(t,r),!0),this.privHeaders&&Object.keys(this.privHeaders).forEach((function(e){return p.setRequestHeader(e,c.privHeaders[e])})),this.privIgnoreCache&&p.setRequestHeader("Cache-Control","no-cache"),p.timeout=this.privTimeout,p.onload=function(){u.resolve(c.parseXHRResult(p))},p.onerror=function(){u.resolve(c.errorResponse(p,"Failed to make request."))},p.ontimeout=function(){u.resolve(c.errorResponse(p,"Request took longer than expected."))},e===i.File&&a?(p.setRequestHeader("Content-Type","multipart/form-data"),p.send(a)):e===i.Post&&n?(p.setRequestHeader("Content-Type","application/json"),p.send(JSON.stringify(n))):p.send(),u.promise()},e.prototype.parseXHRResult=function(e){return{data:e.responseText,headers:e.getAllResponseHeaders(),json:function(){return JSON.parse(e.responseText)},ok:e.status>=200&&e.status<300,status:e.status,statusText:e.statusText}},e.prototype.errorResponse=function(e,t){return void 0===t&&(t=null),{data:t||e.statusText,headers:e.getAllResponseHeaders(),json:function(){return JSON.parse(t||'"'+e.statusText+'"')},ok:!1,status:e.status,statusText:e.statusText}},e.prototype.withQuery=function(e,t){void 0===t&&(t={});var r=this.queryParams(t);return r?e+(-1===e.indexOf("?")?"?":"&")+r:e},e.prototype.queryParams=function(e){return void 0===e&&(e={}),Object.keys(e).map((function(t){return encodeURIComponent(t)+"="+encodeURIComponent(e[t])})).join("&")},e}();t.RestMessageAdapter=a},function(e,t){}]); \ No newline at end of file diff --git a/js/speech.js b/js/speech.js index 0bc4a998..2297cdb7 100644 --- a/js/speech.js +++ b/js/speech.js @@ -38,6 +38,7 @@ function Speech(texts, options) { }) } if (isAmazonPolly(options.voice)) return amazonPollyTtsEngine; + if (isAzure(options.voice)) return azureTtsEngine; if (isGoogleWavenet(options.voice)) return googleWavenetTtsEngine; if (isIbmWatson(options.voice)) return ibmWatsonTtsEngine; if (isRemoteVoice(options.voice)) return remoteTtsEngine; diff --git a/js/tts-engines.js b/js/tts-engines.js index 6c72ea5c..dd6e0276 100644 --- a/js/tts-engines.js +++ b/js/tts-engines.js @@ -5,6 +5,7 @@ var googleTranslateTtsEngine = new GoogleTranslateTtsEngine(); var amazonPollyTtsEngine = new AmazonPollyTtsEngine(); var googleWavenetTtsEngine = new GoogleWavenetTtsEngine(); var ibmWatsonTtsEngine = new IbmWatsonTtsEngine(); +var azureTtsEngine = new AzureTtsEngine(); /* @@ -38,6 +39,162 @@ interface TtsEngine { } */ +function AzureTtsEngine() { + var audio = document.createElement("AUDIO"); + var prefetchAudio; + var isSpeaking = false; + var speakPromise; + var synthesizer; + this.speak = function(utterance, options, onEvent) { + if (!options.volume) options.volume = 1; + if (!options.rate) options.rate = 1; + if (!options.pitch) options.pitch = 1; + audio.pause(); + audio.volume = options.volume; + audio.defaultPlaybackRate = options.rate; + audio.onplay = function() { + onEvent({type: 'start', charIndex: 0}); + isSpeaking = true; + }; + audio.onended = function() { + onEvent({type: 'end', charIndex: utterance.length}); + isSpeaking = false; + }; + audio.onerror = function() { + onEvent({type: "error", errorMessage: audio.error.message}); + isSpeaking = false; + }; + speakPromise = Promise.resolve() + .then(function() { + if (prefetchAudio && prefetchAudio[0] == utterance && prefetchAudio[1] == options) return prefetchAudio[2]; + else return getAudioUrl(utterance, options.lang, options.voice, options.pitch); + }) + .then(function(url) { + audio.src = url; + return audio.play(); + }) + .catch(function(err) { + onEvent({ + type: "error", + errorMessage: err.name == "NotAllowedError" ? JSON.stringify({code: "error_user_gesture_required"}) : err.message + }) + }) + }; + this.isSpeaking = function(callback) { + callback(isSpeaking); + }; + this.pause = + this.stop = function() { + speakPromise.then(function() {audio.pause()}); + }; + this.resume = function() { + audio.play(); + }; + this.setNextStartTime = function() { + }; + this.getVoices = function() { + return voices; + /*getSettings(["pollyVoices"]) + .then(function(items) { + if (!items.pollyVoices || Date.now()-items.pollyVoices[0].ts > 24*3600*1000) updateVoices(); + return items.pollyVoices || voices; + })*/ + } + function updateVoices() { + // TODO - using list API: get access token, list voices, turn result into compatible format + // https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/rest-text-to-speech#get-a-list-of-voices + /*ajaxGet(config.serviceUrl + "/read-aloud/list-voices/amazon") + .then(JSON.parse) + .then(function(list) { + list[0].ts = Date.now(); + updateSettings({pollyVoices: list}); + })*/ + } + function getAudioUrl(text, lang, voice, pitch) { + assert(text && lang && voice && pitch != null); + /*var matches = voice.voiceName.match(/^Amazon .* \((\w+)\)( \+\w+)?$/); + var voiceId = matches[1]; + var style = matches[2] && matches[2].substr(2);*/ + + return getSynthesizer() + .then(function(synthesizer) { + synthesizer.speakTextAsync( + text, + result => { + //const audioData = result.audioData; + URL.createObjectURL(result.audioData); + console.log(`Audio data byte size: ${audioData.byteLength}.`) + synthesizer.close(); + }, + error => { + console.log(error); + synthesizer.close(); + }); + }); + } + function getSynthesizer() { + //return synthesizer || (synthesizer = createSynthesizer()); + // TODO figure out how to reuse synthesizer object + return createSynthesizer(); + } + function createSynthesizer() { + return getSettings(["azureCreds"]) + .then(function(items) { + if (!items.azureCreds) throw new Error("Missing Azure credentials"); + const speechConfig = SpeechSDK.SpeechConfig.fromSubscription(items.azureCreds.subscriptionKey, items.azureCreds.region); + return new SpeechSDK.SpeechSynthesizer(speechConfig); + }) + } + /*function getOpts(text, voiceId, style) { + switch (style) { + case "newscaster": + return { + OutputFormat: "mp3", + Text: '' + escapeXml(text) + '', + TextType: "ssml", + VoiceId: voiceId, + Engine: "neural" + } + case "conversational": + return { + OutputFormat: "mp3", + Text: '' + escapeXml(text) + '', + TextType: "ssml", + VoiceId: voiceId, + Engine: "neural" + } + case "neural": + return { + OutputFormat: "mp3", + Text: text, + VoiceId: voiceId, + Engine: "neural" + } + default: + return { + OutputFormat: "mp3", + Text: text, + VoiceId: voiceId + } + } + } + function escapeXml(unsafe) { + return unsafe.replace(/[<>&'"]/g, function (c) { + switch (c) { + case '<': return '<'; + case '>': return '>'; + case '&': return '&'; + case '\'': return '''; + case '"': return '"'; + } + }) + }*/ + var voices = [ + {"voiceName":"Azure default voice","lang":"en-US","gender":"female"} + ] +} + + function BrowserTtsEngine() { this.speak = function(text, options, onEvent) { brapi.tts.speak(text, { diff --git a/manifest.json b/manifest.json index f20c9838..f16f3fd4 100644 --- a/manifest.json +++ b/manifest.json @@ -51,7 +51,8 @@ "js/tts-engines.js", "js/speech.js", "js/document.js", - "js/events.js" + "js/events.js", + "js/microsoft.cognitiveservices.speech.sdk.bundle-min.js" ], "persistent": false }, diff --git a/options.html b/options.html index 4ca613fc..648ddbf9 100644 --- a/options.html +++ b/options.html @@ -8,6 +8,7 @@ +