public class DiphoneUnitDatabase extends Object
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.cacheTypecan be set to one of:
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.Modifier and Type | Field and Description |
---|---|
private String |
cacheType |
private Diphone |
defaultDiphone |
private int |
defaultIndex |
private Map |
diphoneIndex |
private Map |
diphoneMap |
private static int |
INDEX_MAGIC |
private String |
indexName |
private int |
lineCount |
private static Logger |
LOGGER
Logger instance.
|
private float |
lpcMin |
private float |
lpcRange |
private static int |
MAGIC |
private static int |
MAX_DB_SIZE |
private MappedByteBuffer |
mbb |
private String |
name |
private int |
numChannels |
private int |
residualFold |
private SampleInfo |
sampleInfo |
private int |
sampleRate |
private boolean |
useCache |
private boolean |
useIndexing |
private boolean |
useNewIO |
private boolean |
useSoftCache |
private static int |
VERSION |
Constructor and Description |
---|
DiphoneUnitDatabase(URL url,
boolean isBinary)
Creates the DiphoneUnitDatabase from the given input stream.
|
Modifier and Type | Method and Description |
---|---|
private void |
add(Diphone diphone)
Adds the given diphone to the DB.
|
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.
|
(package private) void |
dumpBinaryIndex(String path)
Dumps a binary index.
|
private void |
dumpCacheSize()
Dumps the soft ref cache.
|
private Diphone |
getFromCache(String name)
Gets the named diphone from the cache.
|
private int |
getIndex(String diphone)
Gets the index for the given diphone.
|
private String |
getIndexName(String databaseName)
Returns the index name from the databaseName.
|
String |
getName()
Returns the name of this DiphoneUnitDatabase.
|
(package private) SampleInfo |
getSampleInfo()
Return the information about the sample data
for this database.
|
Diphone |
getUnit(String unitName)
Looks up the diphone with the given name.
|
private void |
loadBinary(DataInputStream dis)
Loads the binary data from the given input stream.
|
private void |
loadBinary(InputStream is)
Loads a binary file from the input stream.
|
private void |
loadBinaryIndex(URL url)
Loads a binary index.
|
private void |
loadDatabase(ByteBuffer bb)
Loads the database from the given byte buffer.
|
private void |
loadDatabaseHeader(ByteBuffer bb)
Loads the database header from the given byte buffer.
|
private void |
loadMappedBinary(FileInputStream is)
Loads the database from the given FileInputStream.
|
private void |
loadText(InputStream is)
Loads the database from the given input stream.
|
static void |
main(String[] args)
Manipulates a DiphoneUnitDatabase.
|
private void |
mapDatabase(FileInputStream is)
Maps the database from the given FileInputStream.
|
private void |
parseAndAdd(String line,
BufferedReader reader)
Parses and process the given line.
|
private void |
putIntoCache(String diphoneName,
Diphone diphone)
Puts the diphone in the cache.
|
private int sampleRate
private int numChannels
private int residualFold
private float lpcMin
private float lpcRange
private int lineCount
private Diphone defaultDiphone
private Map diphoneMap
private Map diphoneIndex
private SampleInfo sampleInfo
private boolean useNewIO
private boolean useIndexing
private boolean useCache
private boolean useSoftCache
private static final int MAGIC
private static final int INDEX_MAGIC
private static final int VERSION
private static final int MAX_DB_SIZE
private MappedByteBuffer mbb
private int defaultIndex
public DiphoneUnitDatabase(URL url, boolean isBinary) throws IOException
url
- the location of the databaseisBinary
- if true
the database is in
binary format; otherwise it is in text formatIOException
- if there is trouble opening the DBSampleInfo getSampleInfo()
private String getIndexName(String databaseName)
databaseName
- the database nameprivate void loadText(InputStream is)
is
- the input streamprivate void parseAndAdd(String line, BufferedReader reader)
line
- the line to processreader
- the source for the linesprivate void add(Diphone diphone)
diphone
- the diphone to add.public Diphone getUnit(String unitName)
unitName
- the name of the diphone to look forprivate Diphone getFromCache(String name)
name
- the name of the diphone null
if not in the cacheprivate void putIntoCache(String diphoneName, Diphone diphone)
diphoneName
- the name of the diphonediphone
- the diphone to put in the cacheprivate void dumpCacheSize()
public void dump()
public void dumpBinary(String path)
path
- the path to dump the file tovoid dumpBinaryIndex(String path)
path
- the path to dump the file toprivate void loadBinaryIndex(URL url)
url
- the location of the binary index fileprivate int getIndex(String diphone)
diphone
- the name of the diphoneprivate void loadBinary(InputStream is) throws IOException
Note that we currently have four! methods of loading up the database. We were interested in the performance characteristics of the various methods of loading the database so we coded it all up.
is
- the input stream to read the database
fromIOException
- if there is trouble opening the DBprivate void loadBinary(DataInputStream dis) throws IOException
dis
- the data input stream.IOException
private void loadMappedBinary(FileInputStream is) throws IOException
is
- the InputStream to load the database fromIOException
- if there is trouble opening the DBprivate void mapDatabase(FileInputStream is) throws IOException
is
- the InputStream to load the database fromIOException
- if there is trouble opening the DBprivate void loadDatabaseHeader(ByteBuffer bb) throws IOException
bb
- the byte buffer to load the db fromIOException
- if there is trouble opening the DBprivate void loadDatabase(ByteBuffer bb) throws IOException
bb
- the byte buffer to load the db fromIOException
- if there is trouble opening the DBpublic boolean compare(DiphoneUnitDatabase other)
other
- the other databasetrue
if the DBs are identical;
otherwise false
public static void main(String[] args)
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
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses