upstream version 1.2.2
[debian/freetts] / com / sun / speech / freetts / en / us / CMUArcticVoice.java
1 package com.sun.speech.freetts.en.us;
2
3 import java.io.IOException;
4 import java.net.URL;
5 import java.util.Locale;
6
7 import com.sun.speech.freetts.Age;
8 import com.sun.speech.freetts.Gender;
9 import com.sun.speech.freetts.Item;
10 import com.sun.speech.freetts.UtteranceProcessor;
11 import com.sun.speech.freetts.clunits.ClusterUnitSelector;
12
13 import de.dfki.lt.freetts.ClusterUnitNamer;
14
15 /**
16  * Experimental class that selects units for the
17  * <a href="http://festvox.org/cmu_arctic/">CMU ARCTIC voices</a>.
18  */
19 public class CMUArcticVoice extends CMUClusterUnitVoice {
20     
21     /**
22      * Creates a simple cluster unit voice for the ARCTIC voices
23      *
24      * @param name the name of the voice
25      * @param gender the gender of the voice
26      * @param age the age of the voice
27      * @param description a human-readable string providing a
28      * description that can be displayed for the users.
29      * @param locale the locale of the voice
30      * @param domain the domain of this voice.  For example,
31      * @param organization the organization which created the voice
32      * &quot;general&quot;, &quot;time&quot;, or
33      * &quot;weather&quot;.
34      * @param lexicon the lexicon to load
35      * @param database the url to the database containing unit data
36      * for this voice.
37      */
38     public CMUArcticVoice(String name, Gender gender, Age age,
39             String description, Locale locale, String domain,
40             String organization, CMULexicon lexicon, URL database) {
41         super(name, gender, age, description, locale,
42                 domain, organization, lexicon, database);
43     }
44
45     /**
46      * Returns the unit selector to be used by this voice.
47      * Derived voices typically override this to customize behaviors.
48      * This voice uses  a cluster unit selector as the unit selector.
49      * 
50      * @return the post lexical processor
51      * 
52      * @throws IOException if an IO error occurs while getting
53      *     processor
54      */
55     public UtteranceProcessor getUnitSelector() throws IOException {
56         ClusterUnitNamer unitNamer = new ClusterUnitNamer() {
57             public void setUnitName(Item seg) {
58                 String VOWELS = "aeiou";
59                 String cname = null;
60                 
61                 String segName = seg.getFeatures().getString("name");
62                 
63                 /*
64                  * If we have a vowel, then the unit name is the segment name
65                  * plus a 0 or 1, depending upon the stress of the parent.
66                  * Otherwise, the unit name is the segment name plus "coda" or
67                  * "onset" based upon the seg_onsetcoda feature processor.
68                  */
69                 if (segName.equals("pau")) {
70                     cname = segName;
71                 } else if (VOWELS.indexOf(segName.charAt(0)) >= 0) {
72                     cname = segName + seg.findFeature("R:SylStructure.parent.stress");
73                 } else {
74                     cname = segName + seg.findFeature("seg_onsetcoda");
75                 }
76                 
77                 seg.getFeatures().setString("clunit_name", cname);
78             }
79             
80         };
81         return new ClusterUnitSelector(getDatabase(), unitNamer);
82     }
83 }
84