2 * Copyright 2001 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 java.net.Socket;
11 import javax.speech.synthesis.Synthesizer;
12 import com.sun.speech.freetts.util.Utilities;
16 * Implements a very simplified version of the Emacspeak speech server.
18 public class JSAPIEmacspeakHandler extends EmacspeakProtocolHandler {
20 // synthesizer related variables
21 private Synthesizer synthesizer;
25 * Constructs a JSAPIEmacspeakHandler.
27 * @param socket the Socket that holds the TCP connection
28 * @param synthesizer the JSAPI synthesizer to use
30 public JSAPIEmacspeakHandler(Socket socket, Synthesizer synthesizer) {
32 this.synthesizer = synthesizer;
33 setDebug(Utilities.getBoolean("debug"));
38 * Speaks the given input text.
40 * @param input the input text to speak.
42 public void speak(String input) {
44 String[] parts = input.split(PARENS_STAR_REGEX);
45 for (int i = 0; i < parts.length; i++) {
46 debugPrintln(parts[i]);
47 synthesizer.speakPlainText(parts[i], null);
53 * Removes all the queued text.
55 public void cancelAll() {
56 synthesizer.cancelAll();
61 * Sets the speaking rate.
63 * @param wpm the new speaking rate (words per minute)
65 public void setRate(float wpm) {
67 synthesizer.getSynthesizerProperties().setSpeakingRate(wpm);
68 } catch (java.beans.PropertyVetoException e) {
69 // ignore and do nothing