Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

60
LINES

< > BotCompany Repo | #1020629 // Speech Recognition Control [almost OK]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (5279L/26K).

1  
!7
2  
3  
cmodule SpeechRecognitionControl {
4  
  S method = 'google;
5  
  
6  
  bool enabled = true;
7  
  transient JPanel stack; // TODO: add elements when showing
8  
  transient new RestartableCountdown deleteIfUnused;
9  
  transient Set<AutoCloseable> activeRequests;
10  
  transient ReliableSingleThread rstStartStop;
11  
  
12  
  start {
13  
    rstStartStop = dm_rst(this, r startStop);
14  
    activeRequests = setWithNotify(rstStartStop);
15  
    startCountdown();
16  
    if (dm_getBounds() == null) {
17  
      int w = getWidth(dm_desktopPane()), h = getHeight(dm_desktopPane());
18  
      dm_setBounds(this, w-300, h-200, 300, 200);
19  
    }
20  
  }
21  
  
22  
  visualize {
23  
    ret centerAndSouth(
24  
      withRightMargin(stack = dynamicVStack2()),
25  
      withMargin(dm_rightAlignedFieldCheckBox('enabled)));
26  
  }
27  
  
28  
  // start countdown to delete module if unused
29  
  void startCountdown {
30  
    if (enabled) deleteIfUnused.start(10*60.0, rEnter dm_deleteModule);
31  
  }
32  
  
33  
  void startStop {
34  
    if (enabled && nempty(activeRequests))
35  
      dm_requireAndCallModule("#1018551/SpeechRecognizer", 'startListening);
36  
    else
37  
      dm_findAndCallModule("#1018551/SpeechRecognizer", 'stopListening);
38  
   }
39  
  
40  
  // API
41  
  
42  
  // Note: cancelMe will be called in GUI thread
43  
  AutoCloseable activateSpeechRecognition(S reason) {
44  
    deleteIfUnused.stop();
45  
    final JLabel lbl = jlabel(reason);
46  
    final new Var<JComponent> c;
47  
    final AutoCloseable release = autoCloseable {
48  
      removeAndValidate(c!);
49  
      activeRequests.remove(this);
50  
      startCountdown();
51  
    };
52  
    c.set(centerAndEast(lbl, jbutton("Cancel", r { close(release) })));
53  
    addAndValidate(stack, c!);
54  
    ret addAndReturn(activeRequests, release);
55  
  }
56  
  
57  
  void cancelAll {
58  
    closeAll_cloneList(activeRequests);
59  
  }
60  
}

Author comment

Began life as a copy of #1019874

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1020629
Snippet name: Speech Recognition Control [almost OK]
Eternal ID of this version: #1020629/21
Text MD5: 8f0c9c7b23dcf3b12cc3241db0de3a30
Transpilation MD5: 931de48a70d93f226a56f5390d7ea0aa
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-19 20:49:29
Source code size: 1770 bytes / 60 lines
Pitched / IR pitched: No / No
Views / Downloads: 336 / 4150
Version history: 20 change(s)
Referenced in: [show references]