var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{c:()=>a});var n=function(){function e(){}return e.prototype.appendPickerHTMLtoChatWindowFooter=function(e){this.hostInstance.chatEle.find(".kore-chat-footer .footerContainer").append(e)},e.prototype.installTextToSpeechTemplate=function(){var e=this,t=e.hostInstance.$;e.pickerHTML=t(e.getTextToSpeechTemplateString()),e.appendPickerHTMLtoChatWindowFooter(e.pickerHTML),e.bindEvents()},e.prototype.getTextToSpeechTemplateString=function(){return'<div class="sdkFooterIcon ttspeakerDiv ttsOff">         <button class="ttspeaker" title="Talk to speak">             <span class="ttsSpeakerEnable"></span>             <span class="ttsSpeakerDisable"></span>             <span style="display:none;"><audio id="ttspeaker" controls="" autoplay="" name="media"><source src="" type="audio/wav"></audio></span>        </button>     </div> '},e.prototype.bindEvents=function(){var e=this;(0,e.hostInstance.$)(e.pickerHTML).on("click",".ttspeaker",(function(t){e.OnSpeakerButtonClick&&e.OnSpeakerButtonClick()}))},e}();var o,s=(o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},o(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});const a=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="BrowserTTS",t.audioMsgs=[],t.audioPlaying=!1,t}return s(t,e),t.prototype.onHostCreate=function(){var e=this,t=e.hostInstance;t.on("viewInit",(function(t){e.onInit()})),t.on("onKeyDown",(function(t){t&&13==t.event.keyCode&&e.stop()})),t.on("beforeViewInit",(function(t){var n,o,s;null===(n=t.chatEle.find(".close-btn"))||void 0===n||n.on("click",(function(){e.stop()})),null===(o=t.chatEle.find(".reload-btn"))||void 0===o||o.on("click",(function(){e.stop()})),null===(s=t.chatEle.find(".minimize-btn"))||void 0===s||s.on("click",(function(){e.stop()}))}))},t.prototype.onInit=function(){var e=this;e.installTextToSpeechTemplate(),window.addEventListener("beforeunload",(function(t){e.stop()}))},t.prototype.OnSpeakerButtonClick=function(){var e=this,t=this,n=t.hostInstance.$,o=t.hostInstance;n(".ttspeakerDiv").hasClass("ttsOff")?(n(".ttspeakerDiv").removeClass("ttsOff"),o.on("afterRenderMessage",(function(n){var o=n.msgData;if("bot_response"===(null==o?void 0:o.type)&&!t.hostInstance.minimized&&!t.hostInstance.historyLoading&&!o.fromHistorySync){if(o.message[0]&&o.message[0].component&&o.message[0].component.payload&&"live_agent"===o.message[0].component.payload.template_type&&o.message[0].component.payload.text)e._txtToSpeak=o.message[0].component.payload.text;else if(o.message[0]&&o.message[0].component&&"object"!=typeof o.message[0].component)e._txtToSpeak=o.message[0].component;else if(o.message[0]&&o.message[0].component&&"template"===o.message[0].component.type)e._txtToSpeak="";else try{e._txtToSpeak=o.message[0].component.payload.text?o.message[0].component.payload.text.replace(/\r?\n/g,". ."):"",e._txtToSpeak=t.hostInstance.helpers.checkMarkdowns(e._txtToSpeak),e._txtToSpeak=e._txtToSpeak.replace("___","<hr/>"),e._txtToSpeak=e._txtToSpeak.replace("---","<hr/>")}catch(t){e._txtToSpeak=""}o.message[0].component&&o.message[0].component.payload.speech_hint&&(e._txtToSpeak=o.message[0].component.payload.speech_hint),e.speakWithWebAPI(e._txtToSpeak)}}))):(window.speechSynthesis.pause(),n(".ttspeakerDiv").addClass("ttsOff"))},t.prototype.speakWithWebAPI=function(e){if(!e)return!1;"speechSynthesis"in window?(this.audioMsgs.push(e),this.playMessageSequence()):console.warn("KORE:Your browser doesn't support TTS(Speech Synthesiser)")},t.prototype.playMessageSequence=function(){var e=this;this.speechSyn||(this.speechSyn=new SpeechSynthesisUtterance),this.audioMsgs.length>0&&!this.audioPlaying&&(this.audioPlaying=!0,this.speechSyn.text=this.audioMsgs.shift(),window.speechSynthesis.speak(this.speechSyn),this.speechSyn.onend=function(){e.audioPlaying=!1,e.playMessageSequence()})},t.prototype.stop=function(){"speechSynthesis"in window&&(this.audioMsgs=[],this.audioPlaying=!1,window.speechSynthesis.cancel())},t}(n);var i=t.c;export{i as BrowserTTS};