Saturday 30 May 2015

How generate Text to speech in Java?

DownLoad Freetts1.2 java Api....here and execute the jspi.exe in lib folder of freetts api.

Then start cmd and type..
set classpath=.../freetts1.2/lib/freetts.jar;.

Compile the folling code and place your String in command line argument to speak..


       


import com.sun.speech.freetts.FreeTTS;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
import com.sun.speech.freetts.audio.SingleFileAudioPlayer;
import java.io.FileInputStream;
import com.sun.speech.freetts.*;


public class MainSpeak {


public static void   speaking(String str){
 Voice voice;
 FreeTTS freetts;

 voice=VoiceManager.getInstance().getVoice("kevin16");
 if(voice!=null)
 {
 voice.allocate();
 }
 freetts=new FreeTTS(voice);
 voice.speak(str);
 
 
 }
public static void main(String[] args)throws Exception {

 MainSpeak m1=new MainSpeak();
 
 m1.speaking(args[0]);
 
}

}

 

No comments:

Post a Comment