public class Sphinx3Loader extends java.lang.Object implements Loader
The acoustic model is stored as a directory specified by a URL. The dictionary and language model files are not required to be in the package. You can specify their locations separately.
Configuration file should set mandatory property of component: location - this specifies the directory where the actual model data files are. You can use resource: prefix to refer to files packed inside jar or any other URI scheme. The actual model data files are named "mdef", "means", "variances", "transition_matrices", "mixture_weights".
Modifier and Type | Field and Description |
---|---|
protected static int |
BYTE_ORDER_MAGIC |
protected float |
distFloor |
protected static java.lang.String |
FILLER |
protected java.util.logging.Logger |
logger |
protected LogMath |
logMath |
protected Pool<float[]> |
meansPool |
protected Pool<float[][]> |
meanTransformationMatrixPool |
protected Pool<float[]> |
meanTransformationVectorPool |
protected float |
mixtureWeightFloor |
protected GaussianWeights |
mixtureWeights |
static java.lang.String |
MODEL_VERSION
Supports this version of the acoustic model
|
protected java.util.Properties |
modelProps |
static java.lang.String |
PROP_LOCATION
The root location of the model directory structure
|
static java.lang.String |
PROP_MC_FLOOR
Mixture component score floor.
|
static java.lang.String |
PROP_MW_FLOOR
Mixture weight floor
|
static java.lang.String |
PROP_TOPN
Number of top Gaussians to use in scoring
|
static java.lang.String |
PROP_UNIT_MANAGER
The unit manager
|
static java.lang.String |
PROP_USE_CD_UNITS
The property specifying whether context-dependent units should be used.
|
static java.lang.String |
PROP_VARIANCE_FLOOR
Variance floor.
|
protected Pool<Senone> |
senonePool |
protected static java.lang.String |
SILENCE_CIPHONE |
protected float[][] |
transformMatrix |
protected Pool<float[][]> |
transitionsPool |
protected boolean |
useCDUnits |
protected float |
varianceFloor |
protected Pool<float[]> |
variancePool |
protected Pool<float[][]> |
varianceTransformationMatrixPool |
protected Pool<float[]> |
varianceTransformationVectorPool |
Constructor and Description |
---|
Sphinx3Loader() |
Sphinx3Loader(java.lang.String location,
UnitManager unitManager,
float distFloor,
float mixtureWeightFloor,
float varianceFloor,
int topGauNum,
boolean useCDUnits) |
Sphinx3Loader(java.net.URL location,
UnitManager unitManager,
float distFloor,
float mixtureWeightFloor,
float varianceFloor,
int topGauNum,
boolean useCDUnits) |
Modifier and Type | Method and Description |
---|---|
void |
clearGauScores() |
protected Pool<Senone> |
createSenonePool(float distFloor,
float varianceFloor)
Creates the senone pool from the rest of the pools.
|
java.util.Map<java.lang.String,Unit> |
getContextIndependentUnits()
Returns the map of context indepent units.
|
protected java.io.InputStream |
getDataStream(java.lang.String path) |
protected HMMManager |
getHmmManager()
Return the HmmManager.
|
HMMManager |
getHMMManager()
Returns the HMM Manager for this loader.
|
int |
getLeftContextSize()
Returns the size of the left context for context dependent units.
|
java.lang.String |
getLocation() |
protected Pool<float[][]> |
getMatrixPool()
Return the MatrixPool.
|
Pool<float[]> |
getMeansPool()
Gets the pool of means for this loader.
|
Pool<float[][]> |
getMeansTransformationMatrixPool()
Gets the means transformation matrix pool.
|
Pool<float[]> |
getMeansTransformationVectorPool()
Gets the means transformation vectors pool.
|
GaussianWeights |
getMixtureWeights()
Gets the mixture weight pool.
|
protected GaussianWeights |
getMixtureWeightsPool()
Return the MixtureWeightsPool.
|
int |
getNumGaussiansPerState() |
int |
getNumStates() |
int |
getNumStreams() |
java.util.Properties |
getProperties() |
int |
getRightContextSize()
Returns the size of the right context for context dependent units.
|
int[] |
getSenone2Ci() |
Pool<Senone> |
getSenonePool()
Gets the senone pool for this loader.
|
protected SenoneSequence |
getSenoneSequence(int[] stateid)
Gets the senone sequence representing the given senones.
|
float[][] |
getTransformMatrix()
Gets the transformation matrix.
|
Pool<float[][]> |
getTransitionMatrixPool()
Gets the transition matrix pool.
|
Pool<float[]> |
getVariancePool()
Gets the variance pool.
|
Pool<float[][]> |
getVarianceTransformationMatrixPool()
Gets the variance transformation matrix pool.
|
Pool<float[]> |
getVarianceTransformationVectorPool()
Gets the variance transformation vectors pool.
|
int[] |
getVectorLength() |
boolean |
hasTiedMixtures() |
protected void |
init(java.net.URL location,
UnitManager unitManager,
float distFloor,
float mixtureWeightFloor,
float varianceFloor,
int topGauNum,
boolean useCDUnits,
java.util.logging.Logger logger) |
void |
load()
Loads the acoustic model.
|
Pool<float[]> |
loadDensityFile(java.lang.String path,
float floor)
Loads the sphinx3 density file, a set of density arrays are created and
placed in the given pool.
|
protected void |
loadHMMPool(boolean useCDUnits,
java.io.InputStream inputStream)
Loads the sphinx3 density file, a set of density arrays are created and
placed in the given pool.
|
protected GaussianWeights |
loadMixtureWeights(java.lang.String path,
float floor)
Loads the mixture weights (Binary).
|
protected void |
loadModelFiles()
Loads the AcousticModel from a directory in the file system.
|
protected java.util.Properties |
loadModelProps(java.lang.String path) |
protected float[][] |
loadTransformMatrix(java.lang.String path)
Loads the transform matrices (Binary).
|
protected Pool<float[][]> |
loadTransitionMatrices(java.lang.String path)
Loads the transition matrices (Binary).
|
void |
logInfo()
logs information about this loader
|
void |
newProperties(PropertySheet ps)
This method is called when this configurable component needs to be reconfigured.
|
float |
readFloat(java.io.DataInputStream dis)
Read a float from the input stream, byte-swapping as necessary.
|
float[] |
readFloatArray(java.io.DataInputStream dis,
int size)
Reads the given number of floats from the stream and returns them in an
array of floats.
|
int |
readInt(java.io.DataInputStream dis)
Read an integer from the input stream, byte-swapping as necessary.
|
java.io.DataInputStream |
readS3BinaryHeader(java.lang.String path,
java.util.Properties props)
Reads the S3 binary header from the given location + path.
|
protected boolean |
sameSenoneSequence(int[] ssid1,
int[] ssid2)
Returns true if the given senone sequence IDs are the same.
|
void |
setGauScoresQueueLength(int scoresQueueLen) |
void |
update(Transform transform,
ClusteredDensityFileData clusters)
Apply the transform
|
@S4Component(type=UnitManager.class) public static final java.lang.String PROP_UNIT_MANAGER
@S4String(mandatory=true) public static final java.lang.String PROP_LOCATION
@S4Boolean(defaultValue=true) public static final java.lang.String PROP_USE_CD_UNITS
@S4Double(defaultValue=0.0) public static final java.lang.String PROP_MC_FLOOR
@S4Double(defaultValue=9.999999747378752E-5) public static final java.lang.String PROP_VARIANCE_FLOOR
@S4Double(defaultValue=1.0000000116860974E-7) public static final java.lang.String PROP_MW_FLOOR
@S4Integer(defaultValue=4) public static final java.lang.String PROP_TOPN
protected static final java.lang.String FILLER
protected static final java.lang.String SILENCE_CIPHONE
protected static final int BYTE_ORDER_MAGIC
public static final java.lang.String MODEL_VERSION
protected java.util.Properties modelProps
protected Pool<float[]> meansPool
protected Pool<float[]> variancePool
protected Pool<float[][]> transitionsPool
protected GaussianWeights mixtureWeights
protected Pool<float[][]> meanTransformationMatrixPool
protected Pool<float[]> meanTransformationVectorPool
protected Pool<float[][]> varianceTransformationMatrixPool
protected Pool<float[]> varianceTransformationVectorPool
protected float[][] transformMatrix
protected LogMath logMath
protected java.util.logging.Logger logger
protected float distFloor
protected float mixtureWeightFloor
protected float varianceFloor
protected boolean useCDUnits
public Sphinx3Loader(java.net.URL location, UnitManager unitManager, float distFloor, float mixtureWeightFloor, float varianceFloor, int topGauNum, boolean useCDUnits)
public Sphinx3Loader(java.lang.String location, UnitManager unitManager, float distFloor, float mixtureWeightFloor, float varianceFloor, int topGauNum, boolean useCDUnits) throws java.net.MalformedURLException, java.lang.ClassNotFoundException
java.net.MalformedURLException
java.lang.ClassNotFoundException
public Sphinx3Loader()
protected void init(java.net.URL location, UnitManager unitManager, float distFloor, float mixtureWeightFloor, float varianceFloor, int topGauNum, boolean useCDUnits, java.util.logging.Logger logger)
public int getNumStates()
public int getNumStreams()
public int getNumGaussiansPerState()
public int[] getVectorLength()
public int[] getSenone2Ci()
public java.lang.String getLocation()
public boolean hasTiedMixtures()
public void newProperties(PropertySheet ps) throws PropertyException
Configurable
newProperties
in interface Configurable
ps
- a property sheet holding the new dataPropertyException
- if there is a problem with the properties.protected java.io.InputStream getDataStream(java.lang.String path) throws java.io.IOException, java.net.URISyntaxException
java.io.IOException
java.net.URISyntaxException
public void load() throws java.io.IOException
Loader
protected HMMManager getHmmManager()
protected Pool<float[][]> getMatrixPool()
protected GaussianWeights getMixtureWeightsPool()
protected void loadModelFiles() throws java.io.IOException, java.net.URISyntaxException
java.io.IOException
- IO went wrongjava.net.URISyntaxException
- uri was incorrectly specifiedpublic java.util.Map<java.lang.String,Unit> getContextIndependentUnits()
Loader
getContextIndependentUnits
in interface Loader
protected Pool<Senone> createSenonePool(float distFloor, float varianceFloor)
distFloor
- the lowest allowed scorevarianceFloor
- the lowest allowed variancepublic Pool<float[]> loadDensityFile(java.lang.String path, float floor) throws java.io.IOException, java.net.URISyntaxException
path
- the name of the datafloor
- the minimum density allowedjava.io.FileNotFoundException
- if a file cannot be foundjava.io.IOException
- if an error occurs while loading the datajava.net.URISyntaxException
- uri was incorrectly specifiedpublic java.io.DataInputStream readS3BinaryHeader(java.lang.String path, java.util.Properties props) throws java.io.IOException, java.net.URISyntaxException
path
- the name of the fileprops
- the propertiesjava.io.IOException
- on errorjava.net.URISyntaxException
- uri was incorrectly specifiedpublic int readInt(java.io.DataInputStream dis) throws java.io.IOException
dis
- the input streamjava.io.IOException
- on errorpublic float readFloat(java.io.DataInputStream dis) throws java.io.IOException
dis
- the input streamjava.io.IOException
- on errorpublic float[] readFloatArray(java.io.DataInputStream dis, int size) throws java.io.IOException
dis
- the stream to read data fromsize
- the number of floats to readjava.io.IOException
- if an exception occursprotected void loadHMMPool(boolean useCDUnits, java.io.InputStream inputStream) throws java.io.IOException
useCDUnits
- if true, loads also the context dependent unitsinputStream
- the open input stream to usejava.io.FileNotFoundException
- if a file cannot be foundjava.io.IOException
- if an error occurs while loading the dataprotected boolean sameSenoneSequence(int[] ssid1, int[] ssid2)
ssid1
- ids of first senone sequencessid2
- ids of second senone sequenceprotected SenoneSequence getSenoneSequence(int[] stateid)
stateid
- is the array of senone state idsprotected GaussianWeights loadMixtureWeights(java.lang.String path, float floor) throws java.io.IOException, java.net.URISyntaxException
path
- the path to the mixture weight filefloor
- the minimum mixture weight allowedjava.io.IOException
- if an error occurs while loading the datajava.net.URISyntaxException
- uri was incorrectly specifiedprotected Pool<float[][]> loadTransitionMatrices(java.lang.String path) throws java.io.IOException, java.net.URISyntaxException
path
- the path to the transitions matricesjava.io.IOException
- if an error occurs while loading the datajava.net.URISyntaxException
- uri was incorrectly specifiedprotected float[][] loadTransformMatrix(java.lang.String path) throws java.io.IOException
path
- the path to the transform matrixjava.io.FileNotFoundException
- if a file cannot be foundjava.io.IOException
- if an error occurs while loading the datapublic void clearGauScores()
public void setGauScoresQueueLength(int scoresQueueLen)
public Pool<float[]> getMeansPool()
Loader
getMeansPool
in interface Loader
public Pool<float[][]> getMeansTransformationMatrixPool()
Loader
getMeansTransformationMatrixPool
in interface Loader
public Pool<float[]> getMeansTransformationVectorPool()
Loader
getMeansTransformationVectorPool
in interface Loader
public Pool<float[]> getVariancePool()
Loader
getVariancePool
in interface Loader
public Pool<float[][]> getVarianceTransformationMatrixPool()
Loader
getVarianceTransformationMatrixPool
in interface Loader
public Pool<float[]> getVarianceTransformationVectorPool()
Loader
getVarianceTransformationVectorPool
in interface Loader
public GaussianWeights getMixtureWeights()
Loader
getMixtureWeights
in interface Loader
public Pool<float[][]> getTransitionMatrixPool()
Loader
getTransitionMatrixPool
in interface Loader
public float[][] getTransformMatrix()
Loader
getTransformMatrix
in interface Loader
public Pool<Senone> getSenonePool()
Loader
getSenonePool
in interface Loader
public int getLeftContextSize()
Loader
getLeftContextSize
in interface Loader
public int getRightContextSize()
Loader
getRightContextSize
in interface Loader
public HMMManager getHMMManager()
Loader
getHMMManager
in interface Loader
public void logInfo()
Loader
public java.util.Properties getProperties()
getProperties
in interface Loader
protected java.util.Properties loadModelProps(java.lang.String path) throws java.net.MalformedURLException, java.io.IOException, java.net.URISyntaxException
java.net.MalformedURLException
java.io.IOException
java.net.URISyntaxException
public void update(Transform transform, ClusteredDensityFileData clusters)
Loader