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

Create a simple virus using java

What's my idea Before we start talking how we will create a simple flooder virus using java we must be clear about what is  the idea and how to implement it. So the idea is to create a program which will create  thousands of blank files in a drive you will don't believe but it could create file with  a speed of   1060+ files per second . How to implement it Now the problem is how we would do this?? So here is the answer .  First of all we will design a loop which will run  N  number of times where  N  is the number of files which we want to create. Then we will create a new File with the help of  createNewFile()  function of  java.io.File  class. The name of each file is the value of the variable which is used in the loop. Here is the sample virus program. /**  * **********This virus program is just for educational purpose   * author will not be responsible for any issues **************  *   * @author (Shashank

Simple tricks to enhance your java cui program

Today I will tell you how can you enhance your simple java CUI programs and applications with these small tricks and methods How to clear the output screen through code If you had ever make a vast java program then you might have been met with the problem on how to clear the output screen when a specific function is called or it is also needed in large menu driven programs .If you want the answer then you are on the Wright track. In C++ it is easy to clear the screen by just invoking the function clrscr().However java does not provide any predefined function In order to do so yet this one line code can help you to clear the output screen . S ystem.out.print(“\f”); I know you could not believe it but its true this one line can clear the output screen. For your satisfaction see this video practical below. c My dprint and dpritln functions To enhance your cui java program you could use these two user defined functions in your java program these functions can b

Hijack Clipboard using java

What is Clipboard? The clipboard is a special location in your computer's memory that temporarily stores data that has been cut or copied from a document. This data can then be pasted to a new location. The clipboard will typically hold its information until you cut or copy something else, or log out of the computer. For example, a user may copy information from a word processor and paste that information into an e-mail message. What is Clipboard Hijack? A clipboard hijacking is an exploit in which the attacker gains control of the victim'sclipboard and replaces its contents with their own data, such as a link to a malicious Web site.For more details see  here . Hacking clipboard using java. Our java code will repeatedly change clipboard text with the hackers text, may be a irritating line ,or a URL to your site. We will use the Toolkit class to get the system clipboard and then we will use the Clipboard class to change the content of clipboard.