10 Oct 2012

Text To Speech In Java Source Code

/* Text To Speech In Java Source Code, text to speech converter in java source code, text to speech in java, text to speech in java example */

import com.sun.speech.freetts.*;
import java.io.* ;
public class tts
{
private String speaktext;
public void dospeak(String speak,String voice)
{
speaktext=speak; 
try
{
VoiceManager voiceManager=VoiceManager.getInstance();
Voice voices=voiceManager.getVoice(voice);
Voice voices1[]=voiceManager.getVoices();
System.out.println("Available Voices");
for(int i=0;i<voices1.length;i++)
System.out.println(voices1[i].getName());
Voice sp=null;
if(voices!=null)
{
sp=voices; 
}
else
{
System.out.println("No Voice Available");
}
sp.allocate();
sp.speak(speaktext);
sp.deallocate();
}
catch(Exception e)
{
e.printStackTrace();
}

public static void main(String[] args)
{
String name=null;
//int value=0;
tts obj=new tts();
InputStreamReader istream=new InputStreamReader(System.in) ;
BufferedReader bufRead=new BufferedReader(istream) ;
try 
{
while(!("stop").equals(name))
{
//char c=(char)value;
name=bufRead.readLine();
//if(c==' ')
obj.dospeak(name,"kevin16");
//name=""+c;
}
}
catch(IOException err) 
{
System.out.println("Error reading line");
}
}
}

For ieee projects visit our site here

12 comments:

Anonymous said...

WHAT DO I NEED TO MAKE THE CODE WORK IN MY COMPUTER?

Unknown said...

basic jdk software is enough and speakers.

Unknown said...

and where is the package and class "com.sun.speech.freetts.*"

Unknown said...

set classpath to freetts.jar file.

Unknown said...

you need dowlond the package "freetts.zip" ,extr and add all jars into project

Unknown said...

good work.. but how to change the voice in,,,, natural male / female voice

Anonymous said...

Exception in thread "main" java.lang.Error: Unable to load voice directory. java.lang.ClassNotFoundException: com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory

Unknown said...

add freetts.jar to ur classpath

Unknown said...

Execute the program in netbeans with no error, but i didnt hear any voice, how to give the input and hear the sound, any help? if i type anythg it says that exception in thread main error.

Unknown said...

we need to i add third party library which i posted.

harshil patel said...

plz help me

harshil patel said...

plz help me

Post a Comment