Java speech synthesis

Dear Reader,

All the post in have been moved to is no longer functioning. To get the latest updates and follow up your comments please come to and get subscribed.

Thank you


Are you ready to hear your computer voice ,yeah today I am goanna to discuss about Speech technology, Speech technology is becoming increasingly important in both personal and enterprise computing as it is used to improve existing user interfaces and to support new means of human interaction with computers. In brief let me address what I know about speech technology.

There are two core speech engine namely speech recognition and speech synthesis.

Speech recognition -> it processes audio (speech) input and convert into text form. General Nation speech-to-text.

Speech synthesis -> it processes text as an input and convert into audio(speech) form. General Nation text-to-speech

There are many vendor who provider these speech engines and one such provider is FreeTTS.

FreeTTS is a speech synthesis engine written entirely in the JavaTM programming language and developed at Carnegie Mellon University.

The freetts.jar contains a main entry point that allows a user to interactively control the FreeTTS synthesizer. When invoked with no arguments, freetts will read text and convert the text to speech. freetts can also be used to convert text from a file to speech. It includes options that allow you to redirect the audio to file, as well as a number of metrics and debugging options.


Now let us see a simple sample program that use speech synthesizer


To use the Java Speech API, a user must have certain minimum software and hardware available.

Speech software: we require jsapi (in our case we are going to use freetts )

Audio Hardware: Microphone, speakers


import com.sun.speech.freetts.Voice;

import com.sun.speech.freetts.VoiceManager;

public class FreeTTSHelloWorld


public FreeTTSHelloWorld()



public static void listAllVoices()


System.out.println(“All voices available:”);

VoiceManager voiceManager = VoiceManager.getInstance();

Voice voices[] = voiceManager.getVoices();

for(int i = 0; i < voices.length; i++)

System.out.println(” ” + voices[i].getName() + ” (” + voices[i].getDomain() + ” domain)”);


public static void main(String args[])


// listAllVoices();

String voiceName = args.length <= 0 ? “kevin16” : args[0];


System.out.println(“Using voice: ” + voiceName);

VoiceManager voiceManager = VoiceManager.getInstance();

Voice helloVoice = voiceManager.getVoice(voiceName);

if(helloVoice == null)


System.err.println(“Cannot find a voice named ” + voiceName + “. Please specify a different voice.”);




helloVoice.speak(“SRM University”);

helloVoice.speak(“Department Of Information Technology”);





Note: Before you run this code please don’t forget the add the freetts.jar to your class path.If you use netbeans or eclipse add freetts.jar to lib with the options provided.


3 Responses to “Java speech synthesis”

  1. Ahmed Refaey Says:

    Thanks for the efforts, I tried this code on Ubuntu 12.04 but unfortunately it just prints:
    “Using voice: kevin16”
    and get frozen!, do you have any clues what actually happens?
    Thanks in advance,

    • shakthydoss Says:

      Hi Ahmed Refaey ….

      I too notice long back. It fails to work on Linux.
      Possibly it is not able to find the audio files on Linux platform.

      • Montaro Says:

        I managed to get it working on Ubuntu, simple used SunJDK instead of default OpenJDK

Leave a Reply

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

You are commenting using your 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

%d bloggers like this: