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

104
LINES

< > BotCompany Repo | #1018551 // Speech Recognizer Using Chrome [Dyn Module]

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

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

1  
!7
2  
3  
cmodule SpeechRecognizer {
4  
  switchable bool autoStart;
5  
  //bool hideChromeWindow; // doesn't work
6  
  transient new Flag flag;
7  
  switchable bool showHostTrayIcon = true;
8  
  switchable bool passiveMode; // use "passive log" to prevent normal programs from reacting to speech
9  
  switchable bool flatInfoBox = true;
10  
  
11  
  transient S botName = "Chrome Speech.";
12  
  transient O recognizer;
13  
  
14  
  start {
15  
    O[] menuItems = litobjectarray(
16  
      "Start Listening", rThread startListening,
17  
      "Stop Listening", rThread stopListening,
18  
      "Switch to German", rThread switchToGerman,
19  
      "Switch to English", rThread switchToEnglish);
20  
      
21  
    dm_addTrayIcon_left(componentPopupMenuItems(onLeftClick(
22  
      toolTip(jimage_16(#1101635), "Continuous Speech Recognizer"),
23  
      rThread startListening),
24  
      menuItems));
25  
    dm_reloadOnFieldChange showHostTrayIcon();
26  
    if (showHostTrayIcon)
27  
      dm_systemTrayIcon(#1101635, "Continuous Speech Recognizer", itemPlusArray(rThread startListening, menuItems));
28  
    dm_watchField passiveMode(r {
29  
      //sendOpt(botName, passiveMode ? "use passive log" : "use active log");
30  
      setAll(recognizer, doLog := passiveMode, usePassiveLog := passiveMode);
31  
      updateTitle();
32  
    });
33  
    updateTitle();
34  
    if (autoStart) startListening();
35  
  }
36  
  
37  
  void updateTitle {
38  
    setModuleName((passiveMode ? "[PASSIVE]" : "") + " Speech Recognizer Using Chrome");
39  
  }
40  
  
41  
  visual
42  
    jfullcenter(
43  
      northAndCenterWithMargin(dm_checkBox passiveMode(),
44  
      jButtonWithInset("Start listening", rThread doIt)));
45  
46  
  void setLanguage(S language) { if (sendOpt("botName", "language *", language) == null) startRecognizer(true); }
47  
  void switchToEnglish { setLanguage("en-US"); }
48  
  void switchToGerman { setLanguage("de-DE"); }
49  
50  
  void startListening { doIt(false); }
51  
  void justOnce { doIt(true); }
52  
  
53  
  void doIt enter { doIt(false); }
54  
  
55  
  void doIt(bool justOnce) enter {
56  
    if (sendOptQuietly(botName, justOnce ? "just once" : "start recognition") == null)
57  
      startRecognizer(justOnce);
58  
  }
59  
  
60  
  // only call if it's not running already
61  
  void startRecognizer(bool justOnce) {
62  
    print("Starting recognizer");
63  
    recognizer = hotwireDependent(#1009816);
64  
    setAll(recognizer, doLog := passiveMode/*, +hideChromeWindow*/, usePassiveLog := passiveMode);
65  
    set(recognizer, onUtterance := voidfunc(S text) {
66  
      if (passiveMode) ret;
67  
      
68  
      S corrected = dm_correctRecognizedSpeech(text);
69  
      if (neq(corrected, text)) {
70  
        print("Correcting " + quote(text) + " to " + quote(corrected));
71  
        vmBus_send('correctedRecognizedSpeech, text, corrected);
72  
        text = corrected;
73  
      } else
74  
        print("Recognized: " + text);
75  
        
76  
      if (flatInfoBox && !dm_osInForeground())
77  
        flatInfoBox(text);
78  
        
79  
      S info = "Chrome Speech";
80  
      /*if (!vmBus_anyTrue dontApplyRecognizedSpeech())
81  
        dm_setAIBarTextAndFireWithInfo(text, info);*/
82  
      dm_rawSpeechRecognized(module(), text, info, null);
83  
      /*if (ai_isStopListeningCommand(text)) {
84  
        call(recognizer, 'stopRecognition);
85  
        playBlip();
86  
      }*/
87  
    });
88  
    set(recognizer, +justOnce);
89  
    /*if (flag.raise())
90  
      dm_putRecognizedSpeechInAIBar();*/
91  
    runMain(recognizer);
92  
  }
93  
  
94  
  void stopListening enter {
95  
    sendOpt(botName, "stop recognition");
96  
  }
97  
  
98  
  void enhanceFrame(JInternalFrame f) {
99  
    super.enhanceFrame(f);
100  
    internalFrameTitleMenuItems(f,
101  
      "Switch to German", rThread switchToGerman,
102  
      "Switch to English", rThread switchToEnglish);
103  
  }
104  
} 

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, unoaxrwscvea, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1018551
Snippet name: Speech Recognizer Using Chrome [Dyn Module]
Eternal ID of this version: #1018551/59
Text MD5: cd6bb3ceb71099a443fb84525f6e8908
Transpilation MD5: ef2a547300713f694d72a6208af8ebc1
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-07-21 21:45:25
Source code size: 3632 bytes / 104 lines
Pitched / IR pitched: No / No
Views / Downloads: 557 / 33872
Version history: 58 change(s)
Referenced in: [show references]