upstream version 1.2.2
[debian/freetts] / de / dfki / lt / freetts / en / us / MbrolaVoiceDirectory.java
1 package de.dfki.lt.freetts.en.us;
2
3 import java.util.List;
4 import java.util.Locale;
5
6 import com.sun.speech.freetts.Age;
7 import com.sun.speech.freetts.Gender;
8 import com.sun.speech.freetts.ValidationException;
9 import com.sun.speech.freetts.Voice;
10 import com.sun.speech.freetts.VoiceDirectory;
11 import com.sun.speech.freetts.en.us.CMULexicon;
12 import com.sun.speech.freetts.util.Utilities;
13
14 /**
15  * Provides access to MBROLA voices.
16  */
17 public class MbrolaVoiceDirectory extends VoiceDirectory {
18     
19     public Voice[] getVoices() {
20
21         String base = Utilities.getProperty("mbrola.base", null);
22
23         if (base == null || base.trim().length() == 0) {
24             System.out.println(
25                 "System property \"mbrola.base\" is undefined.  "
26                 + "Will not use MBROLA voices.");
27             return new Voice[0];
28         } else {
29
30             CMULexicon lexicon = new CMULexicon("cmulex");
31             
32             Voice mbrola1 = new MbrolaVoice
33                 ("us1", "us1", 150f, 180F, 22F,
34                  "mbrola_us1", Gender.FEMALE, Age.YOUNGER_ADULT,
35                  "MBROLA Voice us1",
36                  Locale.US, "general", "mbrola", lexicon);
37
38             Voice mbrola2 = new MbrolaVoice
39                 ("us2", "us2", 150f, 115F, 12F,
40                  "mbrola_us2", Gender.MALE, Age.YOUNGER_ADULT,
41                  "MBROLA Voice us2",
42                  Locale.US, "general", "mbrola", lexicon);
43
44             Voice mbrola3 = new MbrolaVoice
45                 ("us3", "us3", 150f, 125F, 12F,
46                  "mbrola_us3", Gender.MALE, Age.YOUNGER_ADULT,
47                  "MBROLA Voice us3",
48                  Locale.US, "general", "mbrola", lexicon);
49
50             Voice[] voices = {mbrola1, mbrola2, mbrola3};
51             
52             List validVoices = new java.util.ArrayList();
53             int count = 0;
54
55             for (int i = 0; i < voices.length; i++) {
56                 MbrolaVoiceValidator validator = 
57                     new MbrolaVoiceValidator((MbrolaVoice) voices[i]);
58                 try {
59                     validator.validate();
60                     validVoices.add(voices[i]);
61                     count++;
62                 } catch (ValidationException ve) {
63                     // does nothing if the voice is not found 
64                 }
65             }
66             if (count == 0) {
67                 System.err.println(
68                     "\n"
69                     + "Could not validate any MBROLA voices at\n\n"
70                     + "  " + base + "\n");
71                 if (base.indexOf('~') != -1) {
72                     System.err.println(
73                         "DO NOT USE ~ as part of the path name\n"
74                         + "to specify the mbrola.base property.");
75                 }
76                 System.err.println(
77                     "Make sure you FULLY specify the path to\n"
78                     + "the MBROLA directory using the mbrola.base\n"
79                     + "system property.\n");
80                 return new Voice[0];
81             } else {
82                 return ((Voice[])validVoices.toArray(new Voice[count]));
83             }
84         }
85     }
86
87     /**
88      * Prints out the MBROLA voices.
89      */
90     public static void main(String[] args) {
91         System.out.println((new MbrolaVoiceDirectory()).toString());
92     }
93 }
94
95