/**
 * Copyright 2001 Sun Microsystems, Inc.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 */

package demo.jsapi.cardmatch;

import java.io.File;

import java.util.Locale;

import javax.speech.Central;
import javax.speech.Engine;
import javax.speech.EngineStateError;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;
import javax.speech.synthesis.SynthesizerProperties;
import javax.speech.synthesis.Voice;

import com.sun.speech.freetts.util.Utilities;


/**
 * Manages TTS output
 */
public class CardMatchVoice {

    private Synthesizer synthesizer;
    
    public CardMatchVoice() throws Exception {
	try {
            String synthesizerName = Utilities.getProperty
                ("synthesizerName",
                 "Unlimited domain FreeTTS Speech Synthesizer from Sun Labs");

	    // Create a new SynthesizerModeDesc that will match the FreeTTS
	    // Synthesizer.
	    SynthesizerModeDesc desc = new SynthesizerModeDesc
		(synthesizerName,
		 null,
		 Locale.US,
		 Boolean.FALSE,         // running?
		 null);                 // voice

	    synthesizer = Central.createSynthesizer(desc);

	    if (synthesizer == null) {
		String message = "Can't find synthesizer.\n" +
		    "Make sure that there is a \"speech.properties\" file " +
		    "at either of these locations: \n";
		message += "user.home    : " + 
		    System.getProperty("user.home") + "\n";
		message += "java.home/lib: " + System.getProperty("java.home")
		    + File.separator + "lib\n";
		
		System.err.println(message);
                throw new Exception("JSAPI Synthesizer cannot be constructed");
	    }

            // create the voice
            String voiceName = System.getProperty("voiceName", "kevin16");
	    Voice voice = new Voice
                (voiceName, Voice.GENDER_DONT_CARE, Voice.AGE_DONT_CARE, null);

	    // get it ready to speak
	    synthesizer.allocate();
	    synthesizer.resume();
            synthesizer.getSynthesizerProperties().setVoice(voice);

        } catch (Exception e) {
            e.printStackTrace();
            throw new Exception("Unable to initialize CardMatchVoice");
        }
    }

    /**
     * Speaks the given string of text.
     *
     * @param text the text to speak
     */
    public void speak(String text) {
        if (synthesizer != null) {
            try {
                synthesizer.speakPlainText(text, null);
            } catch (EngineStateError ese) {
                ese.printStackTrace();
            }
        } else {
            System.out.println("CardMatchVoice unavailable");
        }
    }

    /**
     * Shuts down this CardMatchVoice.
     */
    public void close() {
        if (synthesizer != null) {
            try {
                synthesizer.deallocate();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

@@ -547,55 +547,8 @@
 e;%0A%0A
-import com.sun.speech.freetts.util.Utilities;%0A%0A
 %0A/**
@@ -742,18 +742,8 @@
 e = 
-Utilities.
 getP
@@ -2188,32 +2188,717 @@
        %7D%0A    %7D%0A%0A
+    /**%0A     * Gets a property by name and returns its value. If the property%0A     * cannot be found, the default is returned%0A     *%0A     * @param name the name of the property%0A     *%0A     * @param defaultValue the default value to use if the property%0A     * cannot be found.%0A     *%0A     * @return the string value for the property, or the defaultValue if %0A     *  the property cannot be found%0A     */%0A    public static String getProperty(String name, String defaultValue) %7B%0A        String value;%0A        try %7B%0A            value = System.getProperty(name, defaultValue);%0A        %7D catch (SecurityException se) %7B%0A            value = defaultValue;%0A        %7D%0A        return value;%0A    %7D%0A%0A
     /**%0A     * S

Removed the need to 'import com.sun.speech.freetts.util.Utilities;'.