Skip to main content

Java Program which speaks


Today you will see a java program which could convert text to speech .The program will ask you to enter  string and then it will spell the string in a natural human voice.

NOTE:- For this app i am using a third party library named FreeTTS 1.2.2 you could download it from here .Here i am assuming that you know how to use the jars of third party libraries if not then you could have a look on here.
If you are using Blue J IDE then see it here.
If you are using Ellipse then look here.

So below is the complete code of our Application


Spell.java



 
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;
import java.util.Scanner;

public class Spell {
private static final String VOICE_NAME_KEVIN = "kevin16";
    private final Voice voice;
    
    public Spell() {

        VoiceManager vm = VoiceManager.getInstance();       
        voice = vm.getVoice(VOICE_NAME_KEVIN);
        voice.allocate();
    }

    public void speak(String inputText) {

        if(inputText != null) {
            
            voice.speak(inputText);
        }
else          {
                inputText="Atleast enter something to speak";     
                voice.speak(inputText);
         }
}

    public static void main(String[] args) {

        // Defining Scanner Object to read data from console
        Scanner inputScanner = new Scanner(System.in);
        
        Spell tsc = new Spell();

        System.out.println("Enter the Text : (type 'exit' to terminate)");

        // Reading the text
        String inputText = inputScanner.nextLine();

        while (true) {

            if("exit".equalsIgnoreCase(inputText)) {
                
                inputText = "Good Bye, we will talk later";
                tsc.speak(inputText);
                break;
            }
            
            tsc.speak(inputText);
            
            System.out.println("Enter the Text : (type 'exit' to terminate)");
            inputText = inputScanner.nextLine();
        }

        inputScanner.close();
        
    }
}



Comments

Popular posts from this blog

How to setup a .jar file in Blue-J

How to set a new package in Blue-J In this tutorial you will learn how you can setup a jar file in Blue J IDE. Follow the given steps and you could easily set it up. Let me specify that in my case we will install a jar file created my me that is utility.jar .If you are downloading other packages like Free TTS,open cv, j3d or any other then you just need to find the jar files in their folder and rest of the tutorial remain the same. Step 1:- Open blue-J Ide Open your blue j ide in my case it is Blue-J 3.1.7. Step 2:- In the top menu bar click on TOOLS and after that in the drop down menu click on PREFERENCES . Step 3 :- After clicking on preferences you will see a screen like this.      Just click on Libraries Tab.   Step 4 :- After clicking on libraries blue j will show the list of pre loaded jar files that you must be using before.On the right hand side of the window you will see ADD button just click on it. Step 5:- ...

How to setup a .jar file in Eclipse IDE

How to set a new package in Eclipse IDE In this tutorial you will learn how you can setup a jar file in Eclipse IDE. Follow the given steps and you could easily set it up. Let me specify that in my case we will install a jar file created my me that is utility.jar .If you are downloading other packages like Free TTS,open cv, j3d or any other then you just need to find the jar files in their folder and rest of the tutorial remain the same. Step 1:- Open Eclipse Ide Open your Eclipse ide in my case it is  Version: Luna Service Release 2 (4.4.2) Step 2:- In the top menu bar click on  WINDOW  menu item. And then you will see a pop up menu will appear.In the pop up menu click on  PREFERENCES  . Step 3:- Then in the next window's left hand side click on JAVA and then on  BUILD PATH   .Under build path you will see two options   classpath variables   and  User Libraries   you need to click on user...

Java 3D:- Creating a 3d ball using java

Quoted from Wikipedia  Java 3D is a scene graph based 3D application programming interface (API) for the Java platform . It ran atop either OpenGL or Direct3D until the version 1.6.0 which runs at the top of JOGL . Since version 1.2, Java 3D has been developed under the Java Community Process . A Java 3D scene graph is a directed acyclic graph (DAG). Compared to other solutions, Java 3D is not only a wrapper around these graphics APIs, but an interface that encapsulates the graphics programming using a true object-oriented approach. Here a scene is constructed using a scene graph that is a representation of the objects that have to be shown. This scene graph is structured as a tree containing several elements that are necessary to display the objects. Additionally, Java 3D offers extensive spatialized sound support. Java 3D and its documentation are available for download separately. They are not part of the Java Development Kit (JDK). Download Java 3d ...