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

78
LINES

< > BotCompany Repo | #1026348 // Voice Recognition 3-Way Switch [one-stop control for speech recognition on/off/listen on noise]

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

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

!7

cmodule VoiceRecognitionStatus {
  transient S modeOff = "off",
    modeListenAllTheTime = "listen",
    modeListenOnNoise = "listen on noise";
  
  transient LS userSelectedModes = ll(
    modeOff,
    modeListenAllTheTime,
    modeListenOnNoise);
    
  // left-click on tray icon cycles only through these states
  transient LS cycleList = ll(modeOff, modeListenOnNoise);
    
  S userSelectedMode;
  switchable bool showHostTrayIcon = true;
  transient TrayIcon hostTrayIcon;
  transient ButtonGroup buttons;
  
  transient long listeningUntil; // optional
  transient bool listening;
  
  start {
    dm_reloadOnFieldChange showHostTrayIcon();
    if (showHostTrayIcon)
      hostTrayIcon = dm_systemTrayIcon(makeImage(), makeTooltip(),
        flattenArray_recursive(
          rThread nextMode, // left-click command
          "Show speech correlator", r { dm_activateOSAndModule speechCorrelator() },
          map(userSelectedModes, mode -> ll(mode, rThread { setModeWithInfoBox(mode) })), // modes
          "---",
          "type", rThread { dm_focusAIBar() } // allow user to type in AI bar
        ));

    dm_watchFieldAndNow userSelectedMode(r {
      selectRadioButton(buttons, indexOfIC(userSelectedModes, userSelectedMode));
    
      if (eqic(userSelectedMode, modeOff)) {
        // turn off Listen On Noise & actual recognizer
        dm_call(dm_listenOnNoiseModuleOpt(), 'setEnabled, false);
        dm_stopListening();
        dm_findAndCall("#1020629/SpeechRecognitionControl", 'cancelAll);
      } else if (eqic(userSelectedMode, modeListenOnNoise)) {
        dm_call(dm_listenOnNoiseModule(), 'setEnabled, true);
        dm_startGoogleSpeechRecognition();
      } else if (eqic(userSelectedMode, modeListenAllTheTime)) {
        dm_call(dm_listenOnNoiseModuleOpt(), 'setEnabled, false);
        dm_startGoogleSpeechRecognition();
      }
      
      setToolTip(hostTrayIcon, makeTooltip());
      setTrayIconImage(hostTrayIcon, makeImage());
    });
  }
  
  visualize {
    buttons = jRadioButtons(userSelectedModes);
    selectRadioButton(buttons, indexOfIC(userSelectedModes, userSelectedMode));
    onRadioButtonChange(buttons, voidfunc(int i) {
      setField(userSelectedMode := _get(userSelectedModes, i));
    });
    ret jfullcenter(vstackWithSpacing(buttonsInGroup(buttons)));
  }
  
  void nextMode {
    setModeWithInfoBox(nextInCyclicList(userSelectedMode, cycleList));
  }
  
  void setModeWithInfoBox(S mode) {
    infoBox("New mode: " + mode, 1.0);
    setField(userSelectedMode := mode);
  }
  
  S makeTooltip() { ret userSelectedMode + " - voice recognition 3-way switch"; }
  
  S makeImage() { ret eqic(userSelectedMode, modeOff) ? #1102870 : #1101635; }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1026348
Snippet name: Voice Recognition 3-Way Switch [one-stop control for speech recognition on/off/listen on noise]
Eternal ID of this version: #1026348/31
Text MD5: 96b90ad51d9c5519799fd7e6566a8037
Transpilation MD5: 6b86b1145f3abba672773f266d4b50e9
Author: stefan
Category: javax / speech recognition
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-28 14:50:35
Source code size: 2786 bytes / 78 lines
Pitched / IR pitched: No / No
Views / Downloads: 308 / 25589
Version history: 30 change(s)
Referenced in: #1026768 - Test Host Tray Icon Mouse Over Event (only mouseMoved is delivered)