Speech Synthesis in Java Using FreeTTS

Would you like your computer to talk? Would you like it to be in a stilted, robotic manner? Of course you would. What’s cooler than that? But you’d better get started right away, because a bunch of movie characters from the 1980’s have about thirty years of head start on you already, and if you don’t get on the stick they’re going to scoop up all the hot 1980’s babes before you can impress them with your rad 1980’s robot.

Make sure it tells them it’s programmed for love!

1. Download FreeTTS. FreeTTS is an open source implementation of JSAPI (the Java Speech API). JSAPI is a set of interfaces that can be used to perform speech synthesis, or “text-to-speech”, from Java programs. As of this writing, the archive file containing the latest version of the FreeTTS libraries is named “freetts-1.2.2-bin.zip”, and can be downloaded from the URL http://sourceforge.net/projects/freetts/files/.

2. Locate the downloaded FreeTTS archive file and extract it to any convenient location.

3. Open the extracted FreeTTS folder and navigate down the directory structure to the “lib” directory. The lib directory contains several jar files that will be needed to compile the test program.

4. In any convenient location, create a new directory named “SpeechSynthesisTest”.

5. Copy the files “cmu_us_kal.jar”, “cmulex.jar”, “en_us.jar”, and “freetts.jar” from the lib directory to the SpeechSynthesisTest directory.

6. In the SpeechSynthesisTest directory, create a new file named “SpeechSynthesisTest.java” containing the following text.

import com.sun.speech.freetts.*;

public class SpeechSynthesisTest
    public static void main(String[] args)
        Voice voiceKevin16 = new Voice("kevin16");

        String[] thingsToSay = new String[]
            "hi everybody",
            "my name is kevin sixteen",
            "my voice is built into free t t s",
            "but it isn't very mellifluous",
            "it could be worse, though",
            "every time my friend alan tries to talk",
            "about anything more exciting than what time it is",
            "he barfs up a bunch of exceptions",
            "and passes out",


class Voice
    private String name;
    private com.sun.speech.freetts.Voice systemVoice;

    public Voice(String name)
        this.name = name;
        this.systemVoice = VoiceManager.getInstance().getVoice(this.name);

    public void say(String[] thingsToSay)
        for (int i = 0; i < thingsToSay.length; i++)
            this.say( thingsToSay[i] );

    public void say(String thingToSay)

    public void dispose()

7. Still in the SpeechSynthesisTest directory, create a new file named “ProgramBuildAndRun.bat” containing the following text, and substitute the path of the directory containing javac.exe and java.exe in the indicated place.

set javaPath="[path of directory containing javac.exe, java.exe]"
%javaPath%\javac.exe -cp freetts.jar *.java
%javaPath%\java.exe -cp .;freetts.jar SpeechSynthesisTest

8. Double-click the icon of the ProgramBuildAndRun.bat file to run it. A console window will appear, the program will be built and executed, and a short speech will be delivered using FreeTTS’s built-in voice “kevin16”.


  • This example uses the “kevin16” voice that comes with FreeTTS, and presumably is named after Kevin A. Lenzo, one of the major contributors to open source speech synthesis. One can only hope that the real Kevin sounds a little more natural than his namesake, though. Supposedly, there are all manner of voices that you can use with FreeTTS, if you know how, but as of this writing, I don’t. FreeTTS bears all the hallmarks of being a system built by academics, which means that its breathtaking ingenuity blends seamlessly into its gaping, reeking lack of usability.
  • When the program runs, you may notice that it mentions something about how it “will not use MBROLA voices”. MBROLA seems to be, in this context at least, a database of “diphones” (which are transitions between one sound and another) and possibly full voices. If so, they might sound a little better than kevin16. All I can really figure out from the internet is that it can’t legally be used for commercial or, oddly, military purposes. But if you can’t make money with it or break something with it, what good is it?
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

11 Responses to Speech Synthesis in Java Using FreeTTS

  1. Franz says:

    very good self-written example! I’ve used the source code In the BlueJ IDE, the libraries added and it talked to me! It was the first step for my attempts.

  2. Aditi says:

    Thank you so much.I had downloaded free-tts about a month back and was not getting how to use it, this was of so much help.

  3. Sulaiman says:

    how can i change the voice to a female voice.?

  4. Swetha says:

    Thank you for sharing a clear step-by-step guide! Finally, i got one program running in freetts almost at the giving up stage.

  5. Simon says:

    Thanks a lot! Most simple,straight forward example of freetts on the web! Looking forward for an as easy piece of code about speech to text!

  6. Ankur says:

    thanks a lot ..it was really helpful ,it was easy to work with you’er instructions…

  7. Rohith says:

    Just Neat!

  8. Phathe says:

    Your commands are not running

    • Hmm… sorry to hear that. I assume you’re talking about the commands in ProgramBuildAndRun.bat? I guess these instructions make some implicit assumptions that might be better made explicit. Are you trying to run this on a Windows system? Do you have Java installed, and is the directory containing javac.exe and java.exe in your PATH environment variable? If so, I’m not sure what else might be going wrong.

  9. Steve Smith says:

    If it wasn’t for your blog I don’t think I’d have found any sample source code using FreeTTS; they don’t seem to like giving away any practical information on their website. After finally getting it to run I’ve decided I won’t be using it.

  10. kurapati says:

    i had downloaded freetts software into my system. But while executing a program it shows compilation error. so, please help me in this to complete my project.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s