⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sphinx3loader.java

📁 It is the Speech recognition software. It is platform independent. To execute the source code,
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            }            return true;        } else {            return false;        }    }    /**     * Gets the senone sequence representing the given senones     *      * @param stateid     *                is the array of senone state ids     *      * @return the senone sequence associated with the states     */    protected SenoneSequence getSenoneSequence(int[] stateid) {        Senone[] senones = new Senone[stateid.length];        for (int i = 0; i < stateid.length; i++) {            senones[i] = (Senone) senonePool.get(stateid[i]);        }        return new SenoneSequence(senones);    }    /**     * Loads the mixture weights     *      * @param path     *                the path to the mixture weight file     * @param floor     *                the minimum mixture weight allowed     *      * @return a pool of mixture weights     *      * @throws FileNotFoundException     *                 if a file cannot be found     * @throws IOException     *                 if an error occurs while loading the data     */    private Pool loadMixtureWeightsAscii(String path, float floor)            throws FileNotFoundException, IOException {        logger.fine("Loading mixture weights from: " + path);        int numStates;        int numStreams;        int numGaussiansPerState;        InputStream inputStream = StreamFactory.getInputStream(location, path);        Pool pool = new Pool(path);        ExtendedStreamTokenizer est = new ExtendedStreamTokenizer(inputStream,                '#', false);        est.expectString("mixw");        numStates = est.getInt("numStates");        numStreams = est.getInt("numStreams");        numGaussiansPerState = est.getInt("numGaussiansPerState");        pool.setFeature(NUM_SENONES, numStates);        pool.setFeature(NUM_STREAMS, numStreams);        pool.setFeature(NUM_GAUSSIANS_PER_STATE, numGaussiansPerState);        for (int i = 0; i < numStates; i++) {            est.expectString("mixw");            est.expectString("[" + i);            est.expectString("0]");            float total = est.getFloat("total");            float[] logMixtureWeight = new float[numGaussiansPerState];            for (int j = 0; j < numGaussiansPerState; j++) {                float val = est.getFloat("mixwVal");                if (val < floor) {                    val = floor;                }                logMixtureWeight[j] = val;            }            convertToLogMath(logMixtureWeight);            pool.put(i, logMixtureWeight);        }        est.close();        return pool;    }    /**     * Loads the mixture weights (Binary)     *      * @param path     *                the path to the mixture weight file     * @param floor     *                the minimum mixture weight allowed     *      * @return a pool of mixture weights     *      * @throws FileNotFoundException     *                 if a file cannot be found     * @throws IOException     *                 if an error occurs while loading the data     */     private Pool loadMixtureWeightsBinary(String path,                                    float floor)         throws FileNotFoundException, IOException {	logger.fine("Loading mixture weights from: " + path );	int numStates;	int numStreams;	int numGaussiansPerState;        int numValues;        Properties props = new Properties();        DataInputStream dis = readS3BinaryHeader(location, path, props);        String version = props.getProperty("version");        boolean doCheckSum;        if (version == null || !version.equals(MIXW_FILE_VERSION)) {            throw new IOException("Unsupported version in " + path);        }        String checksum = props.getProperty("chksum0");        doCheckSum =  (checksum != null && checksum.equals("yes"));    	Pool pool = new Pool(path);	numStates = readInt(dis);	numStreams = readInt(dis);	numGaussiansPerState = readInt(dis);	numValues = readInt(dis);        assert numValues == numStates * numStreams * numGaussiansPerState;        assert numStreams == 1;	pool.setFeature(NUM_SENONES, numStates);	pool.setFeature(NUM_STREAMS, numStreams);	pool.setFeature(NUM_GAUSSIANS_PER_STATE, numGaussiansPerState);	for (int i = 0; i < numStates; i++) {	    float[] logMixtureWeight = readFloatArray(dis,numGaussiansPerState);            normalize(logMixtureWeight);            floorData(logMixtureWeight, floor);            convertToLogMath(logMixtureWeight);	    pool.put(i, logMixtureWeight);	}        dis.close();	return pool;    }    /**          * Loads the transition matrices          *           * @param path          *                the path to the transitions matrices          *           * @return a pool of transition matrices          *           * @throws FileNotFoundException          *                 if a file cannot be found          * @throws IOException          *                 if an error occurs while loading the data          */    protected Pool loadTransitionMatricesAscii(String path)            throws FileNotFoundException, IOException {        InputStream inputStream = StreamFactory.getInputStream(location, path);	logger.fine("Loading transition matrices from: " + path);        int numMatrices;        int numStates;        Pool pool = new Pool(path);        ExtendedStreamTokenizer est = new ExtendedStreamTokenizer(inputStream,                '#', false);        est.expectString("tmat");        numMatrices = est.getInt("numMatrices");        numStates = est.getInt("numStates");	logger.fine("with " + numMatrices + " and " + numStates + 		    " states, in " + (sparseForm ? "sparse" : "dense") +		    " form");		// read in the matrices        for (int i = 0; i < numMatrices; i++) {            est.expectString("tmat");            est.expectString("[" + i + "]");            float[][] tmat = new float[numStates][numStates];            for (int j = 0; j < numStates; j++) {                for (int k = 0; k < numStates; k++) {                    // the last row is just zeros, so we just do                    // the first (numStates - 1) rows                    if (j < numStates - 1) {                        if (sparseForm) {                            if (k == j || k == j + 1) {                                tmat[j][k] = est.getFloat("tmat value");                            }                        } else {                            tmat[j][k] = est.getFloat("tmat value");                        }                    }                    tmat[j][k] = logMath.linearToLog(tmat[j][k]);                    if (logger.isLoggable(Level.FINE)) {                        logger.fine("tmat j " + j + " k " + k + " tm "                                + tmat[j][k]);                    }                }            }            pool.put(i, tmat);        }        est.close();        return pool;    }    /**     * Loads the transition matrices (Binary)     *      * @param path     *                the path to the transitions matrices     *      * @return a pool of transition matrices     *      * @throws FileNotFoundException     *                 if a file cannot be found     * @throws IOException     *                 if an error occurs while loading the data     */    protected Pool loadTransitionMatricesBinary(String path)        throws FileNotFoundException, IOException {        	logger.fine("Loading transition matrices from: " + path);	int numMatrices;	int numStates;        int numRows;        int numValues;        Properties props = new Properties();        DataInputStream dis = readS3BinaryHeader(location, path, props);        String version = props.getProperty("version");        boolean doCheckSum;        if (version == null || !version.equals(TMAT_FILE_VERSION)) {            throw new IOException("Unsupported version in " + path);        }        String checksum = props.getProperty("chksum0");        doCheckSum =  (checksum != null && checksum.equals("yes"));    	Pool pool = new Pool(path);	numMatrices = readInt(dis);	numRows = readInt(dis);	numStates = readInt(dis);	numValues = readInt(dis);        assert numValues == numStates * numRows * numMatrices;	for (int i = 0; i < numMatrices; i++) {	    float[][] tmat = new float[numStates][];            // last row should be zeros            tmat[numStates -1] = new float[numStates];            convertToLogMath(tmat[numStates-1]);	    for (int j = 0; j < numRows; j++) {                tmat[j] = readFloatArray(dis, numStates);                nonZeroFloor(tmat[j], 0f);                normalize(tmat[j]);                convertToLogMath(tmat[j]);	    }	    pool.put(i, tmat);	}	dis.close();	return pool;    }    /**          * Creates a pool with a single identity matrix in it.          *           * @param name          *                the name of the pool          *           * @return the pool with the matrix          */    private Pool createDummyMatrixPool(String name) {        Pool pool = new Pool(name);        float[][] matrix = new float[vectorLength][vectorLength];        logger.fine("creating dummy matrix pool " + name);        for (int i = 0; i < vectorLength; i++) {            for (int j = 0; j < vectorLength; j++) {                if (i == j) {                    matrix[i][j] = 1.0F;                } else {                    matrix[i][j] = 0.0F;                }            }        }        pool.put(0, matrix);        return pool;    }    /**     * Creates a pool with a single zero vector in it.     *      * @param name     *                the name of the pool     *      * @return the pool with the vector     */    private Pool createDummyVectorPool(String name) {        logger.fine("creating dummy vector pool " + name);        Pool pool = new Pool(name);        float[] vector = new float[vectorLength];        for (int i = 0; i < vectorLength; i++) {            vector[i] = 0.0f;        }        pool.put(0, vector);        return pool;    }    /**     * Gets the pool of means for this loader     *      * @return the pool     */    public Pool getMeansPool() {        return meansPool;    }    /**     * Gets the pool of means transformation matrices for this loader     *      * @return the pool     */    public Pool getMeansTransformationMatrixPool() {        return meanTransformationMatrixPool;    }    /**     * Gets the pool of means transformation vectors for this loader     *      * @return the pool     */    public Pool getMeansTransformationVectorPool() {        return meanTransformationVectorPool;    }    /*     * Gets the variance pool     *      * @return the pool     */    public Pool getVariancePool() {        return variancePool;    }    /**     * Gets the variance transformation matrix pool     *      * @return the pool     */    public Pool getVarianceTransformationMatrixPool() {        return varianceTransformationMatrixPool;    }    /**     * Gets the pool of variance transformation vectors for this loader     *      * @return the pool     */    public Pool getVarianceTransformationVectorPool() {        return varianceTransformationVectorPool;    }    /*     * Gets the mixture weight pool     *      * @return the pool     */    public Pool getMixtureWeightPool() {        return mixtureWeightsPool;    }    /*     * Gets the transition matrix pool     *      * @return the pool     */    public Pool getTransitionMatrixPool() {        return matrixPool;    }    /*     * Gets the senone pool for this loader     *      * @return the pool     */    public Pool getSenonePool() {        return senonePool;    }    /**     * Returns the size of the left context for context dependent units     *      * @return the left context size     */    public int getLeftContextSize() {        return CONTEXT_SIZE;    }    /**     * Returns the size of the right context for context dependent units     *      * @return the left context size     */    public int getRightContextSize() {        return CONTEXT_SIZE;    }    /**     * Returns the hmm manager associated with this loader     *      * @return the hmm Manager     */    public HMMManager getHMMManager() {        return hmmManager;    }    /**     * Log info about this loader     */    public void logInfo() {        logger.info("Sphinx3Loader");        meansPool.logInfo(logger);        variancePool.logInfo(logger);        matrixPool.logInfo(logger);        senonePool.logInfo(logger);        meanTransformationMatrixPool.logInfo(logger);        meanTransformationVectorPool.logInfo(logger);        varianceTransformationMatrixPool.logInfo(logger);        varianceTransformationVectorPool.logInfo(logger);        mixtureWeightsPool.logInfo(logger);        senonePool.logInfo(logger);        logger.info("Context Independent Unit Entries: "                + contextIndependentUnits.size());        hmmManager.logInfo(logger);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -