Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var synth = window.speechSynthesis;
- oldtext="";
- newtext="";
- nextext="";
- function prepareText(s,f){
- var res="";
- //if(s==oldtext)return "";
- nextext+=s.replace(oldtext,"");
- if(!f){
- res=nextext;nextext="";}
- oldtext=s;
- return res;
- };
- rate =1.52;
- var voices = [];
- voices = synth.getVoices().sort(function (a, b) {
- const aname = a.name.toUpperCase(), bname = b.name.toUpperCase();
- if ( aname < bname ) return -1;
- else if ( aname == bname ) return 0;
- else return +1;
- })
- function speak(text){
- if (synth.speaking||text=="") {
- return;
- }
- var utterThis = new SpeechSynthesisUtterance(text);
- utterThis.onend = function (event) {
- }
- utterThis.onerror = function (event) {
- console.error('SpeechSynthesisUtterance.onerror');
- }
- utterThis.voice = voices[1]; //Голос
- utterThis.pitch = 1; //высота
- utterThis.rate = rate; //скорост?
- synth.speak(utterThis);
- }
- document.styleSheets[0].insertRule(".caption-window {display:none}")
- setInterval(function(){
- if(document.getElementsByClassName('ytp-caption-segment').length>0){
- newtext=document.getElementsByClassName('ytp-caption-segment')[document.getElementsByClassName('ytp-caption-segment').length-1].innerText.replace(/[\n\t]/gi," ");
- speak(prepareText(newtext,synth.speaking)); document.title=nextext;
- }
- },100);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement