Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

190
LINES

< > BotCompany Repo | #1013936 // Katze/Computer [Invisible VM w/speech recognition module]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 4079K of libraries. Click here for Pure Java version (15118L/110K).

!7

static long attnTimeout = 10000;
sS denkmodulID = #1013938;

sS friendlySound = #1009564; //#1013870
sS angrySound = #1013884;
sS startUpSound = null; //#1013982;
sS defaultText = "Sorry";
sbool flatInfoBoxOnUtterance = true;

sS regexpActivator = "Katze|Katze|Katja|Götze|Qatar|Cookson|Captain|Cat|Kettle|Cut|Kurt|Computer";

static JTextArea ta;
static IVar<S> text;
static Class recognizer;
static Class denkmodul;
static long attention, skipTill;
sbool fullAttention;
sO speakFunction; // voidfunc(S)

p {
  if (isMain()) {
    substance();
    hideVMShowingConsole();
    outBuf(64K);
    autoRestart(10.0);
  }
  //javaSoundOnly(); // It just corrupts audio sometimes
  loadLibrary(#1013975);
  bot_ensureNotRunning("Katze.");
  recognizer = hotwireDependent(#1009816);
  //denkmodul = run(denkmodulID);
  if (nempty(denkmodulID))
    runInMCVarWithAutoRestart('denkmodul, denkmodulID, f denkmodulLoaded);
  //autoRestartModule('denkmodul, denkmodulID, true);
  
  if (isMain()) {
    text = persistentVar("Text");
    ta = fontSize(20, bindTextAreaToVar(text, jwordwraptextarea()));
    moveCaretToEnd(ta);
    //showFrame(ta);
  
    consoleIcon(#1101168);
    consoleMainContainer(); // cache it before changing layout
    //SingleComponentPanel scp = singleComponentPanel(); 
    //JSplitPane sp = jhsplit(ta, scp);
    //JPanel sp = jhgrid(ta, scp);
    //JTextArea cta = consoleTextArea();
    //replaceAWTComponent(cta, sp);
    //scp.setComponent(cta);
    //setSplitPaneLater(sp, 0.5);
    addToWindowLeftHalf(consoleFrame(), ta);
    doubleWindowSizeToTheLeft(consoleFrame());
    doubleWindowSizeToTheTop(consoleFrame());
  }
  
  set(recognizer, onFirstWebSocket := r {
    playMP3Snippet(startUpSound);    
  });

  set(recognizer, onUtterance := voidfunc(S utterance) {
    if (flatInfoBoxOnUtterance) flatInfoBox(utterance);
    if (ai_isStopListeningCommand(utterance)) {
      call(recognizer, 'stopRecognition);
      playBlip();
    }
    appendToTextAreaAndMoveCaret(ta, utterance + "\n");
    callAnswerMethodVerbose(utterance);
  });
  
  //set(recognizer, startRecognition := true);
  callMain(recognizer);
  //call(recognizer, 'switchToGerman);
}

sS answer(fS s) {
  if (sysNow() < skipTill) null;
  if (sysNow() >= attention+attnTimeout) attnOff();
  
  if (attention != 0) {
    attnOff();
    
    if "nichts|nix|vergiss es|nothing|forget it" {
      playWAVSnippet(#1013870);
    }
    
    try answer denk(s);
  }
  
  S reKatze;
  if (regexpICFind(reKatze = reKatze(), s)) {
    fullAttention = true;
    S rest;
    if (empty(reKatze) || eq(reKatze, ".")) rest = s; else {
      rest = regexpICLastGroup("(" + reKatze + ")(.*)", s);
    
      // e.g. "Computer[ ]spiel George Michael"
      if (startsWithLetter(rest) && !swic(rest, "spiel"))
        rest = trim(substring(rest, indexOf(rest, ' ')));
    }
    
    if (nempty(rest))
      try answer denk(rest);
    else {
      if (isShit(s))
        playMP3Snippet(angrySound);
      else
        playMP3Snippet(friendlySound);
      attention = sysNow();
      fullAttention = true;
      print("attn");
      ret "Yo";
    }
  }
  
  L<S> g = regexpGetGroups("(-?\\d+) x (-?\\d+)", s);
  if (g != null)
    ret speak_withBlip(str(parseLong(first(g))*parseLong(second(g))));
  
  null;
}

sbool isShit(S s) {
  ret regexpICFind("scheiß", s);
}

sS denk(S s) {
  print(">> " + s);
  
  S a = "Fehler";
  
  try {
    a = denk2(s);
  } catch e {
    if (eqic(getInnerMessage(e), "command stopped")) null;
    else printStackTrace(e);
  }
  
  if (empty(a)) {
    if (!fullAttention) null;
    a = defaultText;
  } else {
    attention = sysNow(); fullAttention = false;
    print("half attn");
  }
  
  skipTill = sysNow()+60000;
  try {
    speak_withBlip(a);
  } finally {
    skipTill = sysNow()+1000;
  }
  ret a;
}

sS denk2(S s) {
  if "neu" if (nempty(denkmodulID)) {
    upgradeModuleVar('denkmodul, denkmodulID, true);
    ret "OK";
  }
  
  print("Sending to denkmodul " + programID(denkmodul) + ": " + s);
  callOpt(denkmodul, 'setMsgGlobalID, getOpt(recognizer, 'lastGlobalID));
  S a = callAnswerFunction(denkmodul, s);
  print("Got: " + a);
  ret a;
}

svoid attnOff {
  if (attention == 0) ret;
  attention = 0;
  print("attn off");
}

sS speak_withBlip(S s) {
  if (speakFunction != null) {
    callF(speakFunction, s);
    ret s;
  } else
    ret speakInRecognizerLanguage/*_withBlip*/(s);
}

svoid denkmodulLoaded {
  setOpt(denkmodul, actions := true);
}

sS reKatze() {
  ret or((S) getOpt(denkmodul, 'regexpActivator), regexpActivator);
}

Author comment

Began life as a copy of #1013871

download  show line numbers  debug dex  old transpilations   

Travelled to 20 computer(s): anzfkgltbrzg, aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, oikenkqtkxpn, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, vpdwwinrgdga, xfbsdwenvhih, ydilcnlqtmvn

No comments. add comment

Snippet ID: #1013936
Snippet name: Katze/Computer [Invisible VM w/speech recognition module]
Eternal ID of this version: #1013936/102
Text MD5: 58c54aba9979f43e49cbec39d103d510
Transpilation MD5: 7fdb5301357a65cb9b86470afbed0128
Author: stefan
Category: javax / speech
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-05 13:42:42
Source code size: 4745 bytes / 190 lines
Pitched / IR pitched: No / No
Views / Downloads: 672 / 92661
Version history: 101 change(s)
Referenced in: [show references]