nitor-tts
Version:
Browser TTS (using Web speech API) made easy
2 lines • 1.81 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("nitor-tts",["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["nitor-tts"]={})}(this,(function(e){"use strict";var t=function(){function e(){this.speech=new SpeechSynthesisUtterance,window.speechSynthesis.getVoices()}return e.prototype.hasbrowserSupport=function(){return this.browserSupport="speechSynthesis"in window&&"SpeechSynthesisUtterance"in window},e.prototype.init=function(e,t,i,s,n){if(this.voices=window.speechSynthesis.getVoices(),this.voices.filter((function(t){return t.name==e}))[0])this.speech.voice=this.voices.filter((function(t){return t.name==e}))[0];else{if(!this.voices[0])throw"Error setting voice. The voice you passed is not valid or the voices have not been loaded yet.";this.speech.voice=this.voices[0]}if(this.speech.lang=t,null!=i){if(!(i>=0&&i<=1))throw"Error setting volume. Please verify your volume value is a number between 0 and 1.";this.speech.volume=i}if(null!=s){if(!(s>=0&&s<=10))throw"Error setting rate. Please verify your volume value is a number between 0 and 10.";this.speech.rate=s}if(null!=n){if(!(n>=0&&n<=2))throw"Error setting pitch. Please verify your pitch value is a number between 0 and 2.";this.speech.pitch=n}},e.prototype.speak=function(e){this.speech.text=e,window.speechSynthesis.speak(this.speech)},e.prototype.paused=function(){return speechSynthesis.paused},e.prototype.speaking=function(){return speechSynthesis.speaking},e.prototype.pause=function(){speechSynthesis.pause()},e.prototype.resume=function(){speechSynthesis.resume()},e.prototype.cancel=function(){speechSynthesis.cancel()},e}();e.NitorTTS=t,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=nitor-tts.umd.min.js.map