Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var synth = window.speechSynthesis;
  2. oldtext="";
  3. newtext="";
  4. nextext="";
  5. function prepareText(s,f){
  6. var res="";
  7. //if(s==oldtext)return "";
  8.  nextext+=s.replace(oldtext,"");
  9. if(!f){
  10.  res=nextext;nextext="";}
  11.  oldtext=s;
  12. return res;
  13.  
  14. };
  15.  
  16.  rate =1.52;
  17. var voices = [];
  18.  
  19.   voices = synth.getVoices().sort(function (a, b) {
  20.       const aname = a.name.toUpperCase(), bname = b.name.toUpperCase();
  21.       if ( aname < bname ) return -1;
  22.       else if ( aname == bname ) return 0;
  23.       else return +1;
  24.   })
  25.  
  26.  
  27.  
  28. function speak(text){
  29.     if (synth.speaking||text=="") {
  30.    
  31.         return;
  32.     }
  33.  
  34.     var utterThis = new SpeechSynthesisUtterance(text);
  35.     utterThis.onend = function (event) {
  36.          
  37.     }
  38.    
  39.     utterThis.onerror = function (event) {
  40.    
  41.         console.error('SpeechSynthesisUtterance.onerror');
  42.     }
  43.  
  44.         utterThis.voice = voices[1];        //Голос
  45.      
  46.     utterThis.pitch = 1; //высота    
  47.     utterThis.rate = rate;     //скорост?
  48.     synth.speak(utterThis);
  49.    
  50.      
  51. }
  52.  
  53.  
  54. document.styleSheets[0].insertRule(".caption-window {display:none}")
  55. setInterval(function(){
  56.  
  57. if(document.getElementsByClassName('ytp-caption-segment').length>0){
  58.     newtext=document.getElementsByClassName('ytp-caption-segment')[document.getElementsByClassName('ytp-caption-segment').length-1].innerText.replace(/[\n\t]/gi," ");
  59.     speak(prepareText(newtext,synth.speaking)); document.title=nextext;
  60. }
  61. },100);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement