// 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 l) { S s = first(l); //S ss = dropPrefixTrim(last, s); L 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"; } }