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).

!7

cmodule SpeechRecognitionControl {
  S method = 'google;
  
  bool enabled = true;
  transient JPanel stack; // TODO: add elements when showing
  transient new RestartableCountdown deleteIfUnused;
  transient Set<AutoCloseable> activeRequests;
  transient ReliableSingleThread rstStartStop;
  
  start {
    rstStartStop = dm_rst(this, r startStop);
    activeRequests = setWithNotify(rstStartStop);
    startCountdown();
    if (dm_getBounds() == null) {
      int w = getWidth(dm_desktopPane()), h = getHeight(dm_desktopPane());
      dm_setBounds(this, w-300, h-200, 300, 200);
    }
  }
  
  visualize {
    ret centerAndSouth(
      withRightMargin(stack = dynamicVStack2()),
      withMargin(dm_rightAlignedFieldCheckBox('enabled)));
  }
  
  // start countdown to delete module if unused
  void startCountdown {
    if (enabled) deleteIfUnused.start(10*60.0, rEnter dm_deleteModule);
  }
  
  void startStop {
    if (enabled && nempty(activeRequests))
      dm_requireAndCallModule("#1018551/SpeechRecognizer", 'startListening);
    else
      dm_findAndCallModule("#1018551/SpeechRecognizer", 'stopListening);
   }
  
  // API
  
  // Note: cancelMe will be called in GUI thread
  AutoCloseable activateSpeechRecognition(S reason) {
    deleteIfUnused.stop();
    final JLabel lbl = jlabel(reason);
    final new Var<JComponent> c;
    final AutoCloseable release = autoCloseable {
      removeAndValidate(c!);
      activeRequests.remove(this);
      startCountdown();
    };
    c.set(centerAndEast(lbl, jbutton("Cancel", r { close(release) })));
    addAndValidate(stack, c!);
    ret addAndReturn(activeRequests, release);
  }
  
  void cancelAll {
    closeAll_cloneList(activeRequests);
  }
}

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: 335 / 4148
Version history: 20 change(s)
Referenced in: [show references]