import javax.imageio.*; import java.awt.image.*; import java.awt.event.*; import java.awt.*; import java.security.NoSuchAlgorithmException; import java.security.MessageDigest; import java.lang.management.*; import java.lang.reflect.*; import java.net.*; import java.io.*; import javax.swing.text.*; import javax.swing.event.*; import javax.swing.*; import java.util.concurrent.atomic.*; import java.util.concurrent.*; import java.util.regex.*; import java.util.List; import java.util.zip.*; import java.util.*; import android.app.Activity; import android.speech.tts.*; public class main { static Activity androidContext; static TextToSpeech tts; static String text = "Ich bin der Leopold"; public static void main(String[] args) throws Exception { 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.GERMAN); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) fail("German is not supported"); result = tts.setOnUtteranceProgressListener(new UtteranceProgressListener() { public void onDone(String utteranceId) { print("onDone"); done(); } public void onError(String utteranceId) { print("onError"); } public void onStart(String utteranceId) { } }); if (result != TextToSpeech.SUCCESS) print("Could not set listener"); speak(); } catch (Throwable e) { e.printStackTrace(); } } }); } static void speak() { print(text); HashMap params = new HashMap(); params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "UniqueID"); tts.speak(text, TextToSpeech.QUEUE_FLUSH, params); } static void done() { print("Closing TTS"); tts.stop(); tts.shutdown(); tts = null; } static void print() { System.out.println(); } static void print(Object o) { System.out.println(o); } static void print(long i) { System.out.println(i); } public static String join(String glue, Iterable strings) { StringBuilder buf = new StringBuilder(); Iterator i = strings.iterator(); if (i.hasNext()) { buf.append(i.next()); while (i.hasNext()) buf.append(glue).append(i.next()); } return buf.toString(); } public static String join(String glue, String[] strings) { return join(glue, Arrays.asList(strings)); } public static String join(Iterable strings) { return join("", strings); } public static String join(String[] strings) { return join("", strings); } static RuntimeException fail() { throw new RuntimeException("fail"); } static RuntimeException fail(Object msg) { throw new RuntimeException(String.valueOf(msg)); } }