!7 static JLabel l; static Map consequentsMap = synchroCIMap(), precedentsMap = synchroCIMap(); static Set ignoreSet = asCISet(splitAtVerticalBar("english|englisch|german|deutsch|foreground|fairground|background|Vordergrund|Hintergrund")); sS answer; static L> receivers; static JTextField tfInput, tfSay, tfNote; static JButton btnSay; static TailFile logTail; p-noconsole-autoupdate { startBotInSeparateVM("Katze.", #1013936); hideVMRunningBot("Katze."); final JFrame frame = frameIcon(#1101166, showMaximizedFrame(jscroll_verticalExtend_trackWidth( //jTiledBackground(#1007195, setForeground(Color.white, jCenteredBackgroundImage(#1101166, setBackground(awtColor("e4e4e4"), setForeground(Color.black, setFontSize(60, l = jcenteredlabel_noToolTip()))))))); addToWindowWithMargin(frame, jcenteredline(btnSay = jbutton("Say", f sayIt))); // bottom to top addToWindowNorth(frame, withMargin(10, 1, withLabel("Add a note:", tfNote = jcenteredtextfield()))); addToWindowNorth(frame, withMargin(10, 1, withLabel("Make me say something:", tfSay = jcenteredtextfield()))); addToWindowNorth(frame, withMargin(10, 1, withLabel("Type here instead of speaking:", tfInput = jcenteredtextfield()))); onEnter(tfInput, r-thread { send("Chrome Speech.", "User typed *", getTextTrim(tfInput)) }); onEnter(tfSay, r-thread { speakInRecognizerLanguage(getTextTrim(tfSay)) }); onEnter(tfNote, r { mechAppendQueue().add(r { appendToMechList_noUniq("Today's Notes", "[" + localDateWithMilliseconds() + "] " + getTextTrim(tfNote)) }) }); focusOnFrameActivationAndNow(frame, btnSay); receivers = ll( consequentsMap_receiver(consequentsMap), precedentsMap_receiver(precedentsMap)); time "Loading" { loading { mapVoidMulti(receivers, notNulls(map prepLine(dropLast(linesOfFile(speechRecognitionLog()))))); } } logTail = tailFileLinewisePlusLastLine(speechRecognitionLog(), 100, vf1(f onUtteranceFromLog)); //makeAndCall_warmUp("mL_anInstanceOfA"); } sS prepLine(S s) { s = unquoteAndDropAngleBracketStuff(s); // don't react on older messages if (logTail != null && logTail.started()) printIndentUnlessEmpty(">> ", pcallAnswerMethod(s)); ret nullIfInSet(ignoreSet, s); } svoid onUtteranceFromLog(S utterance) { if (empty(utterance = prepLine(trimLastLine(utterance)))) ret; print(">> " + utterance); onUtterance(utterance); } svoid onUtterance(S utterance) { mapVoidMulti(receivers, ll(utterance)); answer = guessAnswer(utterance); S both = utterance; setTextAndEnabled(btnSay, empty(answer) ? pair("Say", false) : pair("Say " + quote(answer), true)); if (nempty(answer)) { both += "\n\n" + answer; logQuotedWithTime("guessLog", both); } setFrameTitle(l, both.replaceAll("\n+", " > "); setText(l, jlabel_textAsHTML_center(both)); } answer { s = lookupOrKeep(mechMapCI("Mishearing corrections"), s); if "higher" infoBox("Get higher?"); if "font size *" ret "OK" with revalidate(setFontSize(parseInt($1), l)); if "foreground|fairground|vordergrund" ret "OK" with activateFrame(l); if "background|hintergrund" ret "OK" with minimizeFrame(l); if "standard function|standard functions|steroid function|standard fashion" // Google keeps misunderstanding ret "OK" with sfBot_doIt(); if "move mouse away" ret "OK" with moveMouseToTopRightCorner(); if "mouse to center|mouse to centre|most two centre" ret "OK" with moveMouseToScreenCenter(); } svoid sayIt { fS a = answer; if (empty(a)) ret; print("Saying: " + a); thread { speakInRecognizerLanguage(a); } onUtterance(a); } sS guessAnswer(S s) { new Matches m; if (find3plusRestsOneOf(s, m, "Ich heiße", "Ich bin", "Mein Name ist", "Man nennt mich", "Ich werde * genannt", "nennen mich", "nennt mich", "nenne mich")) if (eqic($2, "Stefan")) ret gudrun_later("Stefan ist ein Programmierer"); else ret gudrun_later("Hallo " + $2); try answer mL_answerWithCodeFragments("Witty Answers", s); try answer mL_answerWithCodeFragments(s); try answer consequentsMap.get(s); try answer precedentsMap.get(s); null; }