Uses 3874K of libraries. Click here for Pure Java version (11408L/81K/277K).
!7 static Map<S, S> cmdToProgram; static Map<S, S> cmdToShell; static Map<S, S> cmdToAnswer; static Map<S, S> cmdToCmd; static Map<S, S> cmdToEval; static Map<S, Pair<S>> cmdToBotSend; static L<Pair<S, Long>> voiceCommandLog; static IVar<S> prioBot; p { magellan(); quietDB(); cmdToProgram = persistentTreeMap("Command to program"); cmdToShell = persistentTreeMap("Command to shell"); cmdToAnswer = persistentTreeMap("Command to answer"); cmdToCmd = persistentTreeMap("Command to command"); cmdToBotSend = persistentTreeMap("Command to bot send"); cmdToEval = persistentTreeMap("Command to eval"); prioBot = persistentVar("Prio bot"); voiceCommandLog = persistentList("Voice Command Log"); makeBot("Voice Actions."); } sS answer(S s) { new Matches m; voiceCommandLog.add(pair(s, now())); if "prio bot *" { prioBot.set($1); consoleStatus(prioBot!); ret "OK"; } if "prio bot done *" { if (eqic(prioBot!, $1)) prioBot.set(null); consoleStatus(prioBot!); ret "OK"; } if "prio bot none" { prioBot.set(null); consoleStatus(prioBot!); ret "OK"; } if "user said: *" s = $1; S a; try { a = answer2(s); } catch e { printStackTrace(e); a = str(e); } if (nempty(a)) infoBox_lower(a); ret a; } sS answer2(S s) { new Matches m; // drop "ja" or "yep" //S answerWord = dropPunctuation(botAnswerWord()); //if (matchStart(answerWord, s, m)) s = m.rest(); if (nempty(prioBot!)) pcall { try answer send(prioBot!, "User said: *", s); } Set<S> seen; for ping (seen = new LinkedHashSet; l(seen) < 100; ) { if "command * to program *" { cmdToProgram.put($1, $2); ret "OK"; } if "command * to shell *" { cmdToShell.put($1, $2); ret "OK"; } if "command * to answer *" { cmdToAnswer.put($1, $2); ret "OK"; } if "command * send * to *" { cmdToBotSend.put($1, pair($3, $2)); ret "OK"; } if "command * to eval *" { cmdToEval.put($1, $2); ret "OK"; } if "command * to command *" { cmdToCmd.put($1, $2); ret "OK"; } if "remove command *" { removeFromMaps($1, cmdToProgram, cmdToShell, cmdToAnswer, cmdToBotSend, cmdToEval); ret "OK"; } if "applause" { applause(); ret "Applause!"; } if "restart voice actions" { restartIn1(); ret "OK"; } if "voice log" { showLog(); ret "OK"; } S program = lookupByNLMatch(cmdToProgram, s); if (nempty(program)) { nohupJavax(program); ret "Running: " + snippetWithTitle(program); } Pair<S> botSend = lookupByNLMatch(cmdToBotSend, s); if (botSend != null) ret send(botSend.a, botSend.b); S eval = lookupByNLMatch(cmdToEval, s); if (eval != null) ret or2(strOrEmpty(evalJava(eval)), "OK"); S shell = lookupByNLMatch(cmdToShell, s); if (nempty(shell)) { nohup(shell); ret "Running: " + shell; } try answer lookupByNLMatch(cmdToAnswer, s); seen.add(s); s = lookupByNLMatch(cmdToCmd, s); if (empty(s)) null; if (seen.contains(s)) fail("bad cmd-to-cmd: " + sfu(seen)); } fail("bad cmd-to-cmd: " + sfu(seen)); } svoid showLog { showTable_updatedOnConceptsChange("Voice Log", f renderLog); } static L renderLog() { ret reversed(map(cloneList(voiceCommandLog), func(Pair<S, Long> p) { litorderedmap("Command" := p.a, "Time" := formatDateAndTime(p.b)) })); }
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, wtqryiryparv
No comments. add comment
Snippet ID: | #1009595 |
Snippet name: | Voice Actions 1 [OK] |
Eternal ID of this version: | #1009595/47 |
Text MD5: | c9f7fd4cef3fb50eaabb3a9ae565cadb |
Transpilation MD5: | 81d5e4a72f7ec3352d5a6af6726b382f |
Author: | stefan |
Category: | javax / speech |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-08-22 22:14:06 |
Source code size: | 3368 bytes / 98 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 597 / 1544 |
Version history: | 46 change(s) |
Referenced in: | #1009602 - Start English Assistant #1009608 - Starte deutschen Assistenten |