import javax.speech.*; import javax.speech.synthesis.*; import java.util.Locale; import java.net.URL; import java.io.*; public class Speaker{ public static void main(String args[]) { try { Synthesizer synth = Central.createSynthesizer( new SynthesizerModeDesc(Locale.ENGLISH)); synth.allocate(); synth.resume(); try{ String data = load( args[0] ); System.err.println("Try JSML file."); synth.speak(data, null); //<--- } catch( Exception e1 ){ try{ String data = load( args[0] ); System.err.println("Try XML file."); synth.speak( //<--- "" + data.replaceFirst("<[?]xml.*[?]>", "") + "", null); } catch( Exception e2 ){ try{ String data = load( args[0] ); System.err.println("Try text file."); synth.speakPlainText(data, null); //<--- } catch( Exception e3 ){ System.err.println("Try argument."); synth.speakPlainText(args[0], null); //<--- } } } synth.waitEngineState(Synthesizer.QUEUE_EMPTY); synth.deallocate(); } catch( Exception e4 ){ System.err.println("--- Error --- " ); } } static String load( String file ) throws Exception { String data = "", s; FileReader fr = new FileReader( file ); BufferedReader myIn = new BufferedReader( fr ); while( (s=myIn.readLine()) != null ){ data += s; } return data; } }