Home > Uncategorized > Setup java speech jsapi using FreeTTS

Setup java speech jsapi using FreeTTS

April 13th, 2009

Getting JSAPI setup to work using freetts seems to be quite difficult as seen by here, here, here…..

Turns out the install instructions were incomplete. The instructions were:

1. Go to the FreeTTS/lib directory
2. Type .\jsapi.exe
3. If the binary license agreement is acceptable, accept
it by clicking “I Agree”. The jsapi.jar file will be unpacked
and deposited into the lib directory.

What you actually want to do is:

  1. Download FreeTTS
  2. Unzip the freeTTS binary package and check inside the \lib directory for jsapi.exe
  3. Run Jsapi.exe, say yes, to unpack jsapi.jar
  4. Find your JRE directory, mine was C:\Program Files\Java\jdk1.6.0_03\jre\lib\ext
  5. Copy all the Jars (jsapi.jar, freetts.jar, cmu_time_awb.jar, cmu_us_kal.jar, etc.) to that directory
  6. Check in netbeans your projects properties ie right click on project->properties->libraries->manage platforms and the jars should be listed there. If they are not, restart and hopefully they should now be there.
    Netbeans Freetts Setup

    Netbeans Freetts Setup

  7. Copy speech.properties to the relevant folder. To find out where this is run the HelloWorld example that comes with FreeTTS. In my case the file was located in C:\Documents and Settings\Username\java.home\lib and contained the following
    1
    2
    3
    4
    5
    
    # Modify this accordingly...
    #
    #TextSynthEngineCentral=com.sun.speech.engine.synthesis.text.TextEngineCentral
    #
    FreeTTSSynthEngineCentral=com.sun.speech.freetts.jsapi.FreeTTSEngineCentral

    Or you can set the property using

    1
    
    System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");

Any problems, post here and I will try to help you out.

Uncategorized , , ,

  1. dinesh
    April 30th, 2009 at 15:21 | #1

    Step 7 is not clear.
    please explain it clearly. in which folder “java folder” or ” netbeans folder” or “project folder” or other folder we have to copy speech.properties

  2. May 1st, 2009 at 10:32 | #2

    @dinesh
    Run the helloworld sample that comes with FreeTTS it will tell you for sure which folder. In my case the folder was:
    C:\Documents and Settings\Username\java.home\lib

  3. Shiv
    June 9th, 2009 at 00:25 | #3

    Hey i got my Helloworld example to work. Am using eclipse And i have used the sample code from the sun website for helloworld.

    import javax.speech.*;
    import javax.speech.synthesis.*;
    import java.util.Locale;

    public class HelloWorld {
    public static void main(String args[]) {
    try {
    // Create a synthesizer for English
    Synthesizer synth = Central.createSynthesizer(
    new SynthesizerModeDesc(Locale.ENGLISH));

    // Get it ready to speak
    synth.allocate();
    synth.resume();

    // Speak the “Hello world” string
    synth.speakPlainText(”Hello, world!”, null);

    // Wait till speaking is done
    synth.waitEngineState(Synthesizer.QUEUE_EMPTY);

    // Clean up
    synth.deallocate();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

    after compiling, console output says”mbrola voices do not exist” which is the same i got from executing HelloWorld.jar from freetts\lib. But I dont get any output audio. Whats wrong? When i execute the HelloWorld.jar in the lib folder, i get Hello World as audio output. But no speech in eclipse when executing above code. Help!!

  4. dana
    June 10th, 2009 at 19:59 | #4

    OMG !! its WORKING its WORKING
    Thank you VERY MUCH… U R a life Saver… !!
    U r page will diffinitly go into my favorite…

    Thanksssssss

  5. mido
    August 11th, 2009 at 19:36 | #5

    hi step 7 isn’t work with me and the examples are work but when i make a program it does not work plz help

  6. kikou
    October 26th, 2009 at 10:03 | #6

    Hi, I am a student and I have a project to help blind I download TTS but I can not find the Arabic synthesizer can you help me please Thank you

  7. Timmy
    November 21st, 2009 at 01:49 | #7

    I needed speech.properties here…
    C:\Program Files\Java\jdk1.6.0_16\jre\lib

    and all jars from…
    C:\Downloads\Java\freetts-1.2.2-bin\freetts-1.2
    in…
    C:\Program Files\Java\jdk1.6.0_16\jre\lib\ext

  8. Mauricio
    October 14th, 2010 at 01:57 | #8

    Hey there, thanks a lot, you really helped me, I didnt know all I needed was to add all the .jar files to my Build Path.

  9. Francis
    October 21st, 2010 at 01:13 | #9

    Thx a lot i got it work ahahahah thx thx thx

  10. rob
    November 17th, 2010 at 05:54 | #10

    Hi ,I am an engineer trying to use freetts on Java Speech API . I followed your instructions above and i dont get any error on netbeans. However I dont get any audio either. I modified the code slightly and noticed the program hangs as illustrated on the code snippet below

    import javax.speech.*;
    import javax.speech.synthesis.*;
    import java.util.Locale;

    public class helloWorld {
    public static void main(String args[]) {
    try {
    // Create a synthesizer for English
    Synthesizer synth = Central.createSynthesizer(
    new SynthesizerModeDesc(Locale.ENGLISH));

    System.out.println(”aaaaaaaaaaa”);
    // Get it ready to speak
    synth.allocate();
    System.out.println(”bbbbbbbbbbb”);
    synth.resume();

    System.out.println(”ccccccccccc”);
    // Speak the “Hello world” string
    synth.speakPlainText(”Hello, world!”, null);

    System.out.println(”dddddddddddd”);

    // Wait till speaking is done
    synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
    System.out.println(”eeeeeeeeeeee”);

    // Clean up
    synth.deallocate();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

    The output i got was

    System property “mbrola.base” is undefined. Will not use MBROLA voices.
    aaaaaaaaaaa
    bbbbbbbbbbb
    ccccccccccc
    dddddddddddd

    so the program hangs was wondering why.
    I am using Ubuntu 9.10 and Netbeans 6.9.1

  11. S.Suja
    December 29th, 2010 at 12:47 | #11

    Hey i got my Helloworld example to work. Am using eclipse And i have used the sample code from the sun website for helloworld.

    import javax.speech.*;
    import javax.speech.synthesis.*;
    import java.util.Locale;

    public class HelloWorld {
    public static void main(String args[]) {
    try {
    // Create a synthesizer for English
    Synthesizer synth = Central.createSynthesizer(
    new SynthesizerModeDesc(Locale.ENGLISH));

    // Get it ready to speak
    synth.allocate();
    synth.resume();

    // Speak the “Hello world” string
    synth.speakPlainText(”Hello, world!”, null);

    // Wait till speaking is done
    synth.waitEngineState(Synthesizer.QUEUE_EMPTY);

    // Clean up
    synth.deallocate();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

    after compiling, console output says”java.lang.NullPointerException
    at HelloWorld.main(HelloWorld.java:36)”
    Help.

  12. Anesh
    March 10th, 2011 at 12:05 | #13

    sir i create synthesizer code but this code output get the exception is null pointer exception
    sir why the htrows this exception
    immediately
    and sir give me total step for running the code of speech synthesizer

  13. Anesh
    March 10th, 2011 at 12:10 | #14

    i use the simple edutor like as notepad and jdk 1.6 and speech package

  14. PraveenMJ
    March 18th, 2011 at 10:57 | #15

    thank you very much. i am striving my head for a week to add tts to netbeans. really good work .

  15. jeyaraj
    March 23rd, 2011 at 10:58 | #16

    hi ryan,

    I’m having the problem faced by S.Suja.
    Kindly help.

  16. raj
    March 25th, 2011 at 00:41 | #17

    Hi Ryan,

    Thanks for the tutorial.
    I’m having the same problem as rob and s.suja.
    Kindly help.

  17. syed shaheaz ali
    April 2nd, 2011 at 05:18 | #18

    7th step can be resolved using System.out.println (System.getProperty(

    “java.home” ) );
    but how to set the mbrola voices i am getting this error
    System property “mbrola.base” is undefined. Will not use MBROLA voices.

  18. Rea
    April 3rd, 2011 at 10:36 | #19

    @S.Suja
    I get the same problem as S.Suja, did you find a solution for that? If yes,could you please share it?

  19. J. Fernando Galvez
    April 19th, 2011 at 19:50 | #20

    @rob

    rob :
    Hi ,I am an engineer trying to use freetts on Java Speech API . I followed your instructions above and i dont get any error on netbeans. However I dont get any audio either. I modified the code slightly and noticed the program hangs as illustrated on the code snippet below
    import javax.speech.*;
    import javax.speech.synthesis.*;
    import java.util.Locale;
    public class helloWorld {
    public static void main(String args[]) {
    try {
    // Create a synthesizer for English
    Synthesizer synth = Central.createSynthesizer(
    new SynthesizerModeDesc(Locale.ENGLISH));
    System.out.println(”aaaaaaaaaaa”);
    // Get it ready to speak
    synth.allocate();
    System.out.println(”bbbbbbbbbbb”);
    synth.resume();
    System.out.println(”ccccccccccc”);
    // Speak the “Hello world” string
    synth.speakPlainText(”Hello, world!”, null);
    System.out.println(”dddddddddddd”);
    // Wait till speaking is done
    synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
    System.out.println(”eeeeeeeeeeee”);
    // Clean up
    synth.deallocate();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }
    The output i got was
    System property “mbrola.base” is undefined. Will not use MBROLA voices.
    aaaaaaaaaaa
    bbbbbbbbbbb
    ccccccccccc
    dddddddddddd
    so the program hangs was wondering why.
    I am using Ubuntu 9.10 and Netbeans 6.9.1

    i have the same problem where install the voices..?? and where i can download the voices to work…:S thk.. :D

  20. rakesh
    April 21st, 2011 at 13:54 | #21

    @dana
    excuse me… if you don’t mind, i really need certain help in making it work, can i expect some support from your side..!!

  21. rakesh
    April 24th, 2011 at 16:09 | #22

    thanks for your help dude… atlast it is working for me… now my project is half done.. :)

  22. Nick
    June 11th, 2011 at 17:03 | #23

    Thanks for the instructions! This was way more difficult to install than it should have been.

    For those of you confused about step 7: Run the “HelloWorld.jar” from the command line (if in windows, it will look something like this):

    java -jar HelloWorld.jar

    This should spit out some text output that will tell you where your speech.properties file needs to go. Here’s the output from mine:

    C:\Users\Nicholas\Downloads\freetts-1.2.2-bin\freetts-1.2\bin>java -jar HelloWorld.jar

    All general Mode JSAPI Synthesizers and Voices:

    Using voice: kevin16
    No synthesizer created. This may be the result of any
    number of problems. It’s typically due to a missing
    “speech.properties” file that should be at either of
    these locations:

    user.home : C:\Users\Nicholas
    java.home/lib: C:\Program Files\Java\jre6\lib

    Another cause of this problem might be corrupt or missing
    voice jar files in the freetts lib directory. This problem
    also sometimes arises when the freetts.jar file is corrupt
    or missing. Sorry about that. Please check for these
    various conditions and then try again.

  23. Aakriti
    September 28th, 2011 at 09:46 | #24

    Thank you so much! :-)

  24. sandeep
    October 3rd, 2011 at 09:06 | #25

    Exception in thread “main” java.lang.RuntimeException: Uncompilable source code - illegal start of expression
    at voice.Main.main(Main.java:18)
    Java Result: 1

  25. Mike
    October 9th, 2011 at 05:10 | #26

    Hell Yeah!!!
    Many Thanks to You Guys:). I’ve finally made it to work.
    Works Perfectly

  26. harpreet
    November 16th, 2011 at 00:59 | #27

    hi Ryan,i am doing a project based on speech recognition in j2me..if you know about it anything relevant then pls help me…thanx

  27. Skybird
    December 14th, 2011 at 01:45 | #28

    Hi all,
    I got problem in the step 6. When installing Jsapi.exe I get a msg:
    the program might have not installed correctly.try re-installing..
    Can anyone help?

  28. Guillermo
    January 15th, 2012 at 12:55 | #29

    @Skybird,

    I also got that message I believe. I let it correct it with the popup that stated something like “Should I fix this issue”.

    (Theory)
    I believe it happens because I have a 64bit machine and it might be an issue with a 32 bit program (jsapi.exe) trying to run its course. Let it fix the issue.

    But more than anything, in whatever folder you have jsapi.exe run it, it will add the file jsapi.jar. Once you see that jar file you can make a copy of it and rename the copy to “jsapi.zip”. If you double click it, it will automatically open in your zip utility. Now you should be able to see the jar structure.

    you will see
    [YOUR PATH]\jsapi\javax\speech (contains the Central class)
    [YOUR PATH]\jsapi\javax\speech\synthesis (Synthesizer specific classes)
    [YOUR PATH]\jsapi\javax\speech\recognizer (recognizer specific classes)

    If you can see these in the .zip file then your jar is so far correct. Of course now you want to add it to your classpath so that it is accessible. Now you have to make sure you place the jsapi.jar file in your java.home folder in my case it is “C:\Program Files\Java\jdk1.6.0_18\jre\lib\ext”. This ensures that it gets loaded by the JVM and is accesible.

    Now compile the following and run. You should see in your console no error or an error letting you know that the Central class does not exist. If that is the case the jsapi.jar file is in the wrong place.

    //********* TestSynth.java BELOW **************
    import javax.speech.*;

    public class TestSynth {

    public static void main(String[] args) {
    try{
    EngineList list = Central.availableSynthesizers(null);
    if(list.isEmpty()){
    System.out.println(”No Engines Available”);
    }
    else{
    for (int i = 0; i < list.size(); i++){
    SynthesizerModeDesc desc = (SynthesizerModeDesc) list.get(i);
    Voice[] voices = desc.getVoices();
    for (int j = 0; j < voices.length; j++) {
    System.out.println(” ” + voices[j].getName());
    }
    }
    }
    }catch(Exception e){
    e.printStackTrace();
    }
    }
    }

    I hope i wasnt to long winded and hope it helps.
    Guillermo

  29. Roger
    February 22nd, 2012 at 10:57 | #30

    I had much of these same problems when getting it to compile and now have it compiling, but like Shiv, I haven’t yet been able to get it to output audio when running within Eclipse. However, for those who are having the null pointer exceptions, here is what I found:
    1) Absolutely run java -jar bin/HelloWorld.jar from the freetts folder. I thought I was using one JRE and I was really using another (64-bit Vista machine - so I should have been looking in Program Files, not Program Files (x86))
    2) Edit the speech.properties and voices.txt files if you are in Windows. They need to be cleaned up because the line breaks are not windows compatible. It looks like everything is commented out. The speech engine must be on it’s own line in speech.properties. This may be different for Linux - haven’t tried that yet.
    3) Make sure your classpath environment variable includes the right JRE.

    I did those things and it’s compiling and running correctly. However, as I said earlier, no audio when selecting RUN within Eclipse.

  30. Roger
    February 22nd, 2012 at 10:58 | #31

    @Skybird
    Just say “No”. I had the same error, but my JSAPI.jar is correct. Think it’s a problem with the installer.

  31. Roger
    February 22nd, 2012 at 13:49 | #32

    I found the issue with no sound on the demo in Eclipse. Add this line beneath the SpeakPlainText() line:

    synth.waitEngineState(Synthesizer.QUEUE_EMPTY);
    synth.speakPlainText(”1 2 3 4 5 6 7 8 9 ten”, null);

    I found that the voice “Alan” was being defaulted and since Alan only knows about time, “Hello World” is not in the vocabulary, but counting is. If you get Alan speaking the numbers, all is well and you can continue on with development. Still trying to track down how I got Alan to be the default voice.

  1. No trackbacks yet.