Friday, 27 April 2012

Java text to speech example


/*
*you have to use javax.speech api jar file or cloud garden api
*http://www.cloudgarden.com/JSAPI/
*
*/


import javax.speech.AudioException;
import javax.speech.Central;
import javax.speech.EngineException;
import javax.speech.EngineStateError;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerProperties;

public class SpeechToText {

    public static void main(String[] args) {
        try {
           
           
;  

            String d = "deepak";

            Synthesizer synth = Central.createSynthesizer(null);
            synth.allocate();
            synth.resume();
            SynthesizerProperties props = synth.getSynthesizerProperties();
            synth.speakPlainText(d, null);

            props.setVolume(5.0f);
            props.setSpeakingRate(200.0f);

            synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
            synth.deallocate();

        } catch (IllegalArgumentException | EngineException | EngineStateError | AudioException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}

Tuesday, 13 December 2011

computer name using java code

String currentUser = System.getProperty("user.name");
        System.out.println(currentUser);