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

📄 sphinx3saver.java

📁 It is the Speech recognition software. It is platform independent. To execute the source code,
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	    pw.print(tmat + "\t"); 	    SenoneSequence ss = hmm.getSenoneSequence();	    Senone[] senones = ss.getSenones();	    for (int j = 0; j < senones.length; j++) {		int index = senonePool.indexOf(senones[j]);		assert index >= 0 && index < numTiedState;		pw.print(index + "\t");	    }	    pw.println("N");	    if (logger.isLoggable(Level.FINE)) {		logger.fine("Saved " + unit);	    }	}	outputStream.close();    }    /**     * 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     */    private 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]);        }	// TODO: Is there any advantage in trying to pool these?	return new SenoneSequence(senones);    }    /**     * Saves the mixture weights     *     * @param pool the mixture weight pool     * @param path the path to the mixture weight file     * @param append is true, the file will be appended, useful if     * saving to a ZIP or JAR file     *     * @throws FileNotFoundException if a file cannot be found     * @throws IOException if an error occurs while saving the data     */    private void saveMixtureWeightsAscii(Pool pool, String path,					 boolean append)         throws FileNotFoundException, IOException {	logger.info("Saving mixture weights to: " );	logger.info(path);	int numStates;	int numStreams;	int numGaussiansPerState;        OutputStream outputStream = StreamFactory.getOutputStream(location, 							      path, append);	if (outputStream == null) {	    throw new IOException("Error trying to write file "                                        + location + path);	}	PrintWriter pw = new PrintWriter(outputStream, true);	pw.print("mixw ");	numStates = pool.getFeature(NUM_SENONES, -1);	pw.print(numStates + " ");	numStreams = pool.getFeature(NUM_STREAMS, -1);	pw.print(numStreams + " ");	numGaussiansPerState = pool.getFeature(NUM_GAUSSIANS_PER_STATE, -1); 	pw.println(numGaussiansPerState);	for (int i = 0; i < numStates; i++) {	    pw.print("mixw [" + i + " 0] ");	    float[] mixtureWeight = new float[numGaussiansPerState];	    float[] logMixtureWeight = (float[]) pool.get(i);	    convertFromLogMath(logMixtureWeight, mixtureWeight);	    float sum = 0.0f;	    for (int j = 0; j < numGaussiansPerState; j++) {		sum += mixtureWeight[j];	    }	    pw.println(sum);	    pw.print("\n\t");	    for (int j = 0; j < numGaussiansPerState; j++) {		pw.print(" " + mixtureWeight[j]);	    }	    pw.println();	}	outputStream.close();    }    /**     * Saves the mixture weights (Binary)     *     * @param pool the mixture weight pool     * @param path the path to the mixture weight file     * @param append is true, the file will be appended, useful if     * saving to a ZIP or JAR file     *     * @return a pool of mixture weights     *     * @throws FileNotFoundException if a file cannot be found     * @throws IOException if an error occurs while saving the data     */    private void saveMixtureWeightsBinary(Pool pool, String path, 					  boolean append)         throws FileNotFoundException, IOException {	logger.info("Saving mixture weights to: " );	logger.info(path);		int numStates;	int numStreams;	int numGaussiansPerState;        Properties props = new Properties();	int checkSum = 0;	props.setProperty("version", MIXW_FILE_VERSION);	if (doCheckSum) {	    props.setProperty("chksum0", checksum);	}        DataOutputStream dos = writeS3BinaryHeader(location, path, props, 						  append);	numStates = pool.getFeature(NUM_SENONES, -1);	numStreams = pool.getFeature(NUM_STREAMS, -1);	numGaussiansPerState = pool.getFeature(NUM_GAUSSIANS_PER_STATE, -1);        writeInt(dos, numStates);        writeInt(dos, numStreams);        writeInt(dos, numGaussiansPerState);        assert numStreams == 1;        int rawLength = numGaussiansPerState * numStates * numStreams;	writeInt(dos, rawLength);	for (int i = 0; i < numStates; i++) {	    float[] mixtureWeight = new float[numGaussiansPerState];	    float[] logMixtureWeight = (float[]) pool.get(i);	    convertFromLogMath(logMixtureWeight, mixtureWeight);	    writeFloatArray(dos, mixtureWeight);	}	if (doCheckSum) {	    assert doCheckSum = false: "Checksum not supported";	    // writeInt(dos, checkSum);	}        dos.close();    }    /**     * Saves the transition matrices     *     * @param pool the transition matrices pool     * @param path the path to the transitions matrices     * @param append is true, the file will be appended, useful if     * saving to a ZIP or JAR file     *     * @throws FileNotFoundException if a file cannot be found     * @throws IOException if an error occurs while saving the data     */    protected void saveTransitionMatricesAscii(Pool pool, String path, 					     boolean append)        throws FileNotFoundException, IOException {        OutputStream outputStream = StreamFactory.getOutputStream(location, 							      path, append);	if (outputStream == null) {	    throw new IOException("Error trying to write file "                                        + location + path);	}	PrintWriter pw = new PrintWriter(outputStream, true);        boolean sparseForm = acousticProperties.getBoolean	    (TiedStateAcousticModel.PROP_SPARSE_FORM, 	     TiedStateAcousticModel.PROP_SPARSE_FORM_DEFAULT);	logger.info("Saving transition matrices to: ");	logger.info( path);	int numMatrices = pool.size();	int numStates;	float[][] tmat;	assert numMatrices > 0;	tmat = (float [][])pool.get(0);	numStates = tmat[0].length;	pw.println("tmat " + numMatrices + " " + numStates);	for (int i = 0; i < numMatrices; i++) {	    pw.println("tmat [" + i + "]");	    tmat = (float [][])pool.get(i);	    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) {				pw.print("\t");			    }			    if (k == j  || k  == j + 1) {				pw.print((float)					 logMath.logToLinear(tmat[j][k]));			    }			} else {			    pw.print((float)logMath.logToLinear(tmat[j][k]));			}			if (numStates - 1 == k) {			    pw.println();			} else {			    pw.print(" ");			}		    }		    if (logger.isLoggable(Level.FINE)) {			logger.fine("tmat j " + j  + " k " 			    + k + " tm "+ tmat[j][k]);		    }		}	    }	}	outputStream.close();    }    /**     * Saves the transition matrices (Binary)     *     * @param pool the transition matrices pool     * @param path the path to the transitions matrices     * @param append is true, the file will be appended, useful if     * saving to a ZIP or JAR file     *     * @return a pool of transition matrices     *     * @throws FileNotFoundException if a file cannot be found     * @throws IOException if an error occurs while saving the data     */    protected void saveTransitionMatricesBinary(Pool pool, String path, 					      boolean append)        throws FileNotFoundException, IOException {        boolean sparseForm = acousticProperties.getBoolean	    (TiedStateAcousticModel.PROP_SPARSE_FORM, 	     TiedStateAcousticModel.PROP_SPARSE_FORM_DEFAULT);	logger.info("Saving transition matrices to: ");	logger.info( path);	int numMatrices;	int numStates;        int numRows;        int numValues;        Properties props = new Properties();	int checkSum = 0;	props.setProperty("version", TMAT_FILE_VERSION);	if (doCheckSum) {	    props.setProperty("chksum0", checksum);	}        DataOutputStream dos = writeS3BinaryHeader(location, path, props, 						   append);	numMatrices = pool.size();	assert numMatrices > 0;	writeInt(dos, numMatrices);	float[][] tmat = (float [][])pool.get(0);	numStates = tmat[0].length;	numRows = numStates - 1;	writeInt(dos, numRows);	writeInt(dos, numStates);        numValues = numStates * numRows * numMatrices;	writeInt(dos, numValues);	for (int i = 0; i < numMatrices; i++) {	    float[] logTmatRow;	    float[] tmatRow;	    tmat = (float [][])pool.get(i);	    // Last row should be all zeroes	    logTmatRow = tmat[numStates - 1];	    tmatRow = new float[logTmatRow.length];	    for (int j = 0; j < numStates; j++) {		assert tmatRow[j] == 0.0f;	    }	    for (int j = 0; j < numRows; j++) {		logTmatRow = tmat[j];		tmatRow = new float[logTmatRow.length];		convertFromLogMath(logTmatRow, tmatRow);                writeFloatArray(dos, tmatRow);	    }	}	if (doCheckSum) {	    assert doCheckSum = false: "Checksum not supported";	    // writeInt(dos, checkSum);	}	dos.close();    }    /**     * Returns the properties of the saved AcousticModel.     *     * @return the properties of the saved AcousticModel, or null if     *   it has no properties     */    public SphinxProperties getModelProperties() {        return acousticProperties;    }    /**     * Gets the pool of means for this saver     *     * @return the pool     */    public Pool getMeansPool() {	return meansPool;    }    /**     * Gets the pool of means transformation matrices for this saver     *     * @return the pool     */    public Pool getMeansTransformationMatrixPool() {	return meanTransformationMatrixPool;    }    /**     * Gets the pool of means transformation vectors for this saver     *     * @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 saver     *     * @return the pool     */    public Pool getVarianceTransformationVectorPool() {	return varianceTransformationVectorPool;    }    /*     * Gets the senone pool for this saver     *     * @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 saver     *     * @return the hmm Manager     */    public HMMManager getHMMManager() {	return hmmManager;    }    /**     * Log info about this saver     */    public void logInfo() {	logger.info("Sphinx3Saver");	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 + -