Advertisement
Guest User

speakSystem.js

a guest
May 30th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //ROUGH TTS SYSTEM PHANTOMBOT
  2. /**
  3.  *
  4.  *  Base64 encode / decode
  5.  *  http://www.webtoolkit.info/
  6.  * ADAPTED TO NOT INCLUDE DECODE (NOT NEEDED).
  7.  *
  8.  **/
  9. var Base64 = {
  10.     // private property
  11.     _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
  12.     // public method for encoding
  13.     encode : function (input) {
  14.         var output = "";
  15.         var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
  16.         var i = 0;
  17.         input = Base64._utf8_encode(input);
  18.         while (i < input.length) {
  19.             chr1 = input.charCodeAt(i++);
  20.             chr2 = input.charCodeAt(i++);
  21.             chr3 = input.charCodeAt(i++);
  22.             enc1 = chr1 >> 2;
  23.             enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
  24.             enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
  25.             enc4 = chr3 & 63;
  26.             if (isNaN(chr2)) {
  27.                 enc3 = enc4 = 64;
  28.             } else if (isNaN(chr3)) {
  29.                 enc4 = 64;
  30.             }
  31.             output = output +
  32.              this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
  33.              this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
  34.         }
  35.         return output;
  36.     },
  37.     // private method for UTF-8 encoding
  38.     _utf8_encode : function (string) {
  39.         string = string.replace('/\r\n/g',"\n");
  40.         var utftext = "";
  41.         for (var n = 0; n < string.length; n++) {
  42.             var c = string.charCodeAt(n);
  43.             if (c < 128) {
  44.                 utftext += String.fromCharCode(c);
  45.             }
  46.             else if((c > 127) && (c < 2048)) {
  47.                 utftext += String.fromCharCode((c >> 6) | 192);
  48.                 utftext += String.fromCharCode((c & 63) | 128);
  49.             }
  50.             else {
  51.                 utftext += String.fromCharCode((c >> 12) | 224);
  52.                 utftext += String.fromCharCode(((c >> 6) & 63) | 128);
  53.                 utftext += String.fromCharCode((c & 63) | 128);
  54.             }
  55.         }
  56.         return utftext;
  57.     }
  58. }
  59.  
  60. //Create text to speech object.
  61. //Heavily addapted from Iconica Bizau's TTS: https://github.com/IonicaBizau/text-to-speech-js
  62. var TTS = {
  63.     speak: function(inputText){//Define function getting & playing TTS
  64.     var speechText = "<voice>" + inputText;
  65.     //Post speech text.
  66.     $.panelsocketserver.alertImage(speechText);
  67.     }
  68. };
  69. //Adding text to speech to PhantomBot
  70. (function(){
  71.     //Define function calling tts.
  72.     function speak(textToSpeak){
  73.     TTS.speak(textToSpeak);
  74.     }
  75.     //Bind tts to a command.
  76.     $.bind('command',function(event){
  77.         var concatedArgs = "";
  78.         var allArgs = event.getArgs();
  79.         for (i = 0; i < allArgs.length; i++){
  80.             concatedArgs += allArgs[i] + " ";
  81.         }
  82.     var command = event.getCommand(),
  83.         inputText = concatedArgs;
  84.     //Check command.
  85.     if (command.equalsIgnoreCase('shout')){
  86.         speak(inputText);
  87.     }
  88.     });
  89.     //Register command.
  90.     $.bind('initReady',function(){
  91.         if($.bot.isModuleEnabled('./systems/speakSystem.js')){
  92.         $.registerChatCommand('./systems/speakSystem.js','shout',7);
  93.         }
  94.     });
  95. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement