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

!7

sclass HearMyselfTest > DynPrintLog {
  S text = "I like you", heard;
  transient JTextField tfText;
  transient JLabel lblCat;
  int timeout = 5;
  
  start { logModuleOutput(); }

  visualize {
    ret withCenteredButtons(
      northAndCenter(
      centerAndEast(
        vstack(
          jsection("Text to say",
            onEnter(rThread doIt, tfText = jLiveValueTextField_bothWays(dm_fieldLiveValue('text)))),
          jsection("What I heard",
            disableTextField(jLiveValueTextField(dm_fieldLiveValue('heard))))),
        withMargin(lblCat = jimage(#1101344))),
        super.visualize()),
      "Do the test", rThread doIt);
  }
  
  void doIt enter {
    temp dm_tempDisableAllButtons();
    S text = getTextTrim(tfText);
    if (empty(text)) ret;
    
    print("Initiating voice");
    O voiceOutput = dm_getModule(dm_requireModule("#1016614/VoiceOutput"));
    print("Initiating ear");
    //O katze = dm_getModule(dm_requireModule("#1016461/Katze"));
    O katze = dm_getModule(dm_requireModule("#1018551/SpeechRecognizer"));
    call(katze, 'startListening);
    if (!chromeSpeech_hasRecognizer()) {
      do { sleepSeconds(1); }
      while (!chromeSpeech_hasRecognizer());
    }
    sleepSeconds(2); // give time to start
    
    double seconds = this.timeout;
    long logLength = fileSize(speechRecognitionLog());
    print("Saying & listening for " + seconds + " seconds: " + text);
    call(voiceOutput, 'say, text);
    long timeout = sysTime()+toMS(seconds);
    new Var<S> vLine;
    ManualTailFile tail = new(speechRecognitionLog(), vfAppendToLineBuffer(unquotingLineBuffer(vfSetVar(vLine))));
    tailFile_newOnly(tail);
    while (sysTime() < timeout && !vLine.has()) {
      tail.check();
      sleep(100);
    }
    print("Stop listening.");
    call(katze, 'stopListening);
    
    S s = speechRecognitionLog_extractUtterance(vLine!);
    setField(heard := s);
    print("Got line: " + s);
    if (match(text, s)) {
      print("Yes, I can hear myself!!");
      setModuleName("I can hear myself :)");
      setImage(lblCat, #1101341);
    } else if (nempty(s)) {
      print("I said: " + quote(text) + ", but I heard: " + quote(s));
      setModuleName("I seem to mishear myself");
      setImage(lblCat, #1101343);
    } else {
      print("I said: " + quote(text) + ", but I heard nothing.");
      setModuleName("I can't hear me :(");
      setImage(lblCat, #1101342);
    }
  }
  
  enhanceFrame {
    dm_intFieldMenuItem(f, 'timeout);
  }
}

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: 376 / 835
Version history: 33 change(s)
Referenced in: [show references]