Advertisement
12Me21

tts

May 19th, 2019
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. var synth = window.speechSynthesis;
  2. var readIncoming = true; readOutgoing = true;
  3. var silent = true;
  4. window.speakrate = 3;
  5. window.speakpitch = 1.3;
  6. window.speakvoice = undefined;//synth.getVoices()[0];
  7. var prevMessages=[];
  8. window.speak=function(text,store,force){
  9.     if(store){
  10.         prevMessages.push(text);
  11.         if(prevMessages.length>100)
  12.             prevMessages=prevMessages.slice(1);
  13.     }
  14.     if (!silent && readIncoming || force){
  15.         var utterThis = new SpeechSynthesisUtterance(text.replace(/_/g," "));
  16.         utterThis.rate = speakrate;
  17.         utterThis.pitch = speakpitch;
  18.         utterThis.voice = speakvoice;
  19.         synth.speak(utterThis);
  20.        
  21.     }
  22. }
  23.  
  24. commands.push(new Command("tts", function(){
  25.    silent = !silent;
  26.    speak("reader is now " + (silent ? "off" : "on") + ". use /TTS help for help",false,true);
  27. }));
  28.  
  29. commands.push(new Command("ttsread", function(){
  30.    readIncoming = !readIncoming;
  31.    speak("incoming message reading is now " + (readIncoming ? "on" : "off") + ". use /TTS help for help",false,true);
  32. }));
  33.  
  34. commands.push(new Command("ttsrate", function(param){
  35.    window.speakrate = param.substr(1);
  36.    speak("tts speed is now" + window.speakrate);
  37. }));
  38.  
  39. commands.push(new Command("ttspitch", function(param){
  40.    window.speakpitch = param.substr(1);
  41.    speak("tts pitch is now" + window.speakpitch);
  42. }));
  43.  
  44. commands.push(new Command("re", function(param){
  45.    n = param.substr(1)||1;
  46.    speak(prevMessages[prevMessages.length-n]);
  47. }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement