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

1  
!7
2  
3  
cmodule VoiceRecognitionStatus {
4  
  transient S modeOff = "off",
5  
    modeListenAllTheTime = "listen",
6  
    modeListenOnNoise = "listen on noise";
7  
  
8  
  transient LS userSelectedModes = ll(
9  
    modeOff,
10  
    modeListenAllTheTime,
11  
    modeListenOnNoise);
12  
    
13  
  // left-click on tray icon cycles only through these states
14  
  transient LS cycleList = ll(modeOff, modeListenOnNoise);
15  
    
16  
  S userSelectedMode;
17  
  switchable bool showHostTrayIcon = true;
18  
  transient TrayIcon hostTrayIcon;
19  
  transient ButtonGroup buttons;
20  
  
21  
  transient long listeningUntil; // optional
22  
  transient bool listening;
23  
  
24  
  start {
25  
    dm_reloadOnFieldChange showHostTrayIcon();
26  
    if (showHostTrayIcon)
27  
      hostTrayIcon = dm_systemTrayIcon(makeImage(), makeTooltip(),
28  
        flattenArray_recursive(
29  
          rThread nextMode, // left-click command
30  
          "Show speech correlator", r { dm_activateOSAndModule speechCorrelator() },
31  
          map(userSelectedModes, mode -> ll(mode, rThread { setModeWithInfoBox(mode) })), // modes
32  
          "---",
33  
          "type", rThread { dm_focusAIBar() } // allow user to type in AI bar
34  
        ));
35  
36  
    dm_watchFieldAndNow userSelectedMode(r {
37  
      selectRadioButton(buttons, indexOfIC(userSelectedModes, userSelectedMode));
38  
    
39  
      if (eqic(userSelectedMode, modeOff)) {
40  
        // turn off Listen On Noise & actual recognizer
41  
        dm_call(dm_listenOnNoiseModuleOpt(), 'setEnabled, false);
42  
        dm_stopListening();
43  
        dm_findAndCall("#1020629/SpeechRecognitionControl", 'cancelAll);
44  
      } else if (eqic(userSelectedMode, modeListenOnNoise)) {
45  
        dm_call(dm_listenOnNoiseModule(), 'setEnabled, true);
46  
        dm_startGoogleSpeechRecognition();
47  
      } else if (eqic(userSelectedMode, modeListenAllTheTime)) {
48  
        dm_call(dm_listenOnNoiseModuleOpt(), 'setEnabled, false);
49  
        dm_startGoogleSpeechRecognition();
50  
      }
51  
      
52  
      setToolTip(hostTrayIcon, makeTooltip());
53  
      setTrayIconImage(hostTrayIcon, makeImage());
54  
    });
55  
  }
56  
  
57  
  visualize {
58  
    buttons = jRadioButtons(userSelectedModes);
59  
    selectRadioButton(buttons, indexOfIC(userSelectedModes, userSelectedMode));
60  
    onRadioButtonChange(buttons, voidfunc(int i) {
61  
      setField(userSelectedMode := _get(userSelectedModes, i));
62  
    });
63  
    ret jfullcenter(vstackWithSpacing(buttonsInGroup(buttons)));
64  
  }
65  
  
66  
  void nextMode {
67  
    setModeWithInfoBox(nextInCyclicList(userSelectedMode, cycleList));
68  
  }
69  
  
70  
  void setModeWithInfoBox(S mode) {
71  
    infoBox("New mode: " + mode, 1.0);
72  
    setField(userSelectedMode := mode);
73  
  }
74  
  
75  
  S makeTooltip() { ret userSelectedMode + " - voice recognition 3-way switch"; }
76  
  
77  
  S makeImage() { ret eqic(userSelectedMode, modeOff) ? #1102870 : #1101635; }
78  
}

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: 307 / 25589
Version history: 30 change(s)
Referenced in: [show references]