2 * Portions Copyright 2004 DFKI GmbH.
3 * Portions Copyright 2001 Sun Microsystems, Inc.
4 * Portions Copyright 1999-2001 Language Technologies Institute,
5 * Carnegie Mellon University.
6 * All Rights Reserved. Use is subject to license terms.
8 * See the file "license.terms" for information on usage and
9 * redistribution of this file, and for a DISCLAIMER OF ALL
12 package de.dfki.lt.freetts.de;
14 import java.io.IOException;
16 import java.util.List;
18 import com.sun.speech.freetts.VoiceManager;
19 import com.sun.speech.freetts.lexicon.LexiconImpl;
20 import com.sun.speech.freetts.util.BulkTimer;
23 * Provides a CMU lexicon-specific implementation of a Lexicon that is
24 * stored in a text file.
26 public class GermanLexicon extends LexiconImpl {
30 * Creates a GermanLexicon based upon the given compiled and addenda
31 * DBs and the given letter to sound rules
33 * @param compiledURL the compiled database is loaded from here
34 * @param addendaURL the database addenda is loaded from here
35 * @param letterToSoundURL the letter to sound rules are loaded
37 * @param binary if <code>true</code> the input data are loaded as
38 * binary ; otherwise if <code>false</code> the input
39 * data are loaded as text.
42 public GermanLexicon(URL compiledURL,
46 setLexiconParameters(compiledURL, addendaURL, letterToSoundURL, binary);
50 * Creates the default CMU Lexicon which is a binary lexicon
52 public GermanLexicon() {
57 * Creates the CMU Lexicon which is a binary lexicon
59 * @param basename the basename for the lexicon.
61 public GermanLexicon(String basename) {
65 public GermanLexicon(String basename, boolean useBinaryIO) {
66 java.net.URLClassLoader classLoader =
67 VoiceManager.getVoiceClassLoader();
68 String type = (useBinaryIO ? "bin" : "txt");
70 URL letterToSoundURL = classLoader.getResource(
71 "de/dfki/lt/freetts/de/" + basename + "_lts." + type);
72 URL compiledURL = classLoader.getResource(
73 "de/dfki/lt/freetts/de/" + basename
74 + "_compiled." + type);
75 URL addendaURL = classLoader.getResource(
76 "de/dfki/lt/freetts/de/" + basename
77 + "_addenda." + type);
79 /* Just another try with possibly a different class loader
80 * if the above didn't work.
82 if (letterToSoundURL == null) {
83 Class cls = GermanLexicon.class;
84 letterToSoundURL = cls.getResource(basename + "_lts." + type);
85 compiledURL = cls.getResource(basename + "_compiled." + type);
86 addendaURL = cls.getResource(basename + "_addenda." + type);
87 if (letterToSoundURL == null) {
89 "GermanLexicon: Oh no! Couldn't find lexicon data!");
93 setLexiconParameters(compiledURL, addendaURL,
94 letterToSoundURL, useBinaryIO);
98 * Get the GermanLexicon.
100 * @param useBinaryIO if true use binary IO to load DB
102 * @throws IOException if problems occurred while reading the data
104 static public GermanLexicon getInstance( boolean useBinaryIO)
106 return getInstance("dummylex", useBinaryIO);
110 * Get the GermanLexicon.
112 * @param useBinaryIO if true use binary IO to load DB
114 * @throws IOException if problems occurred while reading the data
116 static public GermanLexicon getInstance( String basename, boolean useBinaryIO)
118 GermanLexicon lexicon = new GermanLexicon(basename, useBinaryIO);
124 * Determines if the currentPhone represents a new syllable
127 * @param syllablePhones the phones in the current syllable so far
128 * @param wordPhones the phones for the whole word
129 * @param currentWordPhone the word phone in question
131 * @return <code>true</code> if the word phone in question is on a
132 * syllable boundary; otherwise <code>false</code>.
134 public boolean isSyllableBoundary(List syllablePhones,
136 int currentWordPhone) {
141 * Provides test code for the GermanLexicon.
142 * <br><b>Usage:</b><br>
144 * de.dfki.lt.freetts.de.GermanLexicon [options]
146 * Where options is any combination of:
150 * -generate_binary [base_name]
156 public static void main(String[] args) {
157 LexiconImpl lex, lex2;
158 boolean showTimes = false;
159 String srcPath = ".";
160 String destPath = ".";
161 String baseName = "germanlex";
164 if (args.length > 0) {
165 BulkTimer.LOAD.start();
166 for (int i = 0 ; i < args.length; i++) {
167 if (args[i].equals("-src")) {
169 } else if (args[i].equals("-dest")) {
170 destPath = args[++i];
171 } else if (args[i].equals("-name")
172 && i < args.length - 1) {
173 baseName = args[++i];
174 } else if (args[i].equals("-generate_binary")) {
176 System.out.println("Loading " + baseName);
177 String path = "file:" + srcPath + "/" + baseName;
178 lex = new GermanLexicon(
179 new URL(path + "_compiled.txt"),
180 new URL(path + "_addenda.txt"),
181 new URL(path + "_lts.txt"),
183 BulkTimer.LOAD.start("load_text");
185 BulkTimer.LOAD.stop("load_text");
187 System.out.println("Dumping " + baseName);
188 BulkTimer.LOAD.start("dump_text");
189 lex.dumpBinary(destPath + "/" + baseName);
190 BulkTimer.LOAD.stop("dump_text");
192 } else if (args[i].equals("-compare")) {
194 BulkTimer.LOAD.start("load_text");
195 lex = GermanLexicon.getInstance(baseName, false);
196 BulkTimer.LOAD.stop("load_text");
198 BulkTimer.LOAD.start("load_binary");
199 lex2 = GermanLexicon.getInstance(baseName, true);
200 BulkTimer.LOAD.stop("load_binary");
202 BulkTimer.LOAD.start("compare");
204 BulkTimer.LOAD.stop("compare");
205 } else if (args[i].equals("-showtimes")) {
208 System.out.println("Unknown option " + args[i]);
211 BulkTimer.LOAD.stop();
213 BulkTimer.LOAD.show("GermanLexicon loading and dumping");
216 System.out.println("Options: ");
217 System.out.println(" -src path");
218 System.out.println(" -dest path");
219 System.out.println(" -compare");
220 System.out.println(" -generate_binary");
221 System.out.println(" -showtimes");
223 } catch (IOException ioe) {
224 System.err.println(ioe);