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 javax.speech.synthesis.Voice;
13 * Extends the JSAPI 1.0 <code>Voice</code> class to encapsulate
14 * engine-specific data.
16 public class BaseVoice extends Voice {
20 protected String voiceId;
25 protected float defaultPitch;
28 * The default pitch range
30 protected float defaultPitchRange;
33 * The default speaking rate
35 protected float defaultSpeakingRate;
40 protected float defaultVolume;
43 * Class constructor. The age and gender parameters are defined in
47 * @param name the name
48 * @param gender the gender
50 * @param style the style
51 * @param pitch the baseline pitch in Hertz
52 * @param pitchRange the pitch range in Hertz
53 * @param speakingRate the speaking rate in words per minute
54 * @param volume the volume expressed between 0.0 and 1.0,
57 public BaseVoice(String id,
66 super(name, gender, age, style);
69 defaultPitchRange = pitchRange;
70 defaultSpeakingRate = speakingRate;
71 defaultVolume = volume;
75 * Gets the id for this voice. Should be unique for a
78 * @return the id for this voice
82 public String getId() {
87 * Sets the id for this voice.
89 * @param id the new id
93 public void setId(String id) {
98 * Gets the pitch for this voice
101 public float getPitch() {
106 * Gets the pitch range for this voice
107 * @return the pitch range
109 public float getPitchRange() {
110 return defaultPitchRange;
114 * Gets the speaking rate for this voice
115 * @return the speaking rate
117 public float getSpeakingRate() {
118 return defaultSpeakingRate;
122 * Gets the volume for this voice
125 public float getVolume() {
126 return defaultVolume;
130 * Creates a copy of this voice.
132 * @return a clone of this voice
134 public Object clone() {
135 return super.clone();
139 * Converts a Voice to a printable string.
142 public String toString() {
143 StringBuffer buf = new StringBuffer();
145 if (getName() != null) {
146 buf.append(getName());
150 // Note: doesn't handle compound choices.
151 // e.g. GENDER_MALE | GENDER_FEMALE
152 int gender = getGender();
153 if (gender == Voice.GENDER_DONT_CARE) {
154 buf.append("GENDER_DONT_CARE");
155 } else if ((gender & Voice.GENDER_MALE) != 0) {
156 buf.append("GENDER_MALE");
157 } else if ((gender & Voice.GENDER_FEMALE) != 0) {
158 buf.append("GENDER_FEMALE");
159 } else if ((gender & Voice.GENDER_NEUTRAL) != 0) {
160 buf.append("GENDER_NEUTRAL");
164 // Note: doesn't handle compound choices.
165 // e.g. AGE_CHILD | AGE_TEENAGER
167 if (age == Voice.AGE_DONT_CARE) {
168 buf.append("AGE_DONT_CARE");
169 } else if ((age & Voice.AGE_CHILD) != 0) {
170 buf.append("AGE_CHILD");
171 } else if ((age & Voice.AGE_TEENAGER) != 0) {
172 buf.append("AGE_TEENAGER");
173 } else if ((age & Voice.AGE_YOUNGER_ADULT) != 0) {
174 buf.append("AGE_YOUNGER_ADULT");
175 } else if ((age & Voice.AGE_MIDDLE_ADULT) != 0) {
176 buf.append("AGE_MIDDLE_ADULT");
177 } else if ((age & Voice.AGE_OLDER_ADULT) != 0) {
178 buf.append("AGE_OLDER_ADULT");
182 if (getStyle() != null) {
183 buf.append(getStyle());
186 return buf.toString();