-
Notifications
You must be signed in to change notification settings - Fork 2
/
polyfill.min.js
1 lines (1 loc) · 963 Bytes
/
polyfill.min.js
1
var polyfills={speechUtteranceChunker:function(e,t,n){var o,i=(t=t||{})&&void 0!==t.offset?e.text.substring(t.offset):e.text;if(e.voice&&"native"===e.voice.voiceURI)(o=e).text=i,o.addEventListener("end",function(){polyfills.speechUtteranceChunker.cancel&&(polyfills.speechUtteranceChunker.cancel=!1),void 0!==n&&n()});else{var s=t&&t.chunkLength||160,c=new RegExp("^[\\s\\S]{"+Math.floor(s/2)+","+s+"}[.!?,]{1}|^[\\s\\S]{1,"+s+"}$|^[\\s\\S]{1,"+s+"} "),r=i.match(c);if(void 0===r[0]||r[0].length<=2)return void(void 0!==n&&n());var l,f=r[0];for(l in o=new SpeechSynthesisUtterance(f),e)e.hasOwnProperty(l)&&"text"!==l&&(o[l]=e[l]);o.addEventListener("end",function(){return polyfills.speechUtteranceChunker.cancel?void(polyfills.speechUtteranceChunker.cancel=!1):(t.offset=t.offset||0,t.offset+=f.length-1,void polyfills.speechUtteranceChunker(e,t,n))})}t.modifier&&t.modifier(o),console.log(o),setTimeout(function(){o.lang="en-US",speechSynthesis.speak(o)},0)}};