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

87
LINES

< > BotCompany Repo | #1008218 // Continuous Speech Recognition [App]

JavaX source code (Android) [tags: use-pretranspiled] - run with: the app

Libraryless. Click here for Pure Java version (6152L/42K/140K).

1  
// Note: This program continuously requires bandwidth while running.
2  
// It will also keep running in the background, even with the display
3  
// off. Press "STOP" or swipe the JavaX app away in the task switcher
4  
// to terminate.
5  
6  
!7
7  
8  
import android.graphics.Color;
9  
10  
static TextView tv, tvStatus;
11  
static ScrollView tvScroll;
12  
static ContinuousEnglishRecognition rec;
13  
14  
please include function aContinuousEnglishRecognition.
15  
16  
p {
17  
  sendToAll("Recognizer.", "kill");
18  
  makeBot("Recognizer.");
19  
  makeMyselfAware();
20  
  
21  
  androidUI(r {
22  
    tvStatus = aTextView("Preparing...");
23  
    tvStatus.setTextSize(20);
24  
    tvStatus.setGravity(Gravity.CENTER);
25  
    tvStatus.setTextColor(Color.RED);
26  
    
27  
    tv = aTextView();
28  
    tv.setTextSize(40);
29  
    tv.setGravity(Gravity.CENTER);
30  
    tv.setTextColor(Color.BLACK);
31  
    
32  
    androidShow(aNorthCenterAndSouth(
33  
      tvStatus,
34  
      tvScroll = ascroll(tv),
35  
      aHorizontalLinearLayout(
36  
        aButton("CLEAR", f clear),
37  
        aButton("STOP", f stop))));
38  
  });
39  
  
40  
  rec = new ContinuousEnglishRecognition;
41  
  rec.onSpeech = f onSpeech;
42  
  rec.onReady = r { aSetText(tvStatus, "Listening."); start = now(); };
43  
  rec.onUnready = r { aSetText(tvStatus, "Hold on...") };
44  
  rec.start();
45  
}
46  
47  
sS last = "";
48  
static long time, start; // time = last word, start = first word of batch
49  
50  
static void onSpeech(L<S> l) {
51  
  S s = first(l);
52  
  //S ss = dropPrefixTrim(last, s);
53  
  L<S> tokens = takeLast(12, javaTokC(s));
54  
  S ss = joinLines(tokens);
55  
  print("> " + ss);
56  
  if (nempty(ss)) {
57  
    time = now();
58  
    last = joinWithSpace(tokens);
59  
    aSetText(tv, ss);
60  
    tvScroll.post(r {
61  
      tvScroll.fullScroll(ScrollView.FOCUS_DOWN)
62  
    });
63  
  }
64  
}
65  
66  
svoid clear {
67  
  rec.stop();
68  
  start = now();
69  
  aSetText(tv, last = "");
70  
  rec.start();
71  
}
72  
73  
svoid cleanMeUp {
74  
  if (rec != null) rec.stop();
75  
  rec = null;
76  
}
77  
78  
svoid stop {
79  
  rec.stop();
80  
  rec = null;
81  
  androidShowText("DONE");
82  
}
83  
84  
answer {
85  
  if "text" ret start+"/"+time+"/"+now() + ": " + last;
86  
  if "kill" { cleanUp(mc()); ret "ok"; }
87  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1008218
Snippet name: Continuous Speech Recognition [App]
Eternal ID of this version: #1008218/42
Text MD5: e21163c1ff1e11c2deb136d772fc696e
Transpilation MD5: 58b0b03e229e0c895ba44332786da4db
Author: stefan
Category: javax / speech recognition
Type: JavaX source code (Android)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-05-03 13:29:19
Source code size: 2080 bytes / 87 lines
Pitched / IR pitched: No / No
Views / Downloads: 517 / 703
Version history: 41 change(s)
Referenced in: [show references]