Uses 408K of libraries. Click here for Pure Java version (16180L/115K).
1 | !7 |
2 | |
3 | module CorrectRecognizedSpeech > DynPrintLog { |
4 | transient Map<S, MultiSet<S>> corrections = syncCIMap(); |
5 | bool autoCorrect = true, verbose; |
6 | |
7 | S switchableFields() { ret "autoCorrect verbose"; } |
8 | |
9 | start { |
10 | ownResource(watchSpeechConfirmations_fromStart(voidfunc(S heard, S corrected) { |
11 | MultiSet<S> ms; |
12 | synchronized(corrections) { |
13 | ms = corrections.get(heard); |
14 | if (ms == null) corrections.put(heard, ms = new MultiSet); |
15 | } |
16 | ms.add(corrected); |
17 | if (verbose) print("Learned correction: " + heard + " => " + corrected); |
18 | })); |
19 | |
20 | ownResource(onSpeechRecognized_withoutMyUtterancesAndTyped(voidfunc(fS s) enter { |
21 | S corrected = getCorrection(s); |
22 | if (nempty(corrected)) |
23 | infoBox("Proposing correction: " + corrected); |
24 | else |
25 | if (verbose) print("No correction found for: " + s); |
26 | })); |
27 | } |
28 | |
29 | visualize { |
30 | ret withRightAlignedButtons(super.visualize(), |
31 | toolTip("Correct all recognized speech", dm_fieldCheckBox('autoCorrect)), |
32 | "Show Corrections Database", rThread { |
33 | showText("Speech Recognition Corrections", formatDoubleArrowMap(mapValues(corrections, f msMostPopularEntry))); |
34 | }); |
35 | } |
36 | |
37 | // API |
38 | |
39 | S getCorrection(S s) { |
40 | ret l(s) < 2 ? null : msMostPopularEntry(corrections.get(s)); |
41 | } |
42 | |
43 | S getAutoCorrection(S s) { |
44 | ret autoCorrect ? getCorrection(s) : null; |
45 | } |
46 | } |
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1020219 |
Snippet name: | Correct Recognized Speech [learns from #1019400] |
Eternal ID of this version: | #1020219/18 |
Text MD5: | 7f918592e457fe4db3255cc434701d6e |
Transpilation MD5: | 64079c239be9535020ed239aed258e94 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-01-01 15:46:06 |
Source code size: | 1447 bytes / 46 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 420 / 3941 |
Version history: | 17 change(s) |
Referenced in: | [show references] |