Java speech synthesis

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.

text2speech

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

Requirements

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();

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.”);

System.exit(1);

}

helloVoice.allocate();

helloVoice.speak(“SRM University”);

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

helloVoice.deallocate();

System.exit(0);

}

}

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 Comments

  1. Ahmed Refaey wrote
    at 11:41 PM - 1st July 2012 Permalink

    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,

  2. shakthydoss wrote
    at 3:41 PM - 3rd July 2012 Permalink

    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.

  3. Montaro wrote
    at 4:49 PM - 3rd July 2012 Permalink

    I managed to get it working on Ubuntu, simple used SunJDK instead of default OpenJDK
    http://stackoverflow.com/a/11315459/348162

Post a Comment

Your email is never published nor shared. Required fields are marked *