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
9 import com.sun.speech.freetts.ValidationException;
10 import com.sun.speech.freetts.Validator;
11 import com.sun.speech.freetts.Voice;
12 import com.sun.speech.freetts.VoiceManager;
13 import com.sun.speech.freetts.audio.JavaClipAudioPlayer;
14 import com.sun.speech.freetts.audio.JavaStreamingAudioPlayer;
16 import java.net.Socket;
19 * Provides text-to-speech server for Emacspeak.
21 public class FreeTTSEmacspeakServer extends TTSServer {
23 private Voice emacsVoice;
26 * Constructs a EmacspeakServer.
28 public FreeTTSEmacspeakServer(String voiceName) {
30 ("com.sun.speech.freetts.audio.AudioPlayer.cancelDelay", "0");
31 createVoice(voiceName);
36 * Creates and loads the Voice.
38 private void createVoice(String voiceName) {
39 VoiceManager voiceManager = VoiceManager.getInstance();
40 emacsVoice = voiceManager.getVoice(voiceName);
41 if (emacsVoice == null) {
42 System.err.println("No such voice with the name: " + voiceName);
45 emacsVoice.allocate();
50 * Spawns a ProtocolHandler depending on the current protocol.
51 * This method is inherited from TTSServer.
53 * @param socket the socket that the spawned protocol handler will use
55 protected void spawnProtocolHandler(Socket socket) {
57 FreeTTSEmacspeakHandler handler =
58 new FreeTTSEmacspeakHandler(socket, emacsVoice);
59 (new Thread(handler)).start();
60 } catch (Exception e) {
67 * Sets the speaking rate of the voice.
69 * @param wpm the speaking rate (words per minute)
71 public void setRate(float wpm) {
72 emacsVoice.setRate(wpm);
77 * Starts this TTS Server.
79 * Usage: FreeTTSEmacspeakServer [voicename [speaking rate]]
81 public static void main(String[] args) {
82 String voiceName = (args.length > 0)
87 System.out.println("Using voice: " + voiceName);
90 FreeTTSEmacspeakServer server = new FreeTTSEmacspeakServer(voiceName);
92 if (args.length > 1) {
93 float wpm = Float.parseFloat(args[1]);
97 (new Thread(server)).start();