From b31e997ebd8128b836030232de8426a91cc2f95b Mon Sep 17 00:00:00 2001 From: jankapunkt Date: Tue, 16 Jan 2024 14:54:08 +0100 Subject: [PATCH] docs: updated demo --- docs/demo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/demo.js b/docs/demo.js index c2f6aa3..c1d0259 100644 --- a/docs/demo.js +++ b/docs/demo.js @@ -1 +1 @@ -!function(){"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function t(t){for(var n=1;n=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var u=i.call(a,"catchLoc"),s=i.call(a,"finallyLoc");if(u&&s){if(this.prev=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&i.call(r,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),C(n),m}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;C(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:A(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),m}},t}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function i(e,t,n,r,i,o,a){try{var c=e[o](a),u=c.value}catch(e){return void n(e)}c.done?t(u):Promise.resolve(u).then(r,i)}function o(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function c(e){i(a,r,o,c,u,"next",e)}function u(e){i(a,r,o,c,u,"throw",e)}c(void 0)}))}}function a(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){if(null==e)return{};var n,r,i=function(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,o,a,c=[],u=!0,s=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;u=!1}else for(;!(u=(r=o.call(n)).done)&&(c.push(r.value),c.length!==t);u=!0);}catch(e){s=!0,i=e}finally{try{if(!u&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(s)throw i}}return c}}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return s(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0;return Object.hasOwnProperty.call(e,t)||t in e||!!e[t]},g=function(){return(d.navigator||{}).userAgent||""},b=function(){return/android/i.test(g())},w=function(){return/kaios/i.test(g())},S=function(){return void 0!==d.InstallTrigger||/firefox/i.test(g())},x=function(){return void 0!==d.GestureEvent},E=["webKit","moz","ms","o"],L=function(e){var t,n="".concat((t=e).charAt(0).toUpperCase()).concat(t.slice(1)),r=E.map((function(e){return"".concat(e).concat(n)})),i=[e,n].concat(r).find(O);return d[i]},O=function(e){return d[e]};f.status=function(){return t({},v)},f.filterVoices=function(e){var t=e.name,n=e.language,r=e.localService,i=e.voiceURI,o=v.voices||[],a=void 0!==t,c=void 0!==i,u=void 0!==r,s=void 0!==n,l=s&&n.split(/[-_]+/g)[0].toLocaleLowerCase();return o.filter((function(e){if(a&&e.name.includes(t)||c&&e.voiceURI.includes(i)||u&&e.localService===r)return!0;if(s){var n=e.lang&&e.lang.toLocaleLowerCase();return n&&(n===l||n.indexOf("".concat(l,"-"))>-1||n.indexOf("".concat(l,"_"))>-1)}return!1}))};var j=function(e){p(e),v.status=e};f.init=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.maxTimeout,n=void 0===t?5e3:t,r=e.interval,i=void 0===r?250:r,o=e.quiet,a=e.maxLengthExceeded;return new Promise((function(e,t){if(v.initialized)return e(!1);var r,c;f.reset(),j("init: start");var u=!1;v.maxLengthExceeded=a||"warn";var s=function(n){return j("init: failed (".concat(n,")")),clearInterval(r),v.initialized=!1,o?e(!1):t(new Error("EasySpeech: ".concat(n)))},l=function(){if(!u)return j("init: complete"),u=!0,v.initialized=!0,clearInterval(r),p.onvoiceschanged=null,c&&p.removeEventListener("voiceschanged",c),e(!0)},h=y();if(!(!!h.speechSynthesis&&!!h.speechSynthesisUtterance))return s("browser misses features");Object.keys(h).forEach((function(e){v[e]=h[e]}));var p=v.speechSynthesis,g=function(){var e=p.getVoices()||[];if(e.length>0){if(v.voices=e,j("voices loaded: ".concat(e.length)),v.defaultVoice=e.find((function(e){return e.default})),!v.defaultVoice){var t=(d.navigator||{}).language||"",n=f.filterVoices({language:t});n.length>0&&(v.defaultVoice=n[0])}return v.defaultVoice||(v.defaultVoice=e[0]),!0}return!1};if(j("init: voices"),g())return l();var b=function(){j("init: voices (timer)");var e=0;r=setInterval((function(){return g()?l():e>n?s("browser has no voices (timeout)"):void(e+=i)}),i)};h.onvoiceschanged?(j("init: voices (onvoiceschanged)"),p.onvoiceschanged=function(){return g()?l():b()},setTimeout((function(){return g()?l():s("browser has no voices (timeout)")}),n)):(m(p,"addEventListener")&&(j("init: voices (addEventListener)"),c=function(){if(g())return l()},p.addEventListener("voiceschanged",c)),b())}))};var k=function(){if(!(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).force&&!v.initialized)throw new Error("EasySpeech: not initialized. Run EasySpeech.init() first")};f.voices=function(){return k(),v.voices},f.on=function(e){return k(),T.forEach((function(t){var n=e[t];N.handler(n)&&(v.handlers[t]=n)})),t({},v.handlers)};var T=["boundary","end","error","mark","pause","resume","start"],N={isNumber:function(e){return"number"==typeof e&&!Number.isNaN(e)},pitch:function(e){return N.isNumber(e)&&e>=0&&e<=2},volume:function(e){return N.isNumber(e)&&e>=0&&e<=1},rate:function(e){return N.isNumber(e)&&e>=.1&&e<=10},text:function(e){return"string"==typeof e},handler:function(e){return"function"==typeof e},voice:function(e){return e&&e.lang&&e.name&&e.voiceURI}};f.defaults=function(e){return k(),e&&(v.defaults=v.defaults||{},["voice","pitch","rate","volume"].forEach((function(t){var n=e[t];(0,N[t])(n)&&(v.defaults[t]=n)}))),t({},v.defaults)};f.speak=function(e){var t=e.text,n=e.voice,r=e.pitch,i=e.rate,o=e.volume,a=e.force,s=e.infiniteResume,f=c(e,l);if(k({force:a}),!N.text(t))throw new Error("EasySpeech: at least some valid text is required to speak");if((new TextEncoder).encode(t).length>4096){var d="EasySpeech: text exceeds max length of 4096 bytes, which will not work with some voices.";switch(v.maxLengthExceeded){case"none":break;case"error":throw new Error(d);default:console.warn(d)}}var y=function(e){var t,n=u(Object.entries(e)[0],2),r=n[0],i=n[1];return N[r](i)?i:null===(t=v.defaults)||void 0===t?void 0:t[r]};return new Promise((function(e,a){j("init speak");var c=function(e){return new(0,v.speechSynthesisUtterance)(e)}(t),u=function(e){var t,n;return e||(null===(t=v.defaults)||void 0===t?void 0:t.voice)||v.defaultVoice||(null===(n=v.voices)||void 0===n?void 0:n[0])}(n);u&&(c.voice=u,c.lang=u.lang,c.voiceURI=u.voiceURI),c.text=t,c.pitch=y({pitch:r}),c.rate=y({rate:i}),c.volume=y({volume:o}),I(c);var l=c.voice&&c.voice.name&&c.voice.name.toLocaleLowerCase().includes("(natural)");p("is MS (Natural)",l),T.forEach((function(e){var t,n=f[e];N.handler(n)&&c.addEventListener(e,n),null!==(t=v.handlers)&&void 0!==t&&t[e]&&c.addEventListener(e,v.handlers[e])})),c.addEventListener("start",(function(){h.paused=!1,h.speaking=!0,("boolean"==typeof s?s:!h.isFirefox&&!h.isSafari&&!0!==h.isAndroid)&&q(c)})),c.addEventListener("end",(function(t){j("speak complete"),h.paused=!1,h.speaking=!1,clearTimeout(C),e(t)})),c.addEventListener("error",(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};j("speak failed: ".concat(e.message)),h.paused=!1,h.speaking=!1,clearTimeout(C),a(e)})),clearTimeout(C),v.speechSynthesis.cancel();var d=function(){return v.speechSynthesis.speak(c)};l?d():setTimeout(d,10)}))};var C,P,A,I=function(e){var t=e.voice,n=e.pitch,r=e.rate,i=e.volume;p("utterance: voice=".concat(null==t?void 0:t.name," volume=").concat(i," rate=").concat(r," pitch=").concat(n))};function q(e){if(!e&&C)return p("force-clear timeout"),d.clearTimeout(C);var t=v.speechSynthesis,n=t.paused,r=t.speaking||h.speaking,i=n||h.paused;p("resumeInfinity isSpeaking=".concat(r," isPaused=").concat(i)),r&&!i&&(v.speechSynthesis.pause(),v.speechSynthesis.resume()),C=d.setTimeout((function(){q(e)}),5e3)}f.cancel=function(){k(),j("cancelling"),v.speechSynthesis.cancel(),h.paused=!1,h.speaking=!1},f.resume=function(){k(),j("resuming"),h.paused=!1,h.speaking=!0,v.speechSynthesis.resume()},f.pause=function(){if(k(),j("pausing"),h.isAndroid)return p("patch pause on Android with cancel"),v.speechSynthesis.cancel();v.speechSynthesis.pause(),h.paused=!0,h.speaking=!1},f.reset=function(){Object.assign(v,{status:"reset",initialized:!1,speechSynthesis:null,speechSynthesisUtterance:null,speechSynthesisVoice:null,speechSynthesisEvent:null,speechSynthesisErrorEvent:null,voices:null,defaultVoice:null,defaults:{pitch:1,rate:1,volume:1,voice:null},handlers:{}})},document.body.onload=o(n().mark((function e(){var t;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return R(),f.debug(F),$(f.detect()),e.next=5,z();case 5:return t=e.sent,e.next=8,D(t);case 8:return V(t),e.next=11,K(t);case 11:B(t),window.EasySpeech=f;case 13:case"end":return e.stop()}}),e)})));var U={voice:void 0,rate:void 0,pitch:void 0,volume:void 0,text:void 0},_={volume:void 0,rate:void 0,pitch:void 0,text:void 0,language:void 0,voice:void 0};function V(e){if(e){F("init volume input");var t=document.querySelector(".volume-value");_.volume=document.querySelector("#volume-input"),_.volume.disabled=!1,_.volume.addEventListener("change",(function(e){U.volume=Number(e.target.value),t.removeChild(t.firstChild),t.appendChild(document.createTextNode(U.volume))})),F("init rate input");var n=document.querySelector(".rate-value");_.rate=document.querySelector("#rate-input"),_.rate.disabled=!1,_.rate.addEventListener("change",(function(e){U.rate=Number(e.target.value)/10,n.removeChild(n.firstChild),n.appendChild(document.createTextNode(U.rate))})),F("init pitch input");var r=document.querySelector(".pitch-value");_.pitch=document.querySelector("#pitch-input"),_.pitch.disabled=!1,_.pitch.addEventListener("change",(function(e){U.pitch=Number(e.target.value),r.removeChild(r.firstChild),r.appendChild(document.createTextNode(U.pitch))})),_.text=document.querySelector("#text-input"),_.text.disabled=!1}}function R(){P=document.querySelector(".log-body"),f.debug(F)}function F(){for(var e=arguments.length,t=new Array(e),n=0;nA.length-1)return U.voice=void 0,void F("no voice found by index",e);U.voice=(A||[])[e],F("select voice",U.voice&&U.voice.name)}function K(e){if(e){var r=document.querySelector(".speak-btn"),i=Object.values(_);r.addEventListener("click",function(){var e=o(n().mark((function e(o){var a,c,u,s,l,d;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r.disabled=!0,i.forEach((function(e){e.disabled=!0})),a=t({},U),c=a.pitch,u=a.rate,s=a.voice,l=a.volume,d=_.text.value,e.prev=4,e.next=7,f.speak({text:d,pitch:c,rate:u,voice:s,volume:l});case 7:e.next=12;break;case 9:e.prev=9,e.t0=e.catch(4),F(e.t0.message);case 12:return e.prev=12,r.disabled=!1,i.forEach((function(e){e.disabled=!1})),e.finish(12);case 16:case"end":return e.stop()}}),e,null,[[4,9,12,16]])})));return function(t){return e.apply(this,arguments)}}())}}function $(e){var t=document.querySelector(".features"),n={};Object.entries(e).forEach((function(e){var t=u(e,2),i=t[0],o=t[1];"object"===r(o)?n[i]=o.toString():n[i]="function"==typeof o?o.name:o}));var i=document.createTextNode(JSON.stringify(n,null,2));t.appendChild(i)}function B(e){if(e){var t=function(e){return F("event: ".concat(e.type))};f.on({boundary:t,start:t,end:t,error:function(e){console.error(e),F("error: ".concat(e.message))}})}}var H=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"div",n=document.createElement(t);return n.appendChild(document.createTextNode(e)),n}}(); +!function(){"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function t(t){for(var n=1;n=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var u=i.call(a,"catchLoc"),s=i.call(a,"finallyLoc");if(u&&s){if(this.prev=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&i.call(r,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),C(n),m}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;C(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:A(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),m}},t}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function i(e,t,n,r,i,o,a){try{var c=e[o](a),u=c.value}catch(e){return void n(e)}c.done?t(u):Promise.resolve(u).then(r,i)}function o(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function c(e){i(a,r,o,c,u,"next",e)}function u(e){i(a,r,o,c,u,"throw",e)}c(void 0)}))}}function a(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){if(null==e)return{};var n,r,i=function(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(r=0;r=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,o,a,c=[],u=!0,s=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;u=!1}else for(;!(u=(r=o.call(n)).done)&&(c.push(r.value),c.length!==t);u=!0);}catch(e){s=!0,i=e}finally{try{if(!u&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(s)throw i}}return c}}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return s(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0;return Object.hasOwnProperty.call(e,t)||t in e||!!e[t]},g=function(){return(d.navigator||{}).userAgent||""},b=function(){return/android/i.test(g())},w=function(){return/kaios/i.test(g())},S=function(){return void 0!==d.InstallTrigger||/firefox/i.test(g())},x=function(){return void 0!==d.GestureEvent},E=["webKit","moz","ms","o"],L=function(e){var t,n="".concat((t=e).charAt(0).toUpperCase()).concat(t.slice(1)),r=E.map((function(e){return"".concat(e).concat(n)})),i=[e,n].concat(r).find(O);return d[i]},O=function(e){return d[e]};f.status=function(){return t({},v)},f.filterVoices=function(e){var t=e.name,n=e.language,r=e.localService,i=e.voiceURI,o=v.voices||[],a=void 0!==t,c=void 0!==i,u=void 0!==r,s=void 0!==n,l=s&&n.split(/[-_]+/g)[0].toLocaleLowerCase();return o.filter((function(e){if(a&&e.name.includes(t)||c&&e.voiceURI.includes(i)||u&&e.localService===r)return!0;if(s){var n=e.lang&&e.lang.toLocaleLowerCase();return n&&(n===l||n.indexOf("".concat(l,"-"))>-1||n.indexOf("".concat(l,"_"))>-1)}return!1}))};var j=function(e){p(e),v.status=e};f.init=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.maxTimeout,n=void 0===t?5e3:t,r=e.interval,i=void 0===r?250:r,o=e.quiet,a=e.maxLengthExceeded;return new Promise((function(e,t){if(v.initialized)return e(!1);var r,c;f.reset(),j("init: start");var u=!1;v.maxLengthExceeded=a||"warn";var s=function(n){return j("init: failed (".concat(n,")")),clearInterval(r),v.initialized=!1,o?e(!1):t(new Error("EasySpeech: ".concat(n)))},l=function(){if(!u)return j("init: complete"),u=!0,v.initialized=!0,clearInterval(r),p.onvoiceschanged=null,c&&p.removeEventListener("voiceschanged",c),e(!0)},h=y();if(!(!!h.speechSynthesis&&!!h.speechSynthesisUtterance))return s("browser misses features");Object.keys(h).forEach((function(e){v[e]=h[e]}));var p=v.speechSynthesis,g=function(){var e=p.getVoices()||[];if(e.length>0){if(v.voices=e,j("voices loaded: ".concat(e.length)),v.defaultVoice=e.find((function(e){return e.default})),!v.defaultVoice){var t=(d.navigator||{}).language||"",n=f.filterVoices({language:t});n.length>0&&(v.defaultVoice=n[0])}return v.defaultVoice||(v.defaultVoice=e[0]),!0}return!1};if(j("init: voices"),g())return l();var b=function(){j("init: voices (timer)");var e=0;r=setInterval((function(){return g()?l():e>n?s("browser has no voices (timeout)"):void(e+=i)}),i)};h.onvoiceschanged?(j("init: voices (onvoiceschanged)"),p.onvoiceschanged=function(){return g()?l():b()},setTimeout((function(){return g()?l():s("browser has no voices (timeout)")}),n)):(m(p,"addEventListener")&&(j("init: voices (addEventListener)"),c=function(){if(g())return l()},p.addEventListener("voiceschanged",c)),b())}))};var k=function(){if(!(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).force&&!v.initialized)throw new Error("EasySpeech: not initialized. Run EasySpeech.init() first")};f.voices=function(){return k(),v.voices},f.on=function(e){return k(),N.forEach((function(t){var n=e[t];T.handler(n)&&(v.handlers[t]=n)})),t({},v.handlers)};var N=["boundary","end","error","mark","pause","resume","start"],T={isNumber:function(e){return"number"==typeof e&&!Number.isNaN(e)},pitch:function(e){return T.isNumber(e)&&e>=0&&e<=2},volume:function(e){return T.isNumber(e)&&e>=0&&e<=1},rate:function(e){return T.isNumber(e)&&e>=.1&&e<=10},text:function(e){return"string"==typeof e},handler:function(e){return"function"==typeof e},voice:function(e){return e&&e.lang&&e.name&&e.voiceURI}};f.defaults=function(e){return k(),e&&(v.defaults=v.defaults||{},["voice","pitch","rate","volume"].forEach((function(t){var n=e[t];(0,T[t])(n)&&(v.defaults[t]=n)}))),t({},v.defaults)};f.speak=function(e){var t=e.text,n=e.voice,r=e.pitch,i=e.rate,o=e.volume,a=e.force,s=e.infiniteResume,f=c(e,l);if(k({force:a}),!T.text(t))throw new Error("EasySpeech: at least some valid text is required to speak");if((new TextEncoder).encode(t).length>4096){var d="EasySpeech: text exceeds max length of 4096 bytes, which will not work with some voices.";switch(v.maxLengthExceeded){case"none":break;case"error":throw new Error(d);default:console.warn(d)}}var p=function(e){var t,n=u(Object.entries(e)[0],2),r=n[0],i=n[1];return T[r](i)?i:null===(t=v.defaults)||void 0===t?void 0:t[r]};return new Promise((function(e,a){j("init speak");var c=function(e){return new(0,v.speechSynthesisUtterance)(e)}(t),u=function(e){var t,n;return e||(null===(t=v.defaults)||void 0===t?void 0:t.voice)||v.defaultVoice||(null===(n=v.voices)||void 0===n?void 0:n[0])}(n);u&&(c.voice=u,c.lang=u.lang,c.voiceURI=u.voiceURI),c.text=t,c.pitch=p({pitch:r}),c.rate=p({rate:i}),c.volume=p({volume:o});var l=c.voice&&c.voice.name&&c.voice.name.toLocaleLowerCase().includes("(natural)");I(c,{isMsNatural:l}),N.forEach((function(e){var t,n=f[e];T.handler(n)&&c.addEventListener(e,n),null!==(t=v.handlers)&&void 0!==t&&t[e]&&c.addEventListener(e,v.handlers[e])})),c.addEventListener("start",(function(){h.paused=!1,h.speaking=!0,("boolean"==typeof s?s:!h.isFirefox&&!h.isSafari&&!0!==h.isAndroid)&&q(c)})),c.addEventListener("end",(function(t){j("speak complete"),h.paused=!1,h.speaking=!1,clearTimeout(C),e(t)})),c.addEventListener("error",(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};j("speak failed: ".concat(e.message)),h.paused=!1,h.speaking=!1,clearTimeout(C),a(e)})),clearTimeout(C),v.speechSynthesis.cancel();var d=function(){return v.speechSynthesis.speak(c)};l?d():setTimeout(d,10)}))};var C,P,A,I=function(e){var t=e.voice,n=e.pitch,r=e.rate,i=e.volume,o=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).isMsNatural,a=void 0!==o&&o;p("utterance: voice=".concat(null==t?void 0:t.name," volume=").concat(i," rate=").concat(r," pitch=").concat(n," isMsNatural=").concat(a))};function q(e){if(!e&&C)return p("force-clear timeout"),d.clearTimeout(C);var t=v.speechSynthesis,n=t.paused,r=t.speaking||h.speaking,i=n||h.paused;p("resumeInfinity isSpeaking=".concat(r," isPaused=").concat(i)),r&&!i&&(v.speechSynthesis.pause(),v.speechSynthesis.resume()),C=d.setTimeout((function(){q(e)}),5e3)}f.cancel=function(){k(),j("cancelling"),v.speechSynthesis.cancel(),h.paused=!1,h.speaking=!1},f.resume=function(){k(),j("resuming"),h.paused=!1,h.speaking=!0,v.speechSynthesis.resume()},f.pause=function(){if(k(),j("pausing"),h.isAndroid)return p("patch pause on Android with cancel"),v.speechSynthesis.cancel();v.speechSynthesis.pause(),h.paused=!0,h.speaking=!1},f.reset=function(){Object.assign(v,{status:"reset",initialized:!1,speechSynthesis:null,speechSynthesisUtterance:null,speechSynthesisVoice:null,speechSynthesisEvent:null,speechSynthesisErrorEvent:null,voices:null,defaultVoice:null,defaults:{pitch:1,rate:1,volume:1,voice:null},handlers:{}})},document.body.onload=o(n().mark((function e(){var t;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return R(),f.debug(F),$(f.detect()),e.next=5,z();case 5:return t=e.sent,e.next=8,D(t);case 8:return V(t),e.next=11,K(t);case 11:B(t),window.EasySpeech=f;case 13:case"end":return e.stop()}}),e)})));var U={voice:void 0,rate:void 0,pitch:void 0,volume:void 0,text:void 0},_={volume:void 0,rate:void 0,pitch:void 0,text:void 0,language:void 0,voice:void 0};function V(e){if(e){F("init volume input");var t=document.querySelector(".volume-value");_.volume=document.querySelector("#volume-input"),_.volume.disabled=!1,_.volume.addEventListener("change",(function(e){U.volume=Number(e.target.value),t.removeChild(t.firstChild),t.appendChild(document.createTextNode(U.volume))})),F("init rate input");var n=document.querySelector(".rate-value");_.rate=document.querySelector("#rate-input"),_.rate.disabled=!1,_.rate.addEventListener("change",(function(e){U.rate=Number(e.target.value)/10,n.removeChild(n.firstChild),n.appendChild(document.createTextNode(U.rate))})),F("init pitch input");var r=document.querySelector(".pitch-value");_.pitch=document.querySelector("#pitch-input"),_.pitch.disabled=!1,_.pitch.addEventListener("change",(function(e){U.pitch=Number(e.target.value),r.removeChild(r.firstChild),r.appendChild(document.createTextNode(U.pitch))})),_.text=document.querySelector("#text-input"),_.text.disabled=!1}}function R(){P=document.querySelector(".log-body"),f.debug(F)}function F(){for(var e=arguments.length,t=new Array(e),n=0;nA.length-1)return U.voice=void 0,void F("no voice found by index",e);U.voice=(A||[])[e],F("select voice",U.voice&&U.voice.name)}function K(e){if(e){var r=document.querySelector(".speak-btn"),i=Object.values(_);r.addEventListener("click",function(){var e=o(n().mark((function e(o){var a,c,u,s,l,d;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r.disabled=!0,i.forEach((function(e){e.disabled=!0})),a=t({},U),c=a.pitch,u=a.rate,s=a.voice,l=a.volume,d=_.text.value,e.prev=4,e.next=7,f.speak({text:d,pitch:c,rate:u,voice:s,volume:l});case 7:e.next=12;break;case 9:e.prev=9,e.t0=e.catch(4),F(e.t0.message);case 12:return e.prev=12,r.disabled=!1,i.forEach((function(e){e.disabled=!1})),e.finish(12);case 16:case"end":return e.stop()}}),e,null,[[4,9,12,16]])})));return function(t){return e.apply(this,arguments)}}())}}function $(e){var t=document.querySelector(".features"),n={};Object.entries(e).forEach((function(e){var t=u(e,2),i=t[0],o=t[1];"object"===r(o)?n[i]=o.toString():n[i]="function"==typeof o?o.name:o}));var i=document.createTextNode(JSON.stringify(n,null,2));t.appendChild(i)}function B(e){if(e){var t=function(e){return F("event: ".concat(e.type))};f.on({boundary:t,start:t,end:t,error:function(e){console.error(e),F("error: ".concat(e.message))}})}}var H=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"div",n=document.createElement(t);return n.appendChild(document.createTextNode(e)),n}}();