|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
FreeTTSHelloWorld.java | 0% | 0% | 0% | 0% |
|
1 |
/**
|
|
2 |
* Copyright 2003 Sun Microsystems, Inc.
|
|
3 |
*
|
|
4 |
* See the file "license.terms" for information on usage and
|
|
5 |
* redistribution of this file, and for a DISCLAIMER OF ALL
|
|
6 |
* WARRANTIES.
|
|
7 |
*/
|
|
8 |
import com.sun.speech.freetts.Voice;
|
|
9 |
import com.sun.speech.freetts.VoiceManager;
|
|
10 |
import com.sun.speech.freetts.audio.JavaClipAudioPlayer;
|
|
11 |
|
|
12 |
/**
|
|
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).
|
|
16 |
*/
|
|
17 |
public class FreeTTSHelloWorld { |
|
18 |
|
|
19 |
/**
|
|
20 |
* Example of how to list all the known voices.
|
|
21 |
*/
|
|
22 | 0 |
public static void listAllVoices() { |
23 | 0 |
System.out.println(); |
24 | 0 |
System.out.println("All voices available:");
|
25 | 0 |
VoiceManager voiceManager = VoiceManager.getInstance(); |
26 | 0 |
Voice[] voices = voiceManager.getVoices(); |
27 | 0 |
for (int i = 0; i < voices.length; i++) { |
28 | 0 |
System.out.println(" " + voices[i].getName()
|
29 |
+ " (" + voices[i].getDomain() + " domain)"); |
|
30 |
} |
|
31 |
} |
|
32 |
|
|
33 | 0 |
public static void main(String[] args) { |
34 |
|
|
35 | 0 |
listAllVoices(); |
36 |
|
|
37 | 0 |
String voiceName = (args.length > 0) |
38 |
? args[0] |
|
39 |
: "kevin16";
|
|
40 |
|
|
41 | 0 |
System.out.println(); |
42 | 0 |
System.out.println("Using voice: " + voiceName);
|
43 |
|
|
44 |
/* The VoiceManager manages all the voices for FreeTTS.
|
|
45 |
*/
|
|
46 | 0 |
VoiceManager voiceManager = VoiceManager.getInstance(); |
47 | 0 |
Voice helloVoice = voiceManager.getVoice(voiceName); |
48 |
|
|
49 | 0 |
if (helloVoice == null) { |
50 | 0 |
System.err.println( |
51 |
"Cannot find a voice named "
|
|
52 |
+ voiceName + ". Please specify a different voice.");
|
|
53 | 0 |
System.exit(1); |
54 |
} |
|
55 |
|
|
56 |
/* Sets the AudioPlayer to the JavaClipAudioPlayer.
|
|
57 |
* For more information on the various AudioPlayer
|
|
58 |
* implementations available (e.g., saving to a file),
|
|
59 |
* see the javadoc for AudioPlayer. For an example
|
|
60 |
* of streaming audio to a socket, see the
|
|
61 |
* SocketAudioPlayer.java in demo/freetts/ClientServer.
|
|
62 |
*/
|
|
63 | 0 |
helloVoice.setAudioPlayer(new JavaClipAudioPlayer());
|
64 |
|
|
65 |
/* Allocates the resources for the voice.
|
|
66 |
*/
|
|
67 | 0 |
helloVoice.allocate(); |
68 |
|
|
69 |
/* Synthesize speech.
|
|
70 |
*/
|
|
71 | 0 |
helloVoice.speak(//"Thank you for giving me a voice. " ""
|
72 |
"boo " + "hello testing"); |
|
73 |
|
|
74 |
/* Clean up and leave.
|
|
75 |
*/
|
|
76 | 0 |
helloVoice.deallocate(); |
77 | 0 |
System.exit(0); |
78 |
} |
|
79 |
} |
|
80 |
|
|