upstream version 1.2.2
[debian/freetts] / com / sun / speech / engine / synthesis / BaseVoice.java
1 /**
2  * Copyright 1998-2001 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 package com.sun.speech.engine.synthesis;
9
10 import javax.speech.synthesis.Voice;
11
12 /**
13  * Extends the JSAPI 1.0 <code>Voice</code> class to encapsulate
14  * engine-specific data.
15  */
16 public class BaseVoice extends Voice {
17     /**
18      * The id of the voice
19      */
20     protected String voiceId;
21
22     /**
23      * The default pitch
24      */
25     protected float defaultPitch;
26
27     /**
28      * The default pitch range
29      */
30     protected float defaultPitchRange;
31
32     /**
33      * The default speaking rate
34      */
35     protected float defaultSpeakingRate;
36
37     /**
38      * The default volume
39      */
40     protected float defaultVolume;
41
42     /**
43      * Class constructor.  The age and gender parameters are defined in
44      * <code>Voice</code>.
45      *
46      * @param id the id
47      * @param name the name
48      * @param gender the gender
49      * @param age the age
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,
55      *   inclusive
56      */ 
57     public BaseVoice(String id,
58                      String name,
59                      int gender,
60                      int age,
61                      String style,
62                      float pitch,
63                      float pitchRange,
64                      float speakingRate,
65                      float volume) {
66         super(name, gender, age, style);   
67         this.voiceId = id;
68         defaultPitch = pitch;
69         defaultPitchRange = pitchRange;
70         defaultSpeakingRate = speakingRate;
71         defaultVolume = volume;
72     }
73
74     /**
75      * Gets the id for this voice.  Should be unique for a
76      * synthesizer.
77      *
78      * @return the id for this voice
79      *
80      * @see #setId
81      */
82     public String getId() {
83         return voiceId;
84     }
85
86     /**
87      * Sets the id for this voice.
88      *
89      * @param id the new id
90      *
91      * @see #getId
92      */
93     public void setId(String id) {
94         voiceId = id;
95     }
96
97     /**
98      * Gets the pitch for this voice
99      * @return the pitch
100      */
101     public float getPitch() {
102         return defaultPitch;
103     }
104
105     /**
106      * Gets the pitch range for this voice
107      * @return the pitch range
108      */
109     public float getPitchRange() {
110         return defaultPitchRange;
111     }
112
113     /**
114      * Gets the speaking rate for this voice
115      * @return the speaking rate
116      */
117     public float getSpeakingRate() {
118         return defaultSpeakingRate;
119     }
120
121     /**
122      * Gets the volume for this voice
123      * @return the volume
124      */
125     public float getVolume() {
126         return defaultVolume;
127     }
128
129     /**
130      * Creates a copy of this voice.
131      *
132      * @return a clone of this voice
133      */
134     public Object clone() {
135         return super.clone();
136     }
137
138     /**
139      * Converts a Voice to a printable string.
140      *
141      */
142     public String toString() {
143         StringBuffer buf = new StringBuffer();
144
145         if (getName() != null) {
146             buf.append(getName());
147         }
148         buf.append(":");
149
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");
161         }
162         buf.append(":");
163
164         // Note: doesn't handle compound choices.
165         // e.g. AGE_CHILD | AGE_TEENAGER
166         int age = getAge();
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");
179         }
180         buf.append(":");
181
182         if (getStyle() != null) {
183             buf.append(getStyle());
184         }
185
186         return buf.toString();
187     }
188 }