!747 import android.app.Activity; import android.speech.tts.TextToSpeech; m { static Activity androidContext; static TextToSpeech tts; static S text = "Hello Android"; p { if (args.length != 0 && args[0].length() != 0) text = join(" ", args); tts = new TextToSpeech(androidContext, new TextToSpeech.OnInitListener() { public void onInit(int status) { try { if (status != TextToSpeech.SUCCESS) fail("Speech engine initialization failed"); /* int result = tts.setLanguage(Locale.US); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) fail("English is not supported"); */ speak(); thread { sleepSeconds(20); // to be improved :) (OnUtteranceListener) androidContext.runOnUiThread(runnable { done(); }); } } catch (Throwable e) { e.printStackTrace(); } } }); } static void speak() { print(text); tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); } static void done() { print("Closing TTS"); tts.stop(); tts.shutdown(); tts = null; } }