Converting Text to Speech in Java

Java Speech API : The Java Speech API allows Java applications to incorporate speech technology into their user interfaces. It defines a cross-platform API to support command and control recognizers, dictation systems and speech synthesizers.
Java Speech supports speech synthesis which means the process of generating spoken language by machine on the basis of written input.
It is important to keep in mind that Java Speech is only a specification -no implementation is included. Thus third-parties provide the implementations.The javax.speech package defines the common functionality of recognizers, synthesizers, and other speech engines. The package javax.speech.synthesis extends this basic functionality for synthesizers.

We will understand that what is required for java API to convert text to speech

1) Engine : The Engine interface is available inside the speech package.”Speech engine” is the generic term for a system designed to deal with either speech input or speech output.

import javax.speech.Engine;

2) Central : Central provides the ability to locate, select and create speech recognizers and speech synthesizers.

import javax.speech.Central;

3) SynthesizerModeDesc : SynthesizerModeDesc extends the EngineModeDesc with the properties that are specific to speech synthesizers.

import javax.speech.synthesis.SynthesizerModeDesc;

3) Synthesizer : The Synthesizer interface provides primary access to speech synthesis capabilities.SynthesizerModeDesc adds two properties: List of voices provided by the synthesizer Voice to be loaded when the synthesizer is started.

import javax.speech.synthesis.Synthesizer;

We are going to use an open source implementation of java speech synthesis called FreeTTS
Download the zip folder go to lib install jsapi.exe. It will create a jar file namely jsapi.jar . Include all jar libraries to your project.





// Java code to convert 
// text to speech
import java.util.Locale;
import javax.speech.Central;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;
public class TextSpeech 
    public static void main(String[] args) 
            // set property as Kevin Dictionary
            // Register Engine
            // Create a Synthesizer
            Synthesizer synthesizer =                                         
                Central.createSynthesizer(new SynthesizerModeDesc(Locale.US));     
            // Allocate synthesizer
            // Resume Synthesizer
            // speaks the given text until queue is empty.
            synthesizer.speakPlainText("GeeksforGeeks", null);         
            // Deallocate the Synthesizer.
        catch (Exception e) 


Related article : Convert Text to Speech in Python



This article is contributed by Akash Sharan. If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

My Personal Notes arrow_drop_up

Article Tags :
Practice Tags :


Please write to us at to report any issue with the above content.