2 * Copyright 2002 DFKI GmbH.
3 * Portions Copyright 2002 Sun Microsystems, Inc.
4 * All Rights Reserved. Use is subject to license terms.
6 * See the file "license.terms" for information on usage and
7 * redistribution of this file, and for a DISCLAIMER OF ALL
11 package de.dfki.lt.freetts.en.us;
14 import java.io.IOException;
16 import java.util.Locale;
18 import com.sun.speech.freetts.Age;
19 import com.sun.speech.freetts.Gender;
20 import com.sun.speech.freetts.UtteranceProcessor;
21 import com.sun.speech.freetts.en.us.CMULexicon;
22 import com.sun.speech.freetts.en.us.CMUVoice;
23 import com.sun.speech.freetts.util.Utilities;
25 import de.dfki.lt.freetts.mbrola.MbrolaAudioOutput;
26 import de.dfki.lt.freetts.mbrola.MbrolaCaller;
27 import de.dfki.lt.freetts.mbrola.ParametersToMbrolaConverter;
30 * Defines an unlimited-domain diphone synthesis based voice using
31 * the MBROLA synthesis.
33 public class MbrolaVoice extends CMUVoice {
35 private String databaseDirectory; // where the voice database is
36 private String database; // name of the voice database
38 private static final String MRPA_TO_SAMPA_RENAME_LIST =
39 "V ah i iy I ih U uh { ae @ ax r= er A aa O ao u uw E eh EI ey AI ay OI oy aU aw @U ow j y h hh N ng S sh T th Z zh D dh tS ch dZ jh _ pau";
42 * Creates an MbrolaVoice.
44 * @param databaseDirectory the directory within the MBROLA directory
45 * where the voice database of this voice is located
46 * @param database the name of the voice database of this voice
47 * @param rate the rate of the voice
48 * @param pitch the pitch of the voice
49 * @param range the range of the voice
50 * @param name the name of the voice
51 * @param gender the gender of the voice
52 * @param age the age of the voice
53 * @param description a human-readable string providing a
54 * description that can be displayed for the users.
55 * @param locale the locale of the voice
56 * @param domain the domain of this voice. For example,
57 * @param organization the organization which created the voice
58 * @param lexicon the lexicon to use
60 public MbrolaVoice(String databaseDirectory,
61 String database, float rate, float pitch, float range,
62 String name, Gender gender, Age age,
63 String description, Locale locale, String domain,
64 String organization, CMULexicon lexicon) {
65 super(name, gender, age, description, locale,
66 domain, organization, lexicon);
70 this.databaseDirectory = databaseDirectory;
71 this.database = database;
74 //[[Providing the Mbrola classes via getUnitSelector() and
75 // getUnitConcatenator() is just a hack allowing us to use
76 // the current CMUVoice.java framework. It only means that
77 // after the Durator and the ContourGenerator, the classes
78 // process the utterance (Selector before Concatenator).]]
80 * Returns the unit selector to be used by this voice.
81 * Derived voices typically override this to customize behaviors.
83 * @return the unit selector
85 * @throws IOException if an IO error occurs while getting
88 protected UtteranceProcessor getUnitSelector() throws IOException {
89 return new ParametersToMbrolaConverter();
93 * Returns the command line that invokes the MBROLA executable.
94 * The command will be in the form of:
96 * <pre> {mbrolaExecutable} -e -R {mbrolaRenameList} {mbrolaVoiceDB}
99 protected String[] getMbrolaCommand() {
101 // Construct the mbrola command in such a way that
102 // mbrola reads from stdin and writes raw, headerless audio data
103 // to stdout; translates CMU us radio to sampa phonetic symbols;
104 // and only complains, but does not abort, when encountering an
107 {getMbrolaBinary(), "-e", "-R", getRenameList(),
108 getDatabase(), "-", "-.raw"};
111 for (int i = 0; i < cmd.length; i++) {
112 System.out.println(cmd[i]);
120 * Returns the absolute name of the MBROLA directory.
122 * @return the absolute name of the MBROLA directory
124 public String getMbrolaBase() {
125 return Utilities.getProperty("mbrola.base", ".");
129 * Returns the absolute file name of the MBROLA binary.
131 * @return the absolute file name of the MBROLA binary
133 public String getMbrolaBinary() {
134 // In windows environments, executables typically end with exe, so
135 // we add this suffix if we are running under windows.
136 StringBuffer executable = new StringBuffer();
137 executable.append("mbrola");
138 String os = System.getProperty("os.name");
139 if (os.indexOf("Windows") >= 0) {
140 executable.append(".exe");
142 return getMbrolaBase() + File.separator + executable.toString();
146 * Returns the absolute file name of the MBROLA phonetic symbols
149 * @return the absolute file name of the rename table
151 public String getRenameList() {
152 return MRPA_TO_SAMPA_RENAME_LIST;
156 * Returns the absolute file name of the Voice database
157 * this MbrolaVoice uses.
159 * @return the absolute file name of the Voice database
161 public String getDatabase() {
162 return getMbrolaBase() + File.separator +
163 databaseDirectory + File.separator + database;
167 // * Returns the unit concatenator to be used by this voice.
168 // * Derived voices typically override this to customize behaviors.
170 // * @return the unit conatenator
172 // * @throws IOException if an IO error occurs while getting
175 // protected UtteranceProcessor getUnitConcatenator() throws IOException {
179 //[[Providing the Mbrola classes via getUnitSelector() and
180 // getUnitConcatenator() is just a hack allowing us to use
181 // the current CMUVoice.java framework. It only means that
182 // after the Durator and the ContourGenerator, the classes
183 // process the utterance (Selector before Concatenator).]]
185 * Returns the unit concatenator to be used by this voice.
186 * This method constructs the command line with which the
187 * MBROLA binary will be called, and initialises the
188 * MbrolaCaller accordingly.
190 * @return the unit conatenator
192 * @throws IOException if an IO error occurs while getting
195 protected UtteranceProcessor getUnitConcatenator() throws IOException {
196 return new MbrolaCaller(getMbrolaCommand());
200 * Returns the audio output used by this voice.
202 * @return the audio output used by this voice
204 * @throws IOException if an I/O error occurs
206 protected UtteranceProcessor getAudioOutput() throws IOException {
207 return new MbrolaAudioOutput();
211 * Get a resource for this voice. Resources for this voice are located in
212 * the package <code>com.sun.speech.freetts.en.us</code>.
214 protected URL getResource(String resource) {
215 return com.sun.speech.freetts.en.us.CMUVoice.class.
216 getResource(resource);
220 * Converts this object to a string
222 * @return a string representation of this object
224 public String toString() {
225 return "MbrolaVoice";