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

69
LINES

< > BotCompany Repo | #1019400 // Speech Recognition Confirmation v2 [Did computer understand correctly?, with tray icon]

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

Uses 1319K of libraries. Click here for Pure Java version (9670L/49K).

1  
!7
2  
3  
cmodule SpeechRecogConfirmation > DynPrintLogAndButtons {
4  
  start {
5  
    ownResource(onSpeechRecognized_withoutMyUtterancesAndTyped(voidfunc(fS s) enter {
6  
      print("\nI heard: " + quote(s));
7  
      if (eq(s, "?")) {
8  
        fS q = "Did you say anything?";
9  
        showButtons1(q, "",
10  
          "Yes", r { log(s, q, 'yes); whatDidYouSay(s); },
11  
          "No", r { log(s, q, 'no); print("Thanks"); });
12  
      } else {
13  
        fS q = "Did you say that?";
14  
        showButtons1(q, s,
15  
          "Yes", r { log(s, q, 'yes); print("Thanks"); },
16  
          "No", r { log(s, q, 'no); whatDidYouSay(s); });
17  
      }
18  
    }));
19  
  }
20  
  
21  
  void log(S heard, S question, S answer) {
22  
    print("> " + upper(answer));
23  
    logStruct(speechConfirmationLogFile(), litorderedmap(date := now(), +heard, +question, +answer));
24  
    hideButtons();
25  
  }
26  
  
27  
  void whatDidYouSay(fS heard) {
28  
    S q = print("What did you say?");
29  
    VF1<S> f = voidfunc(S corrected) {
30  
      corrected = trim(corrected);
31  
      print("> I said " + (empty(corrected) ? "nothing" : quote(upper(corrected))));
32  
      logStruct(speechConfirmationLogFile(), litorderedmap(date := now(), +heard, +corrected));
33  
      hideButtons();
34  
      print("Thanks");
35  
      if (neq(heard, corrected)) dm_setAIBarTextAndFire(corrected);
36  
    };
37  
    showButtons2(q, 
38  
      centerAndEastWithMargin(focusedTextFieldAndButton(heard, "is what I said", f), jbutton("X", r hideButtons)),
39  
      textFieldAndButton(heard, "is what I said", f));
40  
  }
41  
  
42  
  void hideButtons {
43  
    temp enter();
44  
    super.hideButtons();
45  
    dm_setTrayIcon_left(null);
46  
  }
47  
  
48  
  void showButtons1(fS q, fS heard, O... params) {
49  
    print(q);
50  
    showButtons(params);
51  
    JComponent tray = jPreferredSizeToFixedSize(buttonsAsfillerlessHStack_noSpacing(singlePlusArrayPlus(jlabel(q + " "), params, "X", r hideButtons)));
52  
    final new Var<AutoCloseable> disposer;
53  
    bindToComponent(tray, r {
54  
      temp enter();
55  
      disposer.set(vmBus_onMessage('topInputChanged, voidfunc(S s) {
56  
        temp enter();
57  
        //print("Heard=" + heard + ", s=" + s);
58  
        if (neq(s, heard)) dm_hideTrayIcon_left();
59  
      }));
60  
    }, r { close(disposer!) });
61  
    dm_setTrayIcon_left(tray);
62  
  }
63  
  
64  
  void showButtons2(S q, JComponent buttonsForTray, JComponent buttonsForMyWindow) {
65  
    print(q);
66  
    showButtons(buttonsForMyWindow);
67  
    dm_setTrayIcon_left(jPreferredSizeToFixedSize(buttonsForTray));
68  
  }
69  
}

Author comment

Began life as a copy of #1019363

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1019400
Snippet name: Speech Recognition Confirmation v2 [Did computer understand correctly?, with tray icon]
Eternal ID of this version: #1019400/46
Text MD5: 4e8139729e09795b68e239ab46ef9e83
Transpilation MD5: 06d4744e8e63e59f160f0b9da516f6d6
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-12-11 03:04:00
Source code size: 2456 bytes / 69 lines
Pitched / IR pitched: No / No
Views / Downloads: 510 / 34327
Version history: 45 change(s)
Referenced in: [show references]