Skip to main content

Creating a text dictator using java






Want to create your own reader for your .txt files using java .If yes then you are on the right track.Here you see how to use Free TTS ,A free  API written entirely using Java TM .

Requirements

In order to create this reader app you need Free TTS 1.2.2 API you could download it from here

What the program do ?


The program given below will prompt you to enter the path of a .txt file in your computer and then it will read the file in a natural human voice for you .

Reader.java



import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;

public class Reader {

    // Some available voices are (kevin, kevin16, alan)
    private static final String VOICE_NAME_KEVIN = "kevi";
    private final Voice voice;
    
    public Reader() {
 
        VoiceManager vm = VoiceManager.getInstance();       
        voice = vm.getVoice(VOICE_NAME_KEVIN);
        voice.allocate();
    }
    
    public void speak(File file) {
        
        if(file != null) {
            
            FileInputStream inputStream = null;
            try {
            
                inputStream = new FileInputStream(file);
                voice.speak(inputStream);
                
            } catch (FileNotFoundException e) {
                voice.speak("Hey!it seems that the file does not exists.");
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
        }
    }

    public static void main(String args[])
    {
       Scanner sc=new Scanner(System.in);
       System.out.print("Enter full path to the file(.txt):-"); 
       String path=sc.nextLine();
       File file = new File(path);
        
        Reader r= new Reader();

        // Passing file object as argument
        r.speak(file);
        
        System.out.println("Reading is over!!!!");
       
       }
}


Output:-


Enter full path to the file(.txt):-D:/welcome.txt
Reading is over!!!!


Please keep tuned if you like this on my upcoming tutorial we will learn how could we create a simple GUI for this java app,which will consists of a JFileChooser ,a pause and resume button and a dropdown to select through the available voices. 

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...

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...