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.

Unihedron
  • 10,902
  • 13
  • 62
  • 72
SaiCharan
  • 61
  • 4
  • 15
  • You're probably must add the library that contains javax/speech/EngineModeDesc – JFPicard Jul 23 '15 at 13:00
  • Do you have the required `jars` on your classpath? – brso05 Jul 23 '15 at 13:00
  • I have added all jars of freeTTS in my class path @brso05 – SaiCharan Jul 23 '15 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 '15 at 13:14
  • @kotlasaicharanreddy you never specified your class path that is why it isn't working... – brso05 Jul 23 '15 at 13:30
  • 1
    @kotlasaicharanreddy you need to add the argument `-cp` and then specify your class path when you call your program... – brso05 Jul 23 '15 at 13:32
  • @brso05 Sorry, I didn't get you . – SaiCharan Jul 23 '15 at 13:39
  • @kotlasaicharanreddy I posted an answer that is for `Windows` are you running on `Windows`? – brso05 Jul 23 '15 at 13:49
  • @brso05 I'm running on windows and I'm still getting the same error. – SaiCharan Jul 23 '15 at 13:57
  • @kotlasaicharanreddy where is your `jar` file located? – brso05 Jul 23 '15 at 14:04
  • @brso05 There are many jar file.Please, specify name of the jar file. – SaiCharan Jul 23 '15 at 14:15
  • @kotlasaicharanreddy you need to add all jar files to the classpath (all that are used). – brso05 Jul 23 '15 at 14:17
  • @brso05 I've added all jar files to the classpath but still error persists. – SaiCharan Jul 23 '15 at 14:29
  • @kotlasaicharanreddy did you specify the full path of the jars `C:\\example\example\jarfile.jar`? – brso05 Jul 23 '15 at 14:52
  • @kotlasaicharanreddy I don't know what else to tell you the problem is your program can't find the class file it's looking for. You can add the jar files to the JVM class path other than that not sure what more I can help you with. You can try running in IDE and add jars to classpath. The IDE will take care of running it for you... – brso05 Jul 23 '15 at 14:54

2 Answers2

0

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

A T - student
  • 212
  • 1
  • 12
-1

You need to specify your class path:

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

Answer taken from here

Community
  • 1
  • 1
brso05
  • 13,142
  • 2
  • 21
  • 40