Converting Text to Speech in Java Last Updated : 12 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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 the language by machine on the basis of written input. It is important to keep in mind that Java Speech is only a specification i.e. 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 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;Central: Central provides the ability to locate, select and create speech recognizers and speech synthesizers. import javax.speech.Central;SynthesizerModeDesc: SynthesizerModeDesc extends the EngineModeDesc with the properties that are specific to speech synthesizers. import javax.speech.synthesis.SynthesizerModeDesc;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; Below is an open-source implementation of Java Speech Synthesis called FreeTTS in the form of steps: Download the FreeTTS in the form of zip folder from hereExtract the zip file and go to freetts-1.2.2-bin/freetts-1.2/lib/jsapi.exeOpen the jsapi.exe file and install it.This will create a jar file by the name jsapi.jar. This is the JAR library that contains the FreeTTS library to be included in the project.Create a new Java project in your IDE.Include this jsapi.jar file into your project.Now copy the below code into your projectExecute the project to get the below expected output. Below is the code for the above project: Java // 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) { try { // Set property as Kevin Dictionary System.setProperty( "freetts.voices", "com.sun.speech.freetts.en.us" + ".cmu_us_kal.KevinVoiceDirectory"); // Register Engine Central.registerEngineCentral( "com.sun.speech.freetts" + ".jsapi.FreeTTSEngineCentral"); // Create a Synthesizer Synthesizer synthesizer = Central.createSynthesizer( new SynthesizerModeDesc(Locale.US)); // Allocate synthesizer synthesizer.allocate(); // Resume Synthesizer synthesizer.resume(); // Speaks the given text // until the queue is empty. synthesizer.speakPlainText( "GeeksforGeeks", null); synthesizer.waitEngineState( Synthesizer.QUEUE_EMPTY); // Deallocate the Synthesizer. synthesizer.deallocate(); } catch (Exception e) { e.printStackTrace(); } } } Output: [embed]https://www.youtube.com/watch?v=okLA1tNbNiU&feature=youtu.be[/embed] References:https://docs.oracle.com/cd/E17802_01/products/products/java-media/speech/forDevelopers/jsapi-doc/javax/speech/package-summary.htmlhttp://www.oracle.com/technetwork/java/jsapifaq-135248.htmlRelated article: Convert Text to Speech in Python Comment More infoAdvertise with us Next Article Converting Text to Speech in Java A Akash Sharan Improve Article Tags : Misc Java Technical Scripter Practice Tags : JavaMisc Similar Reads How to Convert Text to Speech in Android? Text to Speech App converts the text written on the screen to speech like you have written "Hello World" on the screen and when you press the button it will speak "Hello World". Text-to-speech is commonly used as an accessibility feature to help people who have trouble reading on-screen text, but it 3 min read How to Convert Speech to Text in Android? In this article, speech to text feature is implemented in an application in Android. Speech to text means that anything that the user says is converted into text. This feature has come out to be a very common and useful feature for the users. In various places where search feature is implemented lik 5 min read Program to convert IntStream to String in Java Given a Instream containing ASCII values, the task is to convert this Instream into a String containing the characters corresponding to the ASCII values. Examples: Input: IntStream = 71, 101, 101, 107, 115 Output: Geeks Input: IntStream = 71, 101, 101, 107, 115, 70, 111, 114, 71, 101, 101, 107, 115 1 min read Convert Text to Speech in Python using win32com.client There are several APIs available to convert text to speech in python. One of such APIs available in the python library commonly known as win32com library. It provides a bunch of methods to get excited about and one of them is the Dispatch method of the library. Dispatch method when passed with the a 2 min read Array to Stream in Java Prerequisite : Stream In Java Using Arrays.stream() : Syntax : public static <T> Stream<T> getStream(T[] arr) { return Arrays.stream(arr); } where, T represents generic type. Example 1 : Arrays.stream() to convert string array to stream. Java // Java code for converting string array // t 3 min read Convert a String to a List of Characters in Java In Java, to convert a string into a list of characters, we can use several methods depending on the requirements. In this article, we will learn how to convert a string to a list of characters in Java.Example:In this example, we will use the toCharArray() method to convert a String into a character 3 min read Offline Speech to Text Without any Popup Dialog in Android In this article, we are going to implement an offline speech-to-text functionality in our project. It can work both Online and Offline. When there is no internet connectivity, it will use the pre-stored language model from our mobile device, so it didn't recognize much clearly but gave good results. 6 min read Turing Machine Construction (Transducers Turing Machine) in Java Prerequisite - Turing Machine Turing Machines can broadly be classified into two types, the Acceptors and the Transducers. Acceptor Turing Machine is an automaton used to define Turing-acceptable languages. Such a machine can be used to check whether a given string belongs to a language or not. It i 10 min read Java Fundamentals Coding Practice Problems Understanding Java fundamentals is the first step to becoming a proficient Java programmer. This collection of Java basic coding practice problems covers essential topics such as input/output operations, arithmetic and logical operators, type conversion, conditional statements, loops, and more. Thes 1 min read Java Strings Coding Practice Problems Strings are a fundamental part of Java programming, used for handling and manipulating textual data efficiently. This collection of Java string practice problems covers key operations such as finding string length, slicing, case conversion, palindrome checking, anagram detection, and pattern matchin 2 min read Like