I wanted to upgrade my eclipse version to the latest and it require me to upgrade also the java version. After upgrade(java 15/eclipse 12-2020) I've notice that simple code that I had with freetts is not working with the new configuration.
I still have the old eclipse version that uses java 8, so I did the same steps in the old and the new version: create java project, add all the relevant jars files and set simple demo class. In the old version it is working fine, while in the new it throws exception:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/speech/freetts/VoiceManager
at demoPackage.TextSpecchClass.<init>(TextSpecchClass.java:13)
at demoPackage.TextSpecchClass.main(TextSpecchClass.java:8)
Caused by: java.lang.ClassNotFoundException: com.sun.speech.freetts.VoiceManager
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 2 more
It seems basically that it cannot find the jars file but I'm not sure why, and if it related to the new eclipse version or the java upgrade.
*Also note that it in other sample I used external jar of sqllite and it worked, therefore it doesn't seems to happened with any jar, but something specific with the freetts
jars: (possible some are redundant...):
cmu_time_awb.jar
cmu_us_kal.jar
cmudict04.jar
cmulex.jar
cmutimelex.jar
en_us.jar
freetts.jar
freetts-jsapi10.jar
jsapi.jar
mbrola.jar
package demoPackage;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
public class TextSpecchClass {
public static void main(String[] args) {
new TextSpecchClass("Hello worlds");
}
public TextSpecchClass(String words) {
System.setProperty("freetts.voices",
"com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
Voice voice = VoiceManager.getInstance().getVoice("kevin16");
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(words);// Calling speak() method
} catch (Exception e1) {
e1.printStackTrace();
}
} else {
throw new IllegalStateException("Cannot find voice: kevin16");
}
}
}
Recent versions of Eclipse require at least a Java 11 JDK to run Eclipse, but you can compile/run the projects in Eclipse with older versions of the JDK. Ensure that you have both your Java 15 and Java 8 JDKs. Set Eclipse to run with the Java 15 JDK, and configure your project to use the "JavaSE-1.8" execution environment, and make sure that the Java 8 JDK is in the list of installed JDKs for that execution environment.