I am trying to develop a program that converts text to speech using freetts in java. I had already added all the required jar files and also build path.
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class TextToSpeech {
public static void main(String[] args) {
Voice voice;//Creating object of Voice class
voice = VoiceManager.getInstance().getVoice("kevin");//Getting voice
if (voice != null) {
voice.allocate();//Allocating Voice
}
try {
voice.setRate(190);//Setting the rate of the voice
voice.setPitch(150);//Setting the Pitch of the voice
voice.setVolume(3);//Setting the volume of the voice
voice.speak("Hello world");//Calling speak() method
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
But facing an error.
Exception in thread "main" java.lang.ClassCastException: class com.sun.speech.freetts.en.us.cmu_time_awb.AlanVoiceDirectory
Probably some jars were not linked correctly.. Started working as soon as I built the project using netbeans!
For those who might be having the same problem, use netbeans to avoid hassle of libraries.