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

57
LINES

< > BotCompany Repo | #1014605 // Speak & Hear (dev.)

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (7619L/52K).

!7

enum EType { speakStart, speakEnd, heard, typed }

sclass Event {
  long date;
  EType type;
  S text;
  S voice;
  
  *() {}
  *(long *date, EType *type, S *text) {}
  *(long *date, EType *type, S *text, S *voice) {}
  
  toString {
    ret date + ": " + toStringWithoutDate();
  }
  
  S toStringWithoutDate() {
    ret type + ": " + text + (nempty(voice) ? " (" + voice + ")" : "");
  }
}

static TailFile tail1, tail2;
static Map<Long, Event> events = synchroTreeMap();

p-experiment {
  tail1 = tailFileLinewiseFromStart(cereprocLog(), 100, voidfunc(S line) {
    if ((line = forceProperUnquote(line)) == null) ret;
    Pair<S> p = splitAtFirstSpace(line);
    long date = parseLong(p.a);
    Map map = unstructureMap(p.b);
    print(date + ": " + sfu(map));
    putLongUnique(events, date, new Event(date, swic(getString(map, 'action), "Begin") ? EType.speakStart : EType.speakEnd, getString(map, 'text), getString(map, 'voice)));
  });
  
  tail2 = tailFileLinewiseFromStart(speechRecognitionLog(), 100, voidfunc(S line) {
    if ((line = forceProperUnquote(line)) == null) ret;
    int i = indexOf(line, '[');
    long date = parseLongOpt(trim(takeFirst(line, i)));
    if (date == 0) ret;
    Pair<S> p = splitSquareBracketStuff(substring(line, i));
    print("[heard at " + date + "]: " + p.a + ": " + p.b);
    putLongUnique(events, date, new Event(date, cic(p.a, "typed") ? EType.typed : EType.heard, p.b));
  });
  
  waitUntilAllTailsHaveIdled(tail1, tail2);
  print("\nHave " + n(events, "event") + "\n");
  L<Event> l = valuesList(events);
  //pnlStruct(takeLast(10, l));
  for i over l: {
    Event e = l.get(i);
    long diff = i == 0 ? 0 : e.date-l.get(i-1).date;
    print("[" + diff + " ms] " + e.toStringWithoutDate());
  }
  print();
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1014605
Snippet name: Speak & Hear (dev.)
Eternal ID of this version: #1014605/16
Text MD5: 17aa5b2ae5003ba341a9f780e0e1c924
Transpilation MD5: 6ea3ce6990f58f599a3266ba3e53778c
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-04-26 23:46:03
Source code size: 1818 bytes / 57 lines
Pitched / IR pitched: No / No
Views / Downloads: 325 / 4352
Version history: 15 change(s)
Referenced in: [show references]