The following is the code I'm writing to implement Text to Speech in java using freeTTS and mbrola.
I have added all jars of freeTTS to my classpath.
import java.applet.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.speech.Central;
import javax.speech.EngineList;
import javax.speech.EngineCreate;
import javax.speech.synthesis.SynthesizerModeDesc;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.Voice;
import com.sun.speech.freetts.jsapi.FreeTTSEngineCentral;
import java.util.Locale;
import java.awt.Event;
public class voisedemo extends Applet implements ActionListener
{
public Synthesizer synth;
private static Voice kevinHQ;
TextField t1;
public void init()
{
Button b1 = new Button("press me");
add(b1);
b1.addActionListener(this);
t1 = new TextField(50);
add(t1);
}
public void start()
{
}
public void actionPerformed(ActionEvent e)
{
// synthesizer.speakPlainText(“Hello, world!”, null);
try {
setKevinHQ(new Voice("Hitesh",
Voice.AGE_NEUTRAL,
Voice.GENDER_MALE,
null ));
System.setProperty("mbrola.base", "C:/Users/Sai/Downloads/mbrola");
SynthesizerModeDesc modeDesc = new SynthesizerModeDesc(
null,
"general", /* use “time” or “general” */
Locale.US,
Boolean.FALSE,
null);
FreeTTSEngineCentral central = new FreeTTSEngineCentral();
Synthesizer synthesizer = null;
synthesizer = Central.createSynthesizer( modeDesc );
EngineList list = central.createEngineList(modeDesc);
if (list.size() > 0) {
EngineCreate creator = (EngineCreate) list.get(0);
synthesizer = (Synthesizer) creator.createEngine();
}
if (synthesizer == null) {
System.err.println("Cannot create synthesizer");
System.exit(1);
}
//get ready to speak
synthesizer.allocate();
synthesizer.resume();
String s1 = t1.getText();
synthesizer.speakPlainText(s1, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
synthesizer.deallocate();
} catch (Exception eq) {
eq.printStackTrace();
}
}
public static void setKevinHQ(Voice kevinHQ) {
voisedemo.kevinHQ = kevinHQ;
}
public static Voice getKevinHQ() {
return kevinHQ;
}
public void paint(Graphics g)
{
}
}
I compiled it in command prompt using:
C:\Users\Sai\Desktop\Mini Project>javac voisedemo.java
There are no compilation errors.
But when ever I run it using:
C:\Users\Sai\Desktop\Mini Project>java voisedemo
I'm getting the following the runtime errors:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: javax/speech/EngineModeDesc
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.speech.EngineModeDesc
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
This program is a part of my mini project.
Please help me solve this error.