Package com.sun.speech.freetts.diphone

# Class DiphoneUnitDatabase

java.lang.Object
com.sun.speech.freetts.diphone.DiphoneUnitDatabase

public class DiphoneUnitDatabase extends Object
Represents and manages the unit data for all diphones. The diphone data set is stored in a set of data files. These data are loaded by this class into internal data structures before diphone synthesis can occur.

The diphone data set is one of the largest sets of data that needs to be loaded by the synthesizer and therefore can add to the overall startup time for any system using this database. For certain applications, the startup time is a critical spec that needs to be optimized, while for other applications, startup time is inconsequential. This class provides settings (via system properties) that control how the database is to be loaded so that applications can tune for quick startup or optimal run time.

This class serves also as a testbed for comparing performance of the traditional java binary I/O and the new io ( `java.nio` ) package.

A diphone database can be loaded from a text data file, or a binary datafile. The binary version loads significantly faster than the text version. Additionally, a binary index can be generated and used to reduce overall memory footprint.

A DiphoneUnitDatabase contains an array of frames, and an aray of residuals. The frames are the samples of the wave, and the residuals are for linear predictive coding use. This is called "cst_sts" (a struct) in flite.

Note that if 'com.sun.speech.freetts.useNewIO' is set to true and the input type is binary, than the JDK1.4+ new IO api is used to load the database.

The system property

            com.sun.speech.freetts.diphone.UnitDatabase.cacheType

can be set to one of:

- preload: database is loaded at startup
- demand: database is loaded on demand
- hard: database is loaded on demand but cached
- soft: database is loaded on demand but cached with soft references

This `cacheType` setting controls how the database is loaded. The default is to 'preload' the database. This setting gives best runtime performance but with longer initial startup cost.

## Constructor Summary

Constructors
Constructor
Description
`DiphoneUnitDatabase(URL url, boolean isBinary)`
Creates the DiphoneUnitDatabase from the given input stream.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`compare(DiphoneUnitDatabase other)`
Compares this database to another.
`void`
`dump()`
Dumps the diphone database.
`void`
`dumpBinary(String path)`
Dumps a binary form of the database.
`String`
`getName()`
Returns the name of this DiphoneUnitDatabase.
`Diphone`
`getUnit(String unitName)`
Looks up the diphone with the given name.
`static void`
`main(String[] args)`
Manipulates a DiphoneUnitDatabase.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### DiphoneUnitDatabase

public DiphoneUnitDatabase(URL url, boolean isBinary) throws IOException
Creates the DiphoneUnitDatabase from the given input stream.

Parameters:
  `url` - the location of the database
  `isBinary` - if `true` the database is in binary format; otherwise it is in text format
Throws:
  `IOException` - if there is trouble opening the DB

## Method Details

### getUnit

public Diphone getUnit(String unitName)
Looks up the diphone with the given name.

Parameters:
  `unitName` - the name of the diphone to look for
Returns:
  the diphone or the defaultDiphone if not found.

### getName

public String getName()
Returns the name of this DiphoneUnitDatabase.

### dump

public void dump()
Dumps the diphone database.

### dumpBinary

public void dumpBinary(String path)
Dumps a binary form of the database.

Parameters:
  `path` - the path to dump the file to

### compare

public boolean compare(DiphoneUnitDatabase other)
Compares this database to another. This is used for testing. With this method we can load up two databases (one perhaps from a text source and one from a binary source) and compare to verify that the dbs are identical

Parameters:
  `other` - the other database
Returns:
  `true` if the DBs are identical; otherwise `false`

### main

public static void main(String[] args)
Manipulates a DiphoneUnitDatabase. This program is typically used to generate the binary form (with index) of the DiphoneUnitDatabase from the text form. Additionally, this program can be used to compare two databases to see if they are identical (used for testing).

Usage

`java com.sun.speech.freetts.diphone.DiphoneUnitDatabase [options]`

Options

- `-src path` provides a directory path to the source text for the database
- `-dest path` provides a directory for where to place the resulting binaries
- `-generate_binary [filename]` reads in the text version of the database and generates the binary version of the database.
- `-compare` Loads the text and binary versions of the database and compares them to see if they are equivalent.
- `-showTimes` shows timings for any loading, comparing or dumping operation