Step 1:
Download java speech synthesis called FreeTTS.
https://freetts.sourceforge.io/docs/index.php#download_and_install
If you plan on just creating applications with FreeTTS, the bin package will be sufficient
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.

Step 2:
Copy past the extricted file into the following folder
C:\Program Files\Java\jre1.8.0_151\lib\ext
Step 3:
Define the rule for JRE library

Note: Add “javafx/**” in Rule Pattern as shown below

Step 4: Write the following code in eclipse
package automation; // your package name
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.awt.*;
import java.awt.event.*;
import java.util.concurrent.TimeUnit;
import javax.swing.*;
// importing for text to speech
import java.util.Locale;
import javax.speech.Central;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;
public class TTS implements ActionListener {
// Skipping adding the container, Apply layouts, create & add components etc
public void actionPerformed(ActionEvent event) {
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 queue is empty.
synthesizer.speakPlainText(“Completing the add new hire process for an employee so wait”, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
// Deallocate the Synthesizer at the end of program or at termination of program
//synthesizer.deallocate();
}
catch (Exception e)
{
e.printStackTrace();
}
}
// Main method
public static void main(String[] args) {
new TTS();
}
} // End of class