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).

1  
!7
2  
3  
static long attnTimeout = 10000;
4  
sS denkmodulID = #1013938;
5  
6  
sS friendlySound = #1009564; //#1013870
7  
sS angrySound = #1013884;
8  
sS startUpSound = null; //#1013982;
9  
sS defaultText = "Sorry";
10  
sbool flatInfoBoxOnUtterance = true;
11  
12  
sS regexpActivator = "Katze|Katze|Katja|Götze|Qatar|Cookson|Captain|Cat|Kettle|Cut|Kurt|Computer";
13  
14  
static JTextArea ta;
15  
static IVar<S> text;
16  
static Class recognizer;
17  
static Class denkmodul;
18  
static long attention, skipTill;
19  
sbool fullAttention;
20  
sO speakFunction; // voidfunc(S)
21  
22  
p {
23  
  if (isMain()) {
24  
    substance();
25  
    hideVMShowingConsole();
26  
    outBuf(64K);
27  
    autoRestart(10.0);
28  
  }
29  
  //javaSoundOnly(); // It just corrupts audio sometimes
30  
  loadLibrary(#1013975);
31  
  bot_ensureNotRunning("Katze.");
32  
  recognizer = hotwireDependent(#1009816);
33  
  //denkmodul = run(denkmodulID);
34  
  if (nempty(denkmodulID))
35  
    runInMCVarWithAutoRestart('denkmodul, denkmodulID, f denkmodulLoaded);
36  
  //autoRestartModule('denkmodul, denkmodulID, true);
37  
  
38  
  if (isMain()) {
39  
    text = persistentVar("Text");
40  
    ta = fontSize(20, bindTextAreaToVar(text, jwordwraptextarea()));
41  
    moveCaretToEnd(ta);
42  
    //showFrame(ta);
43  
  
44  
    consoleIcon(#1101168);
45  
    consoleMainContainer(); // cache it before changing layout
46  
    //SingleComponentPanel scp = singleComponentPanel(); 
47  
    //JSplitPane sp = jhsplit(ta, scp);
48  
    //JPanel sp = jhgrid(ta, scp);
49  
    //JTextArea cta = consoleTextArea();
50  
    //replaceAWTComponent(cta, sp);
51  
    //scp.setComponent(cta);
52  
    //setSplitPaneLater(sp, 0.5);
53  
    addToWindowLeftHalf(consoleFrame(), ta);
54  
    doubleWindowSizeToTheLeft(consoleFrame());
55  
    doubleWindowSizeToTheTop(consoleFrame());
56  
  }
57  
  
58  
  set(recognizer, onFirstWebSocket := r {
59  
    playMP3Snippet(startUpSound);    
60  
  });
61  
62  
  set(recognizer, onUtterance := voidfunc(S utterance) {
63  
    if (flatInfoBoxOnUtterance) flatInfoBox(utterance);
64  
    if (ai_isStopListeningCommand(utterance)) {
65  
      call(recognizer, 'stopRecognition);
66  
      playBlip();
67  
    }
68  
    appendToTextAreaAndMoveCaret(ta, utterance + "\n");
69  
    callAnswerMethodVerbose(utterance);
70  
  });
71  
  
72  
  //set(recognizer, startRecognition := true);
73  
  callMain(recognizer);
74  
  //call(recognizer, 'switchToGerman);
75  
}
76  
77  
sS answer(fS s) {
78  
  if (sysNow() < skipTill) null;
79  
  if (sysNow() >= attention+attnTimeout) attnOff();
80  
  
81  
  if (attention != 0) {
82  
    attnOff();
83  
    
84  
    if "nichts|nix|vergiss es|nothing|forget it" {
85  
      playWAVSnippet(#1013870);
86  
    }
87  
    
88  
    try answer denk(s);
89  
  }
90  
  
91  
  S reKatze;
92  
  if (regexpICFind(reKatze = reKatze(), s)) {
93  
    fullAttention = true;
94  
    S rest;
95  
    if (empty(reKatze) || eq(reKatze, ".")) rest = s; else {
96  
      rest = regexpICLastGroup("(" + reKatze + ")(.*)", s);
97  
    
98  
      // e.g. "Computer[ ]spiel George Michael"
99  
      if (startsWithLetter(rest) && !swic(rest, "spiel"))
100  
        rest = trim(substring(rest, indexOf(rest, ' ')));
101  
    }
102  
    
103  
    if (nempty(rest))
104  
      try answer denk(rest);
105  
    else {
106  
      if (isShit(s))
107  
        playMP3Snippet(angrySound);
108  
      else
109  
        playMP3Snippet(friendlySound);
110  
      attention = sysNow();
111  
      fullAttention = true;
112  
      print("attn");
113  
      ret "Yo";
114  
    }
115  
  }
116  
  
117  
  L<S> g = regexpGetGroups("(-?\\d+) x (-?\\d+)", s);
118  
  if (g != null)
119  
    ret speak_withBlip(str(parseLong(first(g))*parseLong(second(g))));
120  
  
121  
  null;
122  
}
123  
124  
sbool isShit(S s) {
125  
  ret regexpICFind("scheiß", s);
126  
}
127  
128  
sS denk(S s) {
129  
  print(">> " + s);
130  
  
131  
  S a = "Fehler";
132  
  
133  
  try {
134  
    a = denk2(s);
135  
  } catch e {
136  
    if (eqic(getInnerMessage(e), "command stopped")) null;
137  
    else printStackTrace(e);
138  
  }
139  
  
140  
  if (empty(a)) {
141  
    if (!fullAttention) null;
142  
    a = defaultText;
143  
  } else {
144  
    attention = sysNow(); fullAttention = false;
145  
    print("half attn");
146  
  }
147  
  
148  
  skipTill = sysNow()+60000;
149  
  try {
150  
    speak_withBlip(a);
151  
  } finally {
152  
    skipTill = sysNow()+1000;
153  
  }
154  
  ret a;
155  
}
156  
157  
sS denk2(S s) {
158  
  if "neu" if (nempty(denkmodulID)) {
159  
    upgradeModuleVar('denkmodul, denkmodulID, true);
160  
    ret "OK";
161  
  }
162  
  
163  
  print("Sending to denkmodul " + programID(denkmodul) + ": " + s);
164  
  callOpt(denkmodul, 'setMsgGlobalID, getOpt(recognizer, 'lastGlobalID));
165  
  S a = callAnswerFunction(denkmodul, s);
166  
  print("Got: " + a);
167  
  ret a;
168  
}
169  
170  
svoid attnOff {
171  
  if (attention == 0) ret;
172  
  attention = 0;
173  
  print("attn off");
174  
}
175  
176  
sS speak_withBlip(S s) {
177  
  if (speakFunction != null) {
178  
    callF(speakFunction, s);
179  
    ret s;
180  
  } else
181  
    ret speakInRecognizerLanguage/*_withBlip*/(s);
182  
}
183  
184  
svoid denkmodulLoaded {
185  
  setOpt(denkmodul, actions := true);
186  
}
187  
188  
sS reKatze() {
189  
  ret or((S) getOpt(denkmodul, 'regexpActivator), regexpActivator);
190  
}

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: 810 / 92943
Version history: 101 change(s)
Referenced in: [show references]