Posted by
shantanu yadav
on
- Get link
- Other Apps
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
Post a Comment