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

1  
!7
2  
3  
enum EType { speakStart, speakEnd, heard, typed }
4  
5  
sclass Event {
6  
  long date;
7  
  EType type;
8  
  S text;
9  
  S voice;
10  
  
11  
  *() {}
12  
  *(long *date, EType *type, S *text) {}
13  
  *(long *date, EType *type, S *text, S *voice) {}
14  
  
15  
  toString {
16  
    ret date + ": " + toStringWithoutDate();
17  
  }
18  
  
19  
  S toStringWithoutDate() {
20  
    ret type + ": " + text + (nempty(voice) ? " (" + voice + ")" : "");
21  
  }
22  
}
23  
24  
static TailFile tail1, tail2;
25  
static Map<Long, Event> events = synchroTreeMap();
26  
27  
p-experiment {
28  
  tail1 = tailFileLinewiseFromStart(cereprocLog(), 100, voidfunc(S line) {
29  
    if ((line = forceProperUnquote(line)) == null) ret;
30  
    Pair<S> p = splitAtFirstSpace(line);
31  
    long date = parseLong(p.a);
32  
    Map map = unstructureMap(p.b);
33  
    print(date + ": " + sfu(map));
34  
    putLongUnique(events, date, new Event(date, swic(getString(map, 'action), "Begin") ? EType.speakStart : EType.speakEnd, getString(map, 'text), getString(map, 'voice)));
35  
  });
36  
  
37  
  tail2 = tailFileLinewiseFromStart(speechRecognitionLog(), 100, voidfunc(S line) {
38  
    if ((line = forceProperUnquote(line)) == null) ret;
39  
    int i = indexOf(line, '[');
40  
    long date = parseLongOpt(trim(takeFirst(line, i)));
41  
    if (date == 0) ret;
42  
    Pair<S> p = splitSquareBracketStuff(substring(line, i));
43  
    print("[heard at " + date + "]: " + p.a + ": " + p.b);
44  
    putLongUnique(events, date, new Event(date, cic(p.a, "typed") ? EType.typed : EType.heard, p.b));
45  
  });
46  
  
47  
  waitUntilAllTailsHaveIdled(tail1, tail2);
48  
  print("\nHave " + n(events, "event") + "\n");
49  
  L<Event> l = valuesList(events);
50  
  //pnlStruct(takeLast(10, l));
51  
  for i over l: {
52  
    Event e = l.get(i);
53  
    long diff = i == 0 ? 0 : e.date-l.get(i-1).date;
54  
    print("[" + diff + " ms] " + e.toStringWithoutDate());
55  
  }
56  
  print();
57  
}

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: 485 / 4687
Version history: 15 change(s)
Referenced in: [show references]