Posted by
shantanu yadav
on
- Get link
- Other Apps
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!!!!"); } }
Comments
Post a Comment