JavaVoice is a library that can be used to add Text-To-Speech support and Voice Recognition in Java. Only English language is available at the moment. It has been built with the Spring Framework and integrates two main components:
See the project sample to see how to declare Spring Beans.
Example to capture voice:
- final RecognitionService service = VoiceServiceLocator.getDefaultInstance().getRecognitionService();
- final Recognizer recognizer = service.getRecognizer("SIMPLE-RECOGNIZER");
- System.out.println("\nStart speaking some words (start | stop | pause | go | next | previous | new). Press Ctrl-C to quit.\n");
- while (true)
- final String text = recognizer.recognize();
- System.out.println("You said: " + (StringUtils.isBlank(text) ? "nothing !" : text));
Example of the speech API:
- final String voiceName = "alicia";
- final Speaker v = VoiceServiceLocator.getDefaultInstance().getSpeakService().getSpeaker(voiceName);
- if (v == null)
- System.err.println("No voice found for name: " + voiceName);
- System.out.println("USING VOICE: " + voiceName);
- v.speak("Hello you !");
NB: The VoiceServiceLocator is a Singleton used to retrieve Spring beans.
This is an example of a small program using this library. We can use this program when playing Twister at only two persons.
You only have to download the program, unzip it, and execute the good script in the bin folder. It will popup a swing dialog box so that you can choose a voice, then you just have to listen and speak to interact with the program.