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
8 package com.sun.speech.freetts.jsapi;
10 import com.sun.speech.engine.synthesis.BaseVoice;
11 import com.sun.speech.freetts.Validator;
12 import com.sun.speech.freetts.ValidationException;
15 * Extends the BaseVoice class to encapsulate FreeTTSSynthesizer specific data.
17 public class FreeTTSVoice extends BaseVoice {
19 private com.sun.speech.freetts.Voice freettsVoice;
20 private Validator validator;
23 * Constructs a FreeTTSVoice
25 * @param freettsVoice the freetts voice
26 * @param validatorName the classname of the validator to use
28 public FreeTTSVoice(com.sun.speech.freetts.Voice freettsVoice,
29 String validatorName) {
30 super(freettsVoice.getName()+Math.random(), freettsVoice.getName(),
31 genderToInt(freettsVoice.getGender()),
32 ageToInt(freettsVoice.getAge()), freettsVoice.getStyle(),
33 freettsVoice.getPitch(), freettsVoice.getPitchRange(),
34 freettsVoice.getRate(), freettsVoice.getVolume());
35 this.freettsVoice = freettsVoice;
37 if (validatorName != null) {
39 Class clazz = Class.forName(validatorName);
40 validator = (Validator) clazz.newInstance();
41 } catch (ClassNotFoundException cnfe) {
42 cnfe.printStackTrace();
43 } catch (IllegalAccessException iae) {
44 iae.printStackTrace();
45 } catch (InstantiationException ie) {
54 * Convert a freetts gender to jsapi gender
56 * @param gender the freetts gender
58 * @return the jsapi gender
60 private static int genderToInt(com.sun.speech.freetts.Gender gender) {
61 if (gender == com.sun.speech.freetts.Gender.MALE) {
62 return javax.speech.synthesis.Voice.GENDER_MALE;
63 } else if (gender == com.sun.speech.freetts.Gender.FEMALE) {
64 return javax.speech.synthesis.Voice.GENDER_FEMALE;
65 } else if (gender == com.sun.speech.freetts.Gender.NEUTRAL) {
66 return javax.speech.synthesis.Voice.GENDER_NEUTRAL;
67 } else if (gender == com.sun.speech.freetts.Gender.DONT_CARE) {
68 return javax.speech.synthesis.Voice.GENDER_DONT_CARE;
70 throw new Error("jaspi does not have an equivalent to gender "
76 * Convert a freetts age to jsapi age
78 * @param age the freetts age
80 * @return the jsapi age
82 private static int ageToInt(com.sun.speech.freetts.Age age) {
83 if (age == com.sun.speech.freetts.Age.CHILD) {
84 return javax.speech.synthesis.Voice.AGE_CHILD;
85 } else if (age == com.sun.speech.freetts.Age.TEENAGER) {
86 return javax.speech.synthesis.Voice.AGE_TEENAGER;
87 } else if (age == com.sun.speech.freetts.Age.YOUNGER_ADULT) {
88 return javax.speech.synthesis.Voice.AGE_YOUNGER_ADULT;
89 } else if (age == com.sun.speech.freetts.Age.MIDDLE_ADULT) {
90 return javax.speech.synthesis.Voice.AGE_MIDDLE_ADULT;
91 } else if (age == com.sun.speech.freetts.Age.OLDER_ADULT) {
92 return javax.speech.synthesis.Voice.AGE_OLDER_ADULT;
93 } else if (age == com.sun.speech.freetts.Age.NEUTRAL) {
94 return javax.speech.synthesis.Voice.AGE_NEUTRAL;
95 } else if (age == com.sun.speech.freetts.Age.DONT_CARE) {
96 return javax.speech.synthesis.Voice.AGE_DONT_CARE;
98 throw new Error("jaspi does not have an equivalent to age "
104 * Gets the id for this voice.
105 * Should be unique for a synthesizer.
107 * @return the voice id
109 public String getId() {
114 * Gets a string representation of the object
116 * @return the name of this voice
118 public String toString() {
124 * Gets a FreeTTS com.sun.speech.freetts.Voice from this JSAPI voice
126 * @return a FreeTTS Voice or null, if the voice cannot be found
128 public synchronized com.sun.speech.freetts.Voice getVoice() {
133 * Sets the id for this voice.
135 * @param id the new id
137 public void setId(String id) {
142 * Creates a copy of this <code>BaseVoice</code>.
144 * @return the cloned object
146 public Object clone() {
147 return super.clone();
151 * Validates this FreeTTSVoice.
153 * @throws ValidationException if this FreeTTSVoice is invalid
155 public void validate() throws ValidationException {
156 if (validator != null) {
157 validator.validate();