public class LetterToSoundImpl extends Object implements LetterToSound
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 indices of two other entries. The first of these two indices 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.]]]
Modifier and Type | Class and Description |
---|---|
(package private) static class |
LetterToSoundImpl.DecisionState
A
State that represents a decision to be made. |
(package private) static class |
LetterToSoundImpl.FinalState
A
State that represents a final state in the
state machine. |
(package private) static interface |
LetterToSoundImpl.State
A marker interface for the states in the LTS state machine.
|
Modifier and Type | Field and Description |
---|---|
private char[] |
fval_buff
An array of characters to hold a string for checking against a
rule.
|
(package private) static String |
INDEX
Entry in file represents the beginning of a new letter index.
|
protected HashMap |
letterIndex
The indexes of the starting points for letters in the state machine.
|
private static int |
MAGIC
Magic number for binary LTS files.
|
private int |
numStates
The number of states in the state machine.
|
(package private) static String |
PHONE
Entry in file represents a final state.
|
private static List |
phonemeTable
The list of phones that can be returned by the LTS rules.
|
(package private) static String |
STATE
Entry in file represents a state.
|
private Object[] |
stateMachine
The LTS 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.
|
(package private) static String |
TOTAL
Entry in file represents the total number of states in the
file.
|
private static int |
VERSION
Current binary file version.
|
private static int |
WINDOW_SIZE
The 'window size' of the LTS rules.
|
Constructor and Description |
---|
LetterToSoundImpl(URL ltsRules,
boolean binary)
Class constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
compare(LetterToSoundImpl other)
Compares this LTS to another for debugging purposes.
|
void |
dumpBinary(String path)
Dumps a binary form of the letter to sound rules.
|
private List |
findPhonemes()
Returns a list of all the phonemes used by the LTS rules.
|
protected char[] |
getFullBuff(String word)
Makes a character array that looks like "000#word#000".
|
String[] |
getPhones(String word,
String partOfSpeech)
Calculates the phone list for a given word.
|
protected LetterToSoundImpl.State |
getState(int i)
Gets the
State at the given index. |
protected LetterToSoundImpl.State |
getState(String s)
Gets the
State based upon the String . |
protected LetterToSoundImpl.State |
getState(String type,
StringTokenizer tokenizer)
Gets the
State based upon the type
and tokenizer |
private void |
loadBinary(InputStream is)
Loads the LTS rules from the given binary input stream.
|
private void |
loadText(InputStream is)
Loads the LTS rules from the given text input stream.
|
static void |
main(String[] args)
Translates between text and binary forms of the CMU6 LTS rules.
|
protected void |
parseAndAdd(String line)
Creates a word from the given input line and add it to the state
machine.
|
static final String TOTAL
static final String INDEX
static final String STATE
static final String PHONE
protected boolean tokenizeOnLoad
protected boolean tokenizeOnLookup
private static final int MAGIC
private static final int VERSION
private Object[] stateMachine
private int numStates
private static final int WINDOW_SIZE
private char[] fval_buff
cst_lts.c
.protected HashMap letterIndex
private static List phonemeTable
public LetterToSoundImpl(URL ltsRules, boolean binary) throws IOException
ltsRules
- a URL pointing to the text
containing the letter to sound rulesbinary
- if true, the URL is a binary sourceNullPointerException
- if the ltsRules are nullIOException
- if errors are encountered while reading the
compiled form or the addendaprivate void loadText(InputStream is) throws IOException
is
- the input streamIOException
- if an error occurs on input.private void loadBinary(InputStream is) throws IOException
is
- the input streamIOException
- if an error occurs on input.protected void parseAndAdd(String line)
line
- the line of text from the input filepublic void dumpBinary(String path) throws IOException
Binary format is:
MAGIC VERSION NUM STATES for each state ...
path
- the path to dump the file toIOException
- if a problem occurs during the dumpprivate List findPhonemes()
protected 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 machineState
at the given index.protected LetterToSoundImpl.State getState(String s)
State
based upon the String
.s
- the string to parseState
protected LetterToSoundImpl.State getState(String type, StringTokenizer tokenizer)
State
based upon the type
and tokenizer.
type
- one of STATE
or PHONE
tokenizer
- a StringTokenizer
containing the
State
State
protected char[] getFullBuff(String word)
word
- the original wordpublic String[] getPhones(String word, 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 totrue
if these are equivalentWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses