UNPKG

@liascript/exporter

Version:
1 lines 1.97 kB
var e=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).parcelRequire55a5;e.register("7Ar6p",(function(t,s){var n,i,r,o;n=t.exports,i="TextToSpeechWeb",r=function(){return p},Object.defineProperty(n,i,{get:r,set:o,enumerable:!0,configurable:!0});var h=e("7VmO8");class p extends h.WebPlugin{async speak(e){this.speechSynthesis||this.throwUnsupportedError(),await this.stop();const t=this.speechSynthesis,s=this.createSpeechSynthesisUtterance(e);return new Promise(((e,n)=>{s.onend=()=>{e()},s.onerror=e=>{n(e)},t.speak(s)}))}async stop(){this.speechSynthesis||this.throwUnsupportedError(),this.speechSynthesis.cancel()}async getSupportedLanguages(){const e=this.getSpeechSynthesisVoices().map((e=>e.lang)).filter(((e,t,s)=>s.indexOf(e)==t));return{languages:e}}async getSupportedVoices(){return{voices:this.getSpeechSynthesisVoices()}}async isLanguageSupported(e){return{supported:(await this.getSupportedLanguages()).languages.includes(e.lang)}}async openInstall(){this.throwUnimplementedError()}createSpeechSynthesisUtterance(e){const t=this.getSpeechSynthesisVoices(),s=new SpeechSynthesisUtterance,{text:n,lang:i,rate:r,pitch:o,volume:h,voice:p}=e;return p&&(s.voice=t[p]),h&&(s.volume=h>=0&&h<=1?h:1),r&&(s.rate=r>=.1&&r<=10?r:1),o&&(s.pitch=o>=0&&o<=2?o:2),i&&(s.lang=i),s.text=n,s}getSpeechSynthesisVoices(){return this.speechSynthesis||this.throwUnsupportedError(),(!this.supportedVoices||this.supportedVoices.length<1)&&(this.supportedVoices=this.speechSynthesis.getVoices()),this.supportedVoices}throwUnsupportedError(){throw this.unavailable("SpeechSynthesis API not available in this browser.")}throwUnimplementedError(){throw this.unimplemented("Not implemented on web.")}constructor(){super(),this.speechSynthesis=null,"speechSynthesis"in window&&(this.speechSynthesis=window.speechSynthesis,window.addEventListener("beforeunload",(()=>{this.stop()})))}}}));