//package hello;

import java.io.*;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import javax.speech.*;
//import javax.speech.recognition.*;
import javax.speech.synthesis.*;

public class say {

    static Synthesizer synthesizer;
    static ResourceBundle resources;

    public static void main(String args[]) {

        try {

	    // locale, resources
	    if (args.length>0) Locale.setDefault(new Locale(args[0], ""));
	    if (args.length>1) Locale.setDefault(new Locale(args[0], args[1]));
	    dbg("locale is " + Locale.getDefault());
	    
        // create a synthesizer, speak a greeting
        Synthesizer synth = Central.createSynthesizer(null);
            
            myEngineListener listener = new myEngineListener();
            // synth.addEngineListener(listener);
            synth.allocate();
            
            // synthesizer.speak(resources.getString("greeting"), null);
            System.out.println("Before");
            synth.speak("hello this is a test", null);
            //synth.waitQueueEmpty();
            //System.out.println("after"+synth.isQueueEmpty());
            System.out.println("after");
            //synth.deallocate();

        } catch (Exception e) {
            e.printStackTrace();
	    System.exit(-1);

        }
    }

    static void dbg(String s) {
        System.out.println(s);
    }

}

class myEngineListener implements EngineListener {
    public void engineAllocated(EngineEvent e) {System.out.println("engineAllocated");}
    public void engineDeallocated(EngineEvent e) {System.out.println("engineDeallocated");}
    public void enginePaused(EngineEvent e) {System.out.println("enginePaused");}
    public void engineResumed(EngineEvent e) {System.out.println("engineResumed");}
}
