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

78
LINES

< > BotCompany Repo | #1016654 // Test whether I can hear myself [Dyn Module]

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

Libraryless. Click here for Pure Java version (15303L/111K).

1  
!7
2  
3  
sclass HearMyselfTest > DynPrintLog {
4  
  S text = "I like you", heard;
5  
  transient JTextField tfText;
6  
  transient JLabel lblCat;
7  
  int timeout = 5;
8  
  
9  
  start { logModuleOutput(); }
10  
11  
  visualize {
12  
    ret withCenteredButtons(
13  
      northAndCenter(
14  
      centerAndEast(
15  
        vstack(
16  
          jsection("Text to say",
17  
            onEnter(rThread doIt, tfText = jLiveValueTextField_bothWays(dm_fieldLiveValue('text)))),
18  
          jsection("What I heard",
19  
            disableTextField(jLiveValueTextField(dm_fieldLiveValue('heard))))),
20  
        withMargin(lblCat = jimage(#1101344))),
21  
        super.visualize()),
22  
      "Do the test", rThread doIt);
23  
  }
24  
  
25  
  void doIt enter {
26  
    temp dm_tempDisableAllButtons();
27  
    S text = getTextTrim(tfText);
28  
    if (empty(text)) ret;
29  
    
30  
    print("Initiating voice");
31  
    O voiceOutput = dm_getModule(dm_requireModule("#1016614/VoiceOutput"));
32  
    print("Initiating ear");
33  
    //O katze = dm_getModule(dm_requireModule("#1016461/Katze"));
34  
    O katze = dm_getModule(dm_requireModule("#1018551/SpeechRecognizer"));
35  
    call(katze, 'startListening);
36  
    if (!chromeSpeech_hasRecognizer()) {
37  
      do { sleepSeconds(1); }
38  
      while (!chromeSpeech_hasRecognizer());
39  
    }
40  
    sleepSeconds(2); // give time to start
41  
    
42  
    double seconds = this.timeout;
43  
    long logLength = fileSize(speechRecognitionLog());
44  
    print("Saying & listening for " + seconds + " seconds: " + text);
45  
    call(voiceOutput, 'say, text);
46  
    long timeout = sysTime()+toMS(seconds);
47  
    new Var<S> vLine;
48  
    ManualTailFile tail = new(speechRecognitionLog(), vfAppendToLineBuffer(unquotingLineBuffer(vfSetVar(vLine))));
49  
    tailFile_newOnly(tail);
50  
    while (sysTime() < timeout && !vLine.has()) {
51  
      tail.check();
52  
      sleep(100);
53  
    }
54  
    print("Stop listening.");
55  
    call(katze, 'stopListening);
56  
    
57  
    S s = speechRecognitionLog_extractUtterance(vLine!);
58  
    setField(heard := s);
59  
    print("Got line: " + s);
60  
    if (match(text, s)) {
61  
      print("Yes, I can hear myself!!");
62  
      setModuleName("I can hear myself :)");
63  
      setImage(lblCat, #1101341);
64  
    } else if (nempty(s)) {
65  
      print("I said: " + quote(text) + ", but I heard: " + quote(s));
66  
      setModuleName("I seem to mishear myself");
67  
      setImage(lblCat, #1101343);
68  
    } else {
69  
      print("I said: " + quote(text) + ", but I heard nothing.");
70  
      setModuleName("I can't hear me :(");
71  
      setImage(lblCat, #1101342);
72  
    }
73  
  }
74  
  
75  
  enhanceFrame {
76  
    dm_intFieldMenuItem(f, 'timeout);
77  
  }
78  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1016654
Snippet name: Test whether I can hear myself [Dyn Module]
Eternal ID of this version: #1016654/34
Text MD5: 2ef821ca3918bc4473b9dad0a9483c3c
Transpilation MD5: 4164410d9325cc727748a5a88a52a8bb
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: 2018-11-24 21:37:22
Source code size: 2571 bytes / 78 lines
Pitched / IR pitched: No / No
Views / Downloads: 449 / 927
Version history: 33 change(s)
Referenced in: [show references]