0

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.

15
  • You're probably must add the library that contains javax/speech/EngineModeDesc
    – JFPicard
    Jul 23, 2015 at 13:00
  • Do you have the required jars on your classpath?
    – brso05
    Jul 23, 2015 at 13:00
  • I have added all jars of freeTTS in my class path @brso05
    – SaiCharan
    Jul 23, 2015 at 13:11
  • @kotlasaicharanreddy according to the error you are missing EngineModeDesc class from your class path so probably you either didn't add them correctly or maybe the jar files you added don't contain javax.speech.EngineModeDesc please make sure the class is contained in the jar file then make sure it is referenced on the class path...are you running this in eclipse or some other IDE?
    – brso05
    Jul 23, 2015 at 13:14
  • 1
    @kotlasaicharanreddy you need to add the argument -cp and then specify your class path when you call your program...
    – brso05
    Jul 23, 2015 at 13:32

2 Answers 2

0

You are missing the jsapi.jar file, available with the voce distribution.

-1

You need to specify your class path:

java -cp (fullpathifnotincurrentworkingdirectory)yourjarfile.jar;. voicedemo

Answer taken from here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.