|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.speech.freetts.lexicon.LetterToSoundImpl
Provides the phone list for words using the CMU6 letter-to-sound (LTS) rules, which are based on the Black, Lenzo, and Pagel paper, "Issues in Building General Letter-to-Sound Rules." Proceedings of ECSA Workshop on Speech Synthesis, pages 77-80, Australia, 1998.
The LTS rules are a simple state machine, with one entry point for each letter of the alphabet (lower case letters are always assumed, and the rules keep an array with one entry per letter that point into the state machine).
The state machine consists of a huge array, with most entries containing a decision and the indeces of two other entries. The first of these two indeces represents where to go if the decision is true, and the second represents where to go if the decision is false. All entries that do not contain a decision are final entries, and these contain a phone.
The decision in this case is a simple character comparison, but it is done in the context of a window around the character in the word. The decision consists of a index into the context window and a character value. If the character in the context window matches the character value, then the decision is true.
The machine traversal for each letter starts at that letter's entry in the state machine and ends only when it reaches a final state. If there is no phone that can be mapped, the phone in the final state is set to 'epsilon.'
The context window for a character is generated in the following way:
Here's how the phone for 'k' in 'monkey' might be determined:
This implementation will either read from a straight ASCII file or a binary file. When reading from an ASCII file, you can specify when the input line is tokenized: load, lookup, or never. If you specify 'load', the entire file will be parsed when it is loaded. If you specify 'lookup', the file will be loaded, but the parsing for each line will be delayed until it is referenced and the parsed form will be saved away. If you specify 'never', the lines will parsed each time they are referenced. The default is 'load'. To specify the load type, set the system property as follows:
-Dcom.sun.speech.freetts.lexicon.LTSTokenize=load
[[[TODO: This implementation uses ASCII 'a'-'z', which is not internationalized.]]]
Field Summary | |
protected java.util.HashMap |
letterIndex
The indexes of the starting points for letters in the state machine. |
protected boolean |
tokenizeOnLoad
If true, the state string is tokenized when it is first read. |
protected boolean |
tokenizeOnLookup
If true, the state string is tokenized the first time it is referenced. |
Constructor Summary | |
LetterToSoundImpl(java.net.URL ltsRules,
boolean binary)
Class constructor. |
Method Summary | |
boolean |
compare(LetterToSoundImpl other)
Compares this LTS to another for debugging purposes. |
void |
dumpBinary(java.lang.String path)
Dumps a binary form of the letter to sound rules. |
protected char[] |
getFullBuff(java.lang.String word)
Makes a character array that looks like "000#word#000". |
java.lang.String[] |
getPhones(java.lang.String word,
java.lang.String partOfSpeech)
Calculates the phone list for a given word. |
protected com.sun.speech.freetts.lexicon.LetterToSoundImpl.State |
getState(int i)
Gets the State at the given index. |
protected com.sun.speech.freetts.lexicon.LetterToSoundImpl.State |
getState(java.lang.String s)
Gets the State based upon the String . |
protected com.sun.speech.freetts.lexicon.LetterToSoundImpl.State |
getState(java.lang.String type,
java.util.StringTokenizer tokenizer)
Gets the State based upon the type
and tokenizer |
static void |
main(java.lang.String[] args)
Translates between text and binary forms of the CMU6 LTS rules. |
protected void |
parseAndAdd(java.lang.String line)
Creates a word from the given input line and add it to the state machine. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected boolean tokenizeOnLoad
protected boolean tokenizeOnLookup
protected java.util.HashMap letterIndex
Constructor Detail |
public LetterToSoundImpl(java.net.URL ltsRules, boolean binary) throws java.io.IOException
ltsRules
- a URL pointing to the text
containing the letter to sound rulesbinary
- if true, the URL is a binary source
java.lang.NullPointerException
- if the ltsRules are null
java.io.IOException
- if errors are encountered while reading the
compiled form or the addendaMethod Detail |
protected void parseAndAdd(java.lang.String line)
line
- the line of text from the input filepublic void dumpBinary(java.lang.String path) throws java.io.IOException
Binary format is:
MAGIC VERSION NUM STATES for each state ...
path
- the path to dump the file to
java.io.IOException
- if a problem occurs during the dumpprotected com.sun.speech.freetts.lexicon.LetterToSoundImpl.State getState(int i)
State
at the given index. This may
replace a String
at
the current spot with an actual State
instance.
i
- the index into the state machine
State
at the given index.protected com.sun.speech.freetts.lexicon.LetterToSoundImpl.State getState(java.lang.String s)
State
based upon the String
.
s
- the string to parse
State
protected com.sun.speech.freetts.lexicon.LetterToSoundImpl.State getState(java.lang.String type, java.util.StringTokenizer tokenizer)
State
based upon the type
and tokenizer.
- Parameters:
type
- one of STATE
or PHONE
tokenizer
- a StringTokenizer
containing the
State
- Returns:
- the parsed
State
protected char[] getFullBuff(java.lang.String word)
word
- the original word
public java.lang.String[] getPhones(java.lang.String word, java.lang.String partOfSpeech)
null
is returned. This particular
implementation ignores the part of speech.
getPhones
in interface LetterToSound
word
- the word to findpartOfSpeech
- the part of speech.
null
public boolean compare(LetterToSoundImpl other)
other
- the other LTS to compare to
true
if these are equivalentpublic static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |