2 * Copyright 2003 Sun Microsystems, Inc.
4 * See the file "license.terms" for information on usage and
5 * redistribution of this file, and for a DISCLAIMER OF ALL
8 import com.sun.speech.freetts.Voice;
9 import com.sun.speech.freetts.VoiceManager;
10 import com.sun.speech.freetts.audio.JavaClipAudioPlayer;
13 * Simple program to demonstrate the use of the FreeTTS speech
14 * synthesizer. This simple program shows how to use FreeTTS
15 * without requiring the Java Speech API (JSAPI).
17 public class FreeTTSHelloWorld {
20 * Example of how to list all the known voices.
22 public static void listAllVoices() {
24 System.out.println("All voices available:");
25 VoiceManager voiceManager = VoiceManager.getInstance();
26 Voice[] voices = voiceManager.getVoices();
27 for (int i = 0; i < voices.length; i++) {
28 System.out.println(" " + voices[i].getName()
29 + " (" + voices[i].getDomain() + " domain)");
33 public static void main(String[] args) {
37 String voiceName = (args.length > 0)
42 System.out.println("Using voice: " + voiceName);
44 /* The VoiceManager manages all the voices for FreeTTS.
46 VoiceManager voiceManager = VoiceManager.getInstance();
47 Voice helloVoice = voiceManager.getVoice(voiceName);
49 if (helloVoice == null) {
51 "Cannot find a voice named "
52 + voiceName + ". Please specify a different voice.");
56 /* Allocates the resources for the voice.
58 helloVoice.allocate();
62 helloVoice.speak("Thank you for giving me a voice. "
63 + "I'm so glad to say hello to this world.");
65 /* Clean up and leave.
67 helloVoice.deallocate();