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

// Note: This program continuously requires bandwidth while running.
// It will also keep running in the background, even with the display
// off. Press "STOP" or swipe the JavaX app away in the task switcher
// to terminate.

!7

import android.graphics.Color;

static TextView tv, tvStatus;
static ScrollView tvScroll;
static ContinuousEnglishRecognition rec;

please include function aContinuousEnglishRecognition.

p {
  sendToAll("Recognizer.", "kill");
  makeBot("Recognizer.");
  makeMyselfAware();
  
  androidUI(r {
    tvStatus = aTextView("Preparing...");
    tvStatus.setTextSize(20);
    tvStatus.setGravity(Gravity.CENTER);
    tvStatus.setTextColor(Color.RED);
    
    tv = aTextView();
    tv.setTextSize(40);
    tv.setGravity(Gravity.CENTER);
    tv.setTextColor(Color.BLACK);
    
    androidShow(aNorthCenterAndSouth(
      tvStatus,
      tvScroll = ascroll(tv),
      aHorizontalLinearLayout(
        aButton("CLEAR", f clear),
        aButton("STOP", f stop))));
  });
  
  rec = new ContinuousEnglishRecognition;
  rec.onSpeech = f onSpeech;
  rec.onReady = r { aSetText(tvStatus, "Listening."); start = now(); };
  rec.onUnready = r { aSetText(tvStatus, "Hold on...") };
  rec.start();
}

sS last = "";
static long time, start; // time = last word, start = first word of batch

static void onSpeech(L<S> l) {
  S s = first(l);
  //S ss = dropPrefixTrim(last, s);
  L<S> tokens = takeLast(12, javaTokC(s));
  S ss = joinLines(tokens);
  print("> " + ss);
  if (nempty(ss)) {
    time = now();
    last = joinWithSpace(tokens);
    aSetText(tv, ss);
    tvScroll.post(r {
      tvScroll.fullScroll(ScrollView.FOCUS_DOWN)
    });
  }
}

svoid clear {
  rec.stop();
  start = now();
  aSetText(tv, last = "");
  rec.start();
}

svoid cleanMeUp {
  if (rec != null) rec.stop();
  rec = null;
}

svoid stop {
  rec.stop();
  rec = null;
  androidShowText("DONE");
}

answer {
  if "text" ret start+"/"+time+"/"+now() + ": " + last;
  if "kill" { cleanUp(mc()); ret "ok"; }
}

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: 516 / 701
Version history: 41 change(s)
Referenced in: [show references]