Java Text to Speech Tutorial Using FreeTTS | Eclipse

Hello friends, Welcome to my new tutorial and in this tutorial, we will learn about how we can convert Java Text to Speech using the FreeTTS Jar file.

So Let’s start our tutorial freetts speech to text example and convert Java text to Speech using the Eclipse IDE. To know how to download Eclipse IDE, you can click here.

Also Read –  How to Play Mp3 File in Java 

Converting Java Text to Speech Using Eclipse IDE

What is FreeTTS?

  • FreeTTS is entirely written in Java programming language, which is nothing but an open-source Speech Synthesis system by which we can make our computer speak.
  • In simple words, we can say that it is an artificial production of human speech which converts normal language text into speech. So in this tutorial, We will learn about how to convert text to speech in Java using the Eclipse IDE.

Downloading FreeTTS Jar file

  • In the first step, we need to download the FreeTTS JAR file to include it in our program.
  • You can download the FreeTTS JAR file from the download link given below.
  • After downloading this ZIP file, extract the files and navigate to the lib folder.
  • After going to the lib folder for your convenience, copy all the JAR files and store them in any new folder on your PC.
  • As we have finally downloaded and extracted our JAR files now, the next thing we have to do is create a Java project in Eclipse IDE.

So let’s get started with our tutorial about text to speech in Java.

Creating a Java Project in Eclipse

  • Open Eclipse IDE and click on the Java Project under the new section of File Menu (File>>New>>Java Project).
Java Text to Speech
Java Text to Speech – fig – 1
  • Now give a name to your project (TextToAudio in this example) and click on “Finish”.
Java Text to Speech
Java Text to Speech – fig – 2
  • Now right click on the project and create a new Java class (New>>Class).
Java Text to Speech
Java Text to Speech – fig – 3
  • Now give a name to your class (TextToSpeech in this Example), tick mark on the public static void main(String[] args), and then click on the Finish button as shown in the figure below.
freetts example – fig – 4

Adding FreeTTS JAR Files to Eclipse

  • To convert Java text to speech in Eclipse IDE, you need to include FreeTTS Jar files to the Eclipse.
  • I have given the download link of the zip file in the above.
  • Extract the Zip Archive and navigate to the lib folder.
  • After going to the lib folder for your convenience, copy all the JAR files and store them in any new folder on your PC.
  • Right-click on the project, go to the properties section, select Java Build Path, and click on the Add External JARs button.
fig – 5
  • After clicking on the button, a pop-up window will appear to select and open the Jar files.
fig – 6
  • You can see the added Jar files as shown in the figure below. Now click on the Apply and Close button.
fig – 7

Adding Voice to Text in Java

  • First of all, we need to create an object of the Voice class.
  • Now we have to get the voice of the person using the getVoice() method and it takes a String value in its parameter(in this example I am using  kevin).
  • Next, we have to allocate the voice using the allocate() method.
  • Now to speak the voice, we will call the method speak() using the object of the Voice class and it takes the text value that we want to be spoken in its argument.
  • We can also set the rate, pitch and volume of the voice according to our requirements.
  • The programming example is given below.
  • Now run your program.
  • As soon as you run your program, the written texts with the speak() method will be spoken. You can try it by yourself. It will act fine.
  • You can also download the source code of this project from the link given below.

Java Text to Speech Source Code Download

  • The link of the file is given below

So Friends, this was all from this tutorial. If you have any queries regarding this post then you can comment below and you can also check my previous post about how to create Login Form in Java Swing. Thank You

People are also Reading…..

5 thoughts on “Java Text to Speech Tutorial Using FreeTTS | Eclipse”

Leave a Comment