Installing and using FreeTTS in Java on Linux
FreeTTS is a quite handy text-to-speech synthesizer that works in Java. It's also a bitch to install and use.
The first thing you'll want to do is download FreeTTS from it's site, http://sourceforge.net/projects/freetts/files/. This will get you a zip that looks like a jar but isn't. Extract the FreeTTS folder out somewhere (I did it to
Now the first thing you need to do is rip out the
jsapi.jar file. For some reason, this is buried in what is probably the most annoying license file known to man, which you have to page through with less, but if you hit enter at the end instead of y (because you weren't reading it, of course) you get kicked out and have to start over. However, Linux has a very handy program called yes that will spam
y for you.
chmod +x <freettsfolder>/lib/jsapi.sh to make it an executable script. Then run
yes | <freettsfolder>/lib/jsapi.sh and page through with enter. When you get to the license agreement yes should spam in a y before you hit enter and the script will extract it's payload.
jsapi is in whatever directory your shell is in. Move it into
<freettsfolder>/lib so it's with it's friends. Since I'm an Eclipse user, I then added this to the build path for a project (right click -> properties -> Java Build Path -> libraries tab -> add external jars) and created a new class.
You'll need to import
com.sun.freetts.*, then set a system property with
to use the Kevin voice. Presumably you can set other voices, which you could probably find by decompiling the cmu_us_kal jar that was in lib, but the Kevin voice is not bad.
Finally, you can speak a sentence with the following:
Voice kevin = VoiceManager.getInstance().getVoice("kevin16"); kevin.allocate(); kevin.speak("You may be wondering why I have gathered you here tonight...");
And you should get glorious machine-generated sound pouring from your speakers. I did not run into the Linux/java sound bug that I found mentioned on StackOverflow while trying to get this to work, but the newest version of FreeTTS is more than a year younger than those issues so I figure it was fixed.
Happy sound saying!