!7 sS botName = "Dictation."; static JTextArea ta; static IVar text; static Splitter2 commandOrText; static JTextArea whatYouSay; static JButton btnText, btnCommand, btnNothing; static new L typeButtons; static new L types; static S currentType; p-subst { if (nempty(sendOpt(botName, "activate"))) { cleanKill(); ret; } commandOrText = persistentObject("Command or text splitter", Splitter2); text = persistentVar("Text"); swing { moveFrameTo(10, 10, 500, 300, showFrame("What you say", whatYouSay = jTextArea())); addToFrame(whatYouSay, withCenteredTitle("What is this?", jcenteredline( btnText = jbutton("It's text", r { setType('text) }), btnCommand = jbutton("It's a command", r { setType('command) }), btnNothing = jbutton("It's nothing", r { setType('nothing) }) ))); typeButtons = ll(btnText, btnCommand, btnNothing); types = ll('text, 'command, 'nothing); updateButtons(); showFrame(ta = jtextArea(text!)); onUpdate(ta, r { text.set(getText(ta)) }); exitProgramOnFrameClose(ta); } bot(botName); prioMe(); hideConsole(); } svoid prioMe { sendOpt("Voice Actions", "prio bot *", botName); } svoid cleanMeUp { sendOpt("Voice Actions", "prio bot done *", botName); } answer { if "activate" { prioMe(); activateFrame(ta); ret "OK"; } if "user said *" { onUtterance($1); ret "OK"; } } svoid onUtterance(fS s) { fS type = commandOrText.get(s); onUtterance(s, type); } svoid onUtterance(fS s, fS type) { swing { currentType = type; setText(whatYouSay, s); updateButtons(); } if (eq(type, 'command)) interpretCommand(s); else if (eq(type, 'text)) { appendToTextArea(ta, s + "\n"); requestFocus(ta); } } svoid interpretCommand(S s) { if "dictation done" { sendOpt("Voice Actions", "prio bot done *", botName); cleanKill(); } } svoid setType(S type) { S text = getText(whatYouSay); if (currentType != null) commandOrText.unlearn(text, type); commandOrText.learn(text, type); onUtterance(text, type); } svoid updateButtons { for i over typeButtons: typeButtons.get(i).setEnabled(neq(currentType, types.get(i))); }