com.sun.speech.freetts.lexicon
Class LetterToSoundImpl

java.lang.Object
  extended bycom.sun.speech.freetts.lexicon.LetterToSoundImpl
All Implemented Interfaces:
LetterToSound

public class LetterToSoundImpl
extends java.lang.Object
implements LetterToSound

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

tokenizeOnLoad

protected boolean tokenizeOnLoad
If true, the state string is tokenized when it is first read. The side effects of this are quicker lookups, but more memory usage and a longer startup time.


tokenizeOnLookup

protected boolean tokenizeOnLookup
If true, the state string is tokenized the first time it is referenced. The side effects of this are quicker lookups, but more memory usage.


letterIndex

protected java.util.HashMap letterIndex
The indexes of the starting points for letters in the state machine.

Constructor Detail

LetterToSoundImpl

public LetterToSoundImpl(java.net.URL ltsRules,
                         boolean binary)
                  throws java.io.IOException
Class constructor.

Parameters:
ltsRules - a URL pointing to the text containing the letter to sound rules
binary - if true, the URL is a binary source
Throws:
java.lang.NullPointerException - if the ltsRules are null
java.io.IOException - if errors are encountered while reading the compiled form or the addenda
Method Detail

parseAndAdd

protected void parseAndAdd(java.lang.String line)
Creates a word from the given input line and add it to the state machine. It expects the TOTAL line to come before any of the states.

Parameters:
line - the line of text from the input file

dumpBinary

public void dumpBinary(java.lang.String path)
                throws java.io.IOException
Dumps a binary form of the letter to sound rules. This method is not thread-safe.

Binary format is:

   MAGIC
   VERSION
   NUM STATES
   for each state ...
 

Parameters:
path - the path to dump the file to
Throws:
java.io.IOException - if a problem occurs during the dump

getState

protected com.sun.speech.freetts.lexicon.LetterToSoundImpl.State getState(int i)
Gets the State at the given index. This may replace a String at the current spot with an actual State instance.

Parameters:
i - the index into the state machine
Returns:
the State at the given index.

getState

protected com.sun.speech.freetts.lexicon.LetterToSoundImpl.State getState(java.lang.String s)
Gets the State based upon the String.

Parameters:
s - the string to parse
Returns:
the parsed State

getState

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.

Parameters:
type - one of STATE or PHONE
tokenizer - a StringTokenizer containing the State
Returns:
the parsed State

getFullBuff

protected char[] getFullBuff(java.lang.String word)
Makes a character array that looks like "000#word#000".

Parameters:
word - the original word
Returns:
the padded word

getPhones

public java.lang.String[] getPhones(java.lang.String word,
                                    java.lang.String partOfSpeech)
Calculates the phone list for a given word. If a phone list cannot be determined, null is returned. This particular implementation ignores the part of speech.

Specified by:
getPhones in interface LetterToSound
Parameters:
word - the word to find
partOfSpeech - the part of speech.
Returns:
the list of phones for word or null

compare

public boolean compare(LetterToSoundImpl other)
Compares this LTS to another for debugging purposes.

Parameters:
other - the other LTS to compare to
Returns:
true if these are equivalent

main

public static void main(java.lang.String[] args)
Translates between text and binary forms of the CMU6 LTS rules.