2 * Copyright 1998-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
8 package com.sun.speech.engine.synthesis;
10 import java.beans.PropertyVetoException;
12 import javax.speech.SpeechError;
14 import javax.speech.synthesis.Voice;
15 import javax.speech.synthesis.SynthesizerProperties;
17 import com.sun.speech.engine.BaseEngineProperties;
20 * Supports the JSAPI 1.0 <code>SynthesizerProperties</code>
21 * interface. The properties of a <code>Synthesizer</code> are:
31 public class BaseSynthesizerProperties extends BaseEngineProperties
32 implements SynthesizerProperties {
37 protected Voice defaultVoice;
42 protected float defaultPitch;
45 * The default pitch range.
47 protected float defaultPitchRange;
50 * The default specking rate.
52 protected float defaultSpeakingRate;
57 protected float defaultVolume;
62 protected Voice currentVoice;
67 protected float currentPitch;
70 * The current pitch range.
72 protected float currentPitchRange;
75 * The current speaking rate.
77 protected float currentSpeakingRate;
82 protected float currentVolume;
87 public BaseSynthesizerProperties() {
88 this.defaultVoice = null;
89 this.defaultPitch = 0.0f;
90 this.defaultPitchRange = 0.0f;
91 this.defaultSpeakingRate = 0.0f;
92 this.defaultVolume = 0.0f;
96 * Creates a new <code>BaseSynthesizerProperties</code> with the
97 * given default values.
99 * @param defaultVoice the default voice
100 * @param defaultPitch the default pitch
101 * @param defaultPitchRange the default pitch range
102 * @param defaultSpeakingRate the default speaking rate
103 * @param defaultVolume the default volume
105 public BaseSynthesizerProperties(Voice defaultVoice,
107 float defaultPitchRange,
108 float defaultSpeakingRate,
109 float defaultVolume) {
110 if (defaultVoice != null) {
111 this.defaultVoice = (Voice)(defaultVoice.clone());
113 this.defaultVoice = null;
116 this.defaultPitch = defaultPitch;
117 this.defaultPitchRange = defaultPitchRange;
118 this.defaultSpeakingRate = defaultSpeakingRate;
119 this.defaultVolume = defaultVolume;
121 if (defaultVoice != null) {
122 currentVoice = (Voice)(defaultVoice.clone());
127 currentPitch = defaultPitch;
128 currentPitchRange = defaultPitchRange;
129 currentSpeakingRate = defaultSpeakingRate;
130 currentVolume = defaultVolume;
134 * Resets all properties to their default values.
136 public void reset() {
138 setVoice(defaultVoice);
139 setVolume(defaultVolume);
140 setPitch(defaultPitch);
141 setPitchRange(defaultPitchRange);
142 setSpeakingRate(defaultSpeakingRate);
143 } catch (PropertyVetoException e) {
144 throw new SpeechError("Inconsistent default properties");
149 * Gets the current synthesizer voice.
151 * @return the current synthesizer voice.
155 public Voice getVoice() {
156 return (Voice)(currentVoice.clone());
160 * Sets the current synthesizer voice.
162 * @param voice the new voice
166 * @throws PropertyVetoException if the voice cannot be set to
169 public void setVoice(Voice voice)
170 throws PropertyVetoException {
171 // [[[TODO: Need to check that the voice is legal.]]]
172 Voice oldVoice = currentVoice;
173 currentVoice = (Voice)(voice.clone());
174 postPropertyChangeEvent("Voice", oldVoice, voice);
178 * Gets the baseline pitch for synthesis.
180 * @return the baseline pitch in Hertz
184 public float getPitch() {
189 * Sets the baseline pitch for the current synthesis voice.
191 * @param hertz the new baseline pitch in Hertz
195 * @throws PropertyVetoException if the baseline pitch cannot be
196 * set to the given value
198 public void setPitch(float hertz)
199 throws PropertyVetoException {
200 float oldPitch = currentPitch;
201 currentPitch = hertz;
202 postPropertyChangeEvent("Pitch", oldPitch, hertz);
206 * Gets the pitch range for synthesis.
208 * @return the current pitch range in Hertz
210 * @see #setPitchRange
213 public float getPitchRange() {
214 return currentPitchRange;
218 * Sets the pitch range for the current synthesis voice.
220 * @param hertz the new range in Hertz
222 * @see #getPitchRange
224 * @throws PropertyVetoException if the pitch range cannot be set
227 public void setPitchRange(float hertz)
228 throws PropertyVetoException {
229 float oldRange = currentPitchRange;
230 currentPitchRange = hertz;
231 postPropertyChangeEvent("PitchRange", oldRange, hertz);
235 * Gets the current target speaking rate in words per minute.
237 * @return the current target speaking rate in words per minute.
239 * @see #getSpeakingRate
241 public float getSpeakingRate() {
242 return currentSpeakingRate;
246 * Sets the target speaking rate in words per minute.
248 * @param wpm the new speaking rate in words per minute
250 * @throws PropertyVetoException if the speaking rate cannot be
251 * set to the given value
253 * @see #getSpeakingRate
255 public void setSpeakingRate(float wpm)
256 throws PropertyVetoException {
257 float oldRate = currentSpeakingRate;
258 currentSpeakingRate = wpm;
260 postPropertyChangeEvent("SpeakingRate", oldRate, wpm);
264 * Gets the current volume.
266 * @return the current volume expressed as a <code>float</code>
267 * 0.0 and 1.0, inclusive
271 public float getVolume() {
272 return currentVolume;
278 * @param volume the new volume expressed as a <code>float</code>
279 * 0.0 and 1.0, inclusive
283 * @throws PropertyVetoException if the volume cannot be
284 * set to the given value
286 public void setVolume(float volume)
287 throws PropertyVetoException {
290 else if (volume < 0.0f)
293 float oldVolume = currentVolume;
294 currentVolume = volume;
296 postPropertyChangeEvent("Volume", oldVolume, volume);