2 * Portions Copyright 2001 Sun Microsystems, Inc.
3 * Portions Copyright 1999-2001 Language Technologies Institute,
4 * Carnegie Mellon University.
5 * All Rights Reserved. Use is subject to license terms.
7 * See the file "license.terms" for information on usage and
8 * redistribution of this file, and for a DISCLAIMER OF ALL
11 package com.sun.speech.freetts.en.us;
13 import com.sun.speech.freetts.diphone.DiphonePitchmarkGenerator;
14 import com.sun.speech.freetts.diphone.DiphoneUnitSelector;
15 import com.sun.speech.freetts.Item;
16 import com.sun.speech.freetts.ProcessException;
17 import com.sun.speech.freetts.Relation;
18 import com.sun.speech.freetts.relp.UnitConcatenator;
19 import com.sun.speech.freetts.Utterance;
20 import com.sun.speech.freetts.UtteranceProcessor;
21 import com.sun.speech.freetts.Voice;
23 import com.sun.speech.freetts.Gender;
24 import com.sun.speech.freetts.Age;
26 import de.dfki.lt.freetts.ConcatenativeVoice;
28 import java.util.Locale;
30 import java.io.IOException;
36 * Defines an unlimited-domain diphone synthesis based voice
38 public class CMUDiphoneVoice extends CMUVoice implements ConcatenativeVoice {
40 protected URL database;
43 * Creates a simple voice. This is merely for backwards
44 * compatibility with versions of FreeTTS earlier than v1.2
45 * (i.e., before the voice manager was introduced).
47 public CMUDiphoneVoice() {
48 this(null, null, null, null, null, null, null, null, null);
52 * Creates a simple voice
54 * @param name the name of the voice
55 * @param gender the gender of the voice
56 * @param age the age of the voice
57 * @param description a human-readable string providing a
58 * description that can be displayed for the users.
59 * @param locale the locale of the voice
60 * @param domain the domain of this voice. For example,
61 * @param organization the organization which created the voice
62 * "general", "time", or
63 * "weather".
64 * @param lexicon the lexicon to load
65 * @param database a url to the unit database file for this voice
67 public CMUDiphoneVoice(String name, Gender gender,
68 Age age, String description, Locale locale, String domain,
69 String organization, CMULexicon lexicon, URL database) {
70 super(name, gender, age, description, locale,
71 domain, organization, lexicon);
75 this.database = database;
79 * Gets the url to the database that defines the unit data for this
82 * @return a url to the database
84 public URL getDatabase() {
85 if (database == null) {
86 /* This is merely for backwards compatibility with
87 * versions of FreeTTS earlier than v1.2 (i.e.,
88 * before the voice manager was introduced).
90 String name = getFeatures().getString(Voice.DATABASE_NAME);
91 database = this.getClass().getResource(name);
97 * Sets the FeatureSet for this Voice.
99 * @throws IOException if an I/O error occurs
101 protected void setupFeatureSet() throws IOException {
102 super.setupFeatureSet();
106 * Returns the post lexical processor to be used by this voice.
107 * Derived voices typically override this to customize behaviors.
109 * @return the Unit selector
111 * @throws IOException if an IO error occurs while getting
114 protected UtteranceProcessor getPostLexicalAnalyzer() throws IOException {
115 return new CMUDiphoneVoicePostLexicalAnalyzer();
119 * Returns the pitch mark generator to be used by this voice.
120 * Derived voices typically override this to customize behaviors.
121 * This voice uses a DiphonePitchMark generator to generate
124 * @return the pitchmark processor
126 * @throws IOException if an IO error occurs while getting
129 public UtteranceProcessor getPitchmarkGenerator() throws IOException {
130 return new DiphonePitchmarkGenerator();
134 * Returns the unit concatenator to be used by this voice.
135 * Derived voices typically override this to customize behaviors.
136 * This voice uses a relp.UnitConcatenator to concatenate units.
138 * @return the unit concatenator processor
140 * @throws IOException if an IO error occurs while getting
143 public UtteranceProcessor getUnitConcatenator() throws IOException {
144 return new UnitConcatenator();
149 * Returns the unit selector to be used by this voice.
150 * Derived voices typically override this to customize behaviors.
151 * This voice uses the DiphoneUnitSelector to select units. The
152 * unit selector requires the name of a diphone database. If no
153 * diphone database has been specified then an Error is thrown.
155 * @return the unit selector processor
157 * @throws IOException if an IO error occurs while getting
160 public UtteranceProcessor getUnitSelector() throws IOException {
161 return new DiphoneUnitSelector(getDatabase());
166 * Converts this object to a string
168 * @return a string representation of this object
170 public String toString() {
171 return "CMUDiphoneVoice";
177 * Annotates the utterance with post lexical information. Converts AH
178 * phonemes to AA phoneme in addition to the standard english postlex
181 class CMUDiphoneVoicePostLexicalAnalyzer implements UtteranceProcessor {
182 UtteranceProcessor englishPostLex =
183 new com.sun.speech.freetts.en.PostLexicalAnalyzer();
186 * performs the processing
187 * @param utterance the utterance to process/tokenize
188 * @throws ProcessException if an IOException is thrown during the
189 * processing of the utterance
191 public void processUtterance(Utterance utterance) throws ProcessException {
192 fixPhoneme_AH(utterance);
193 englishPostLex.processUtterance(utterance);
198 * Turns all AH phonemes into AA phonemes.
199 * This should really be done in the index itself
200 * @param utterance the utterance to fix
202 private void fixPhoneme_AH(Utterance utterance) {
203 for (Item item = utterance.getRelation(Relation.SEGMENT).getHead();
205 item = item.getNext()) {
206 if (item.getFeatures().getString("name").equals("ah")) {
207 item.getFeatures().setString("name", "aa");
212 // inherited from Object
213 public String toString() {
214 return "PostLexicalAnalyzer";