Download Jar. Uses 3874K of libraries. Click here for Pure Java version (9541L/65K).
1 | !7 |
2 | |
3 | sS botName = "Dictation."; |
4 | static JTextArea ta; |
5 | static IVar<S> text; |
6 | static Splitter2<S, S> commandOrText; |
7 | static JTextArea whatYouSay; |
8 | static JButton btnText, btnCommand, btnNothing; |
9 | static new L<JButton> typeButtons; |
10 | static new L<S> types; |
11 | static S currentType; |
12 | |
13 | p-subst { |
14 | if (nempty(sendOpt(botName, "activate"))) { cleanKill(); ret; } |
15 | |
16 | commandOrText = persistentObject("Command or text splitter", Splitter2); |
17 | text = persistentVar("Text"); |
18 | swing { |
19 | moveFrameTo(10, 10, 500, 300, showFrame("What you say", whatYouSay = jTextArea())); |
20 | addToFrame(whatYouSay, withCenteredTitle("What is this?", jcenteredline( |
21 | btnText = jbutton("It's text", r { setType('text) }), |
22 | btnCommand = jbutton("It's a command", r { setType('command) }), |
23 | btnNothing = jbutton("It's nothing", r { setType('nothing) }) |
24 | ))); |
25 | typeButtons = ll(btnText, btnCommand, btnNothing); |
26 | types = ll('text, 'command, 'nothing); |
27 | updateButtons(); |
28 | showFrame(ta = jtextArea(text!)); |
29 | onUpdate(ta, r { text.set(getText(ta)) }); |
30 | exitProgramOnFrameClose(ta); |
31 | } |
32 | bot(botName); |
33 | prioMe(); |
34 | hideConsole(); |
35 | } |
36 | |
37 | svoid prioMe { |
38 | sendOpt("Voice Actions", "prio bot *", botName); |
39 | } |
40 | |
41 | svoid cleanMeUp { |
42 | sendOpt("Voice Actions", "prio bot done *", botName); |
43 | } |
44 | |
45 | answer { |
46 | if "activate" { |
47 | prioMe(); |
48 | activateFrame(ta); |
49 | ret "OK"; |
50 | } |
51 | |
52 | if "user said *" { |
53 | onUtterance($1); |
54 | ret "OK"; |
55 | } |
56 | } |
57 | |
58 | svoid onUtterance(fS s) { |
59 | fS type = commandOrText.get(s); |
60 | onUtterance(s, type); |
61 | } |
62 | |
63 | svoid onUtterance(fS s, fS type) { |
64 | swing { |
65 | currentType = type; |
66 | setText(whatYouSay, s); |
67 | updateButtons(); |
68 | } |
69 | |
70 | if (eq(type, 'command)) |
71 | interpretCommand(s); |
72 | else if (eq(type, 'text)) { |
73 | appendToTextArea(ta, s + "\n"); |
74 | requestFocus(ta); |
75 | } |
76 | } |
77 | |
78 | svoid interpretCommand(S s) { |
79 | if "dictation done" { |
80 | sendOpt("Voice Actions", "prio bot done *", botName); |
81 | cleanKill(); |
82 | } |
83 | } |
84 | |
85 | svoid setType(S type) { |
86 | S text = getText(whatYouSay); |
87 | if (currentType != null) |
88 | commandOrText.unlearn(text, type); |
89 | commandOrText.learn(text, type); |
90 | onUtterance(text, type); |
91 | } |
92 | |
93 | svoid updateButtons { |
94 | for i over typeButtons: |
95 | typeButtons.get(i).setEnabled(neq(currentType, types.get(i))); |
96 | } |
Began life as a copy of #1009702
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1009705 |
Snippet name: | Dictation Bot with Splitter 2 [dev.] |
Eternal ID of this version: | #1009705/7 |
Text MD5: | 4701f93b2d6b5aff60681b1272e5902b |
Transpilation MD5: | 9fb4a0e92db82d64b51fcb7ef1eb1ec4 |
Author: | stefan |
Category: | javax / assistants |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-08-14 17:32:50 |
Source code size: | 2315 bytes / 96 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 649 / 1446 |
Version history: | 6 change(s) |
Referenced in: | [show references] |