!747 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.*; main { static Activity androidContext; static SpeechRecognizer sr; static final String TAG = "MyStt3Activity"; static boolean loop = true; static S language = "de-DE"; static int extraResults = 1; static S voice = "Leopold"; static new L history; p { say("hallo"); androidContext.runOnUiThread(runnable { //androidMuteAudio(androidContext); newRecognizer(); }); sleep(); } static void newRecognizer() { sr = SpeechRecognizer.createSpeechRecognizer(androidContext); sr.setRecognitionListener(new listener()); recog(); } static class listener implements RecognitionListener { public void onReadyForSpeech(Bundle params) { print("SAG WAS."); } public void onBeginningOfSpeech() {} public void onRmsChanged(float rmsdB) {} public void onBufferReceived(byte[] buffer) {} public void onEndOfSpeech() {} public void onError(int error) { //print( "error " + error); // screw the errors! //if (loop) recog(); try { sr.destroy(); } catch (Throwable e) { print(e); } if (loop) newRecognizer(); } public void onResults(Bundle results) { //print("onResults " + results); ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); final S s = data.get(0); print("Ich habe geh\u00f6rt: " + quote(s)); //print("I heard: " +structure(data)); // 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" : answer(s, history); } catch (Throwable e) { e.printStackTrace(); answer = "Fehler"; } if (answer != null) say(answer); androidContext.runOnUiThread(runnable { if (goodbye) { print("\nGOODBYE!"); sr.destroy(); } else if (loop) { sr.stopListening(); recog(); } }); } // end of thread } public void onPartialResults(Bundle partialResults) {} public void onEvent(int eventType, Bundle params) {} } 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); sr.startListening(intent); //print("started listening"); } static void say(S s) { androidUnmuteAudio(androidContext); File mp3 = new File(getProgramDir(), "bla.mp3"); makeSpeechCereproc(s, voice, mp3); androidPlayMp3(androidContext, mp3); androidMuteAudio(androidContext); } //// static synchronized S answer(S s, L history) { if (match3("wie hei\u00dft du", s)) return "Leopold"; if (match3("wie ist deutschland", s)) return "es ist h\u00e4sslich"; if (match3("wie ist \u00f6sterreich", s)) return "es ist sehr sch\u00f6n"; if (match3("du bist lustig", s)) return "danke sch\u00f6n"; return s; } }