set flag NoAWT. set flag Android. import android.app.*; import android.content.*; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.speech.RecognitionListener; import android.speech.RecognizerIntent; import android.speech.SpeechRecognizer; import android.widget.Button; import android.widget.TextView; import android.util.Log; import android.media.*; static SpeechRecognizer sr; static final String TAG = "MyStt3Activity"; static S language = "de-DE"; static int extraResults = 1; static S voice = "Leopold"; static bool fastSynthesis = false; // use device voice (faster) static bool noSpeech = false; // disable speech output static bool manualStart = false; // Start recognition on click only static volatile bool listening; static new L history; svoid leoMain { androidSay_keepEngine = true; S hello = null; /*if (args.length != 0 && args[0].equals("nogfx")) setOpt(getMainClass(), "showPicture", false);*/ try { history.add("*"); //hello = callStaticAnswerMethod("*", history); if (hello == null) hello = "hallo"; } catch (Throwable e) { e.printStackTrace(); return; } say(hello); callOpt(getMainClass(), "happy"); androidUI(r { //androidMuteAudio(androidActivity()); if (!manualStart) newRecognizer(); }); sleep(); } static void newRecognizer() { sr = SpeechRecognizer.createSpeechRecognizer(androidActivity()); sr.setRecognitionListener(new listener()); recog(); } static class listener implements RecognitionListener { public void onReadyForSpeech(Bundle params) { callOpt(getMainClass(), "setBorderColor", 0xFF66FF66); showText(german() ? "SAG WAS." : "TALK NOW."); } public void onBeginningOfSpeech() { showText("User talks"); callOpt(getMainClass(), "oh"); if (!manualStart) androidMuteAudio(); // Mute now, so we don't hear the end-of-speech sound } public void onRmsChanged(float rmsdB) {} public void onBufferReceived(byte[] buffer) {} public void onEndOfSpeech() { showText("onEndOfSpeech"); callOpt(getMainClass(), "setBorderColor", 0xFFFFFFFF); } public void onError(int error) { listening = false; if (error == 6) // timeout print("speech timeout"); else print("error " + error); // screw the errors! try { sr.destroy(); } catch (Throwable e) { print(e); } if (!manualStart) newRecognizer(); callOpt(getMainClass(), "happy"); } public void onResults(Bundle results) { listening = false; //showText("onResults"); ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); final S s = data.get(0); showText((german() ? "Ich habe geh\u00f6rt: " : "I heard: ") + quote(s)); // TODO: fix the java strings umlaut problem final boolean goodbye = match3("goodbye", s) || match3("bye", s) || match3("tsch\u00fcss", s) || match3("tsch\u00fcss ...", s); thread { // get answer history.add(s); S answer; try { answer = goodbye ? "tsch\u00fcss" : callStaticAnswerMethod(s, history); } catch (Throwable e) { e.printStackTrace(); appendToFile(getProgramFile("errors.txt"), getTheStackTrace(e)); answer = "Fehler"; } if (answer != null) say(answer); androidUI(r { if (goodbye) { print("\nGOODBYE!"); sr.destroy(); callOpt(getMainClass(), "disappear"); } else { sr.stopListening(); listening = false; //newRecognizer(); // always make a new one - gives endless errors if (!manualStart) recog(); } }); } // end of thread } public void onPartialResults(Bundle partialResults) { print("onPartialResults"); } public void onEvent(int eventType, Bundle params) { print("onEvent" + eventType); } } static void recog() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language); intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test"); intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, extraResults); // customize recognition time settings callOpt(mc(), "recogTimeSettings", intent); sr.startListening(intent); listening = true; //print("started listening"); } static void say(S s) { showText(">> " + s); history.add(s); androidUnmuteAudio(androidActivity()); if (!noSpeech) { if (fastSynthesis) { if (german()) androidSayInGerman(s); else androidSayInEnglish(s); } else { File mp3 = cereproc_silent(voice, s); androidPlayMp3(androidActivity(), mp3); } } //androidMuteAudio(); } static void stopListening() { listening = false; if (sr != null) sr.stopListening(); } sbool german() { ret swic(language, "de"); }