@liascript/exporter
Version:
A generic exporter for LiaScript
2 lines (1 loc) • 3.1 kB
JavaScript
!function(){var e=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).parcelRequire55a5;e.register("9yLtK",(function(t,n){var r,i;r=t.exports,i=function(){return l},Object.defineProperty(r,"TextToSpeechWeb",{get:i,set:undefined,enumerable:!0,configurable:!0});var s=e("hnmIs"),u=e("9Klpk"),o=e("3bWnf"),a=e("kb0qF"),c=e("bWNdT"),h=e("32Euv"),l=function(e){"use strict";(0,a.default)(n,e);var t=(0,c.default)(n);function n(){var e;return(0,u.default)(this,n),(e=t.call(this)).speechSynthesis=null,"speechSynthesis"in window&&(e.speechSynthesis=window.speechSynthesis,window.addEventListener("beforeunload",(function(){e.stop()}))),e}return(0,o.default)(n,[{key:"speak",value:function(e){var t=this;return(0,s.default)((function(){var n,r;return(0,h.__generator)(this,(function(i){switch(i.label){case 0:return t.speechSynthesis||t.throwUnsupportedError(),[4,t.stop()];case 1:return i.sent(),n=t.speechSynthesis,r=t.createSpeechSynthesisUtterance(e),[2,new Promise((function(e,t){r.onend=function(){e()},r.onerror=function(e){t(e)},n.speak(r)}))]}}))}))()}},{key:"stop",value:function(){var e=this;return(0,s.default)((function(){return(0,h.__generator)(this,(function(t){return e.speechSynthesis||e.throwUnsupportedError(),e.speechSynthesis.cancel(),[2]}))}))()}},{key:"getSupportedLanguages",value:function(){var e=this;return(0,s.default)((function(){var t,n,r;return(0,h.__generator)(this,(function(i){return t=e.getSpeechSynthesisVoices(),n=t.map((function(e){return e.lang})),r=n.filter((function(e,t,n){return n.indexOf(e)==t})),[2,{languages:r}]}))}))()}},{key:"getSupportedVoices",value:function(){var e=this;return(0,s.default)((function(){return(0,h.__generator)(this,(function(t){return[2,{voices:e.getSpeechSynthesisVoices()}]}))}))()}},{key:"isLanguageSupported",value:function(e){var t=this;return(0,s.default)((function(){return(0,h.__generator)(this,(function(n){switch(n.label){case 0:return[4,t.getSupportedLanguages()];case 1:return[2,{supported:n.sent().languages.includes(e.lang)}]}}))}))()}},{key:"openInstall",value:function(){var e=this;return(0,s.default)((function(){return(0,h.__generator)(this,(function(t){return e.throwUnimplementedError(),[2]}))}))()}},{key:"createSpeechSynthesisUtterance",value:function(e){var t=this.getSpeechSynthesisVoices(),n=new SpeechSynthesisUtterance,r=e.text,i=e.lang,s=e.rate,u=e.pitch,o=e.volume,a=e.voice;return a&&(n.voice=t[a]),o&&(n.volume=o>=0&&o<=1?o:1),s&&(n.rate=s>=.1&&s<=10?s:1),u&&(n.pitch=u>=0&&u<=2?u:2),i&&(n.lang=i),n.text=r,n}},{key:"getSpeechSynthesisVoices",value:function(){return this.speechSynthesis||this.throwUnsupportedError(),(!this.supportedVoices||this.supportedVoices.length<1)&&(this.supportedVoices=this.speechSynthesis.getVoices()),this.supportedVoices}},{key:"throwUnsupportedError",value:function(){throw this.unavailable("SpeechSynthesis API not available in this browser.")}},{key:"throwUnimplementedError",value:function(){throw this.unimplemented("Not implemented on web.")}}]),n}(e("4MteB").WebPlugin)}))}();