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

📄 baseresult.java

📁 It is the Speech recognition software. It is platform independent. To execute the source code,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * Copyright 1998-2003 Sun Microsystems, Inc. *  * See the file "license.terms" for information on usage and * redistribution of this file, and for a DISCLAIMER OF ALL  * WARRANTIES. *//** * Very simple implementation of JSAPI Result, FinalResult, * FinalRuleResult, and FinalDictationResult. * * Ignores many things like N-Best, partial-results, etc. * * @version 1.9 09/09/99 14:24:41 */package com.sun.speech.engine.recognition;import java.applet.AudioClip;import javax.speech.*;import javax.speech.recognition.*;import java.util.*;import com.sun.speech.engine.SpeechEventUtilities;import com.sun.speech.engine.SpeechEventDispatcher;public class BaseResult     implements Result, FinalResult, FinalRuleResult, FinalDictationResult,    java.io.Serializable, Cloneable, SpeechEventDispatcher{    private Vector resultListeners;    String theText[] = null;    int nTokens = 0;    transient Grammar grammar = null;    int state = Result.UNFINALIZED;     String[] tags = null;    String   ruleName = null;        /**     * Create an empty result.     */    public BaseResult() {        this(null);    }      /**     * Create an empty result.     */    public BaseResult(Grammar g) {        this(g,null);    }      /**     * Create a result with a result string      */    public BaseResult(Grammar G, String S) {        resultListeners = new Vector();        grammar = G;        tryTokens(G, S);    }    /**     * Copy a result. If the result to be copied is a BaseResult     * then clone it otherwise create a BaseResult and copy the     * tokens onto it.     */    static BaseResult copyResult(Result R) {        BaseResult copy = null;        if (R instanceof BaseResult) {            try {                copy = (BaseResult) ((BaseResult)R).clone();            } catch (CloneNotSupportedException e) {                System.out.println("ERROR: " + e);            }            return copy;        } else {            copy = new BaseResult(R.getGrammar());            copy.nTokens = R.numTokens();            copy.theText = new String[copy.nTokens];            for (int i = 0; i < R.numTokens(); i++) {                copy.theText[i] = R.getBestToken(i).getSpokenText();            }            return copy;        }    }    //////////////////////// Begin Result Methods//////////////////////    /**     * Return the current state of the Result object.     * From javax.speech.recognition.Result.     */    public int getResultState() {        return state;    }    /**      * Return the grammar that goes with this Result.     * From javax.speech.recognition.Result.     */    public Grammar getGrammar() {        return grammar;    }    /**      * Return the number of finalized tokens in the Result.     * From javax.speech.recognition.Result.     */    public int numTokens() {         return nTokens;     }    /**     * Return the best guess for the nth token.     * From javax.speech.recognition.Result.     */    public ResultToken getBestToken(int nth) throws IllegalArgumentException {         if ((nth < 0) || (nth > (nTokens-1))) {            throw new IllegalArgumentException("Token index out of range.");        }        return(new BaseResultToken(theText[nth]));    }        /**     * Return the best guess tokens for the Result.     * From javax.speech.recognition.Result.     */    public ResultToken[] getBestTokens() { 	ResultToken[] bt = new ResultToken[nTokens];	for (int i = 0; i < nTokens; i++) {	    bt[i] = getBestToken(i);	}	return bt;    }    /**     * NOT IMPLEMENTED YET.     * Return the current guess of the tokens following the unfinalized      * tokens.     * From javax.speech.recognition.Result.     */    public ResultToken[] getUnfinalizedTokens() {         return new ResultToken[0];     }    /**     * Add a ResultListener to this Result.     * From javax.speech.recognition.Result.     */    public void addResultListener(ResultListener listener) {         if (!resultListeners.contains(listener)) {            resultListeners.addElement(listener);        }    }    /**     * Remove a ResultListener from this Result.     * From javax.speech.recognition.Result.     */    public void removeResultListener(ResultListener listener) {        resultListeners.removeElement(listener);    }//////////////////////// End Result Methods////////////////////////////////////////////// Begin FinalResult Methods//////////////////////    /**     * Returns true if the Recognizer has training information available     * for this result.     * From javax.speech.recognition.FinalResult.     */    public boolean isTrainingInfoAvailable() throws ResultStateError {        checkResultState(UNFINALIZED);        return false;    }        /**     * Release training info for this FinalResult.     * From javax.speech.recognition.FinalResult.     */    public void releaseTrainingInfo() throws ResultStateError {        checkResultState(UNFINALIZED);    }        /**     * Inform the recognizer of a correction to one or more tokens in     * a FinalResult to the recognizer can re-train itself.     * From javax.speech.recognition.FinalResult.     */    public void tokenCorrection(String correctTokens[],                                 ResultToken fromToken,                                 ResultToken toToken,                                 int correctionType)         throws ResultStateError, IllegalArgumentException    {        checkResultState(UNFINALIZED);    }    /**     * Determine if audio is available for this FinalResult.     * From javax.speech.recognition.FinalResult.     */    public boolean isAudioAvailable() throws ResultStateError {         checkResultState(UNFINALIZED);        return false;     }    /**     * Release the audio for this FinalResult.     * From javax.speech.recognition.FinalResult.     */    public void releaseAudio() throws ResultStateError {         checkResultState(UNFINALIZED);    }    /**     * Get the audio for this FinalResult.     * From javax.speech.recognition.FinalResult.     */    public AudioClip getAudio() throws ResultStateError {         checkResultState(UNFINALIZED);        return null;     }    /**     * Get the audio for this FinalResult.     * From javax.speech.recognition.FinalResult.     */    public AudioClip getAudio(ResultToken from, ResultToken to)         throws ResultStateError    {         checkResultState(UNFINALIZED);        return null;     }//////////////////////// End FinalResult Methods////////////////////////////////////////////// Begin FinalRuleResult Methods//////////////////////    /**     * Return the number of guesses for this FinalRuleResult.     * From javax.speech.recognition.FinalRuleResult.     */    public int getNumberGuesses() throws ResultStateError {        checkResultState(UNFINALIZED);        if (!(grammar instanceof RuleGrammar)) {            throw new ResultStateError("Result is not a FinalRuleResult");        }        return 1;    }        /**     * Get the nBest token sequence for this FinalRuleResult.     * From javax.speech.recognition.FinalRuleResult.     */    public ResultToken[] getAlternativeTokens(int nBest)        throws ResultStateError         {        checkResultState(UNFINALIZED);        if (!(grammar instanceof RuleGrammar)) {            throw new ResultStateError("Result is not a FinalRuleResult");        }        if (nBest == 0) {            return getBestTokens();        }        //[[[WDW - throw InvalidArgumentException?]]]        return null;    }    /**     * Get the RuleGrammar matched by the nBest guess for this FinalRuleResult.     * From javax.speech.recognition.FinalRuleResult.     */    public RuleGrammar getRuleGrammar(int nBest)         throws ResultStateError    {        checkResultState(UNFINALIZED);        if (!(grammar instanceof RuleGrammar)) {            throw new ResultStateError("Result is not a FinalRuleResult");        }        if (nBest == 0) {            return (RuleGrammar) grammar;        }        //[[[WDW - throw InvalidArgumentException?]]]        return null;    }    /**     * Get the RuleGrammar matched by the nBest guess for this FinalRuleResult.     * From javax.speech.recognition.FinalRuleResult.     */    public String getRuleName(int nBest)        throws ResultStateError    {        checkResultState(UNFINALIZED);        if (!(grammar instanceof RuleGrammar)) {            throw new ResultStateError("Result is not a FinalRuleResult");        }        if (nBest == 0) {            return ruleName;        }        //[[[WDW - throw InvalidArgumentException?]]]        return null;    }    /**     * Return the list of tags matched by the best-guess token sequence.     * From javax.speech.recognition.FinalRuleResult.     */    public String[] getTags()        throws ResultStateError    {        checkResultState(UNFINALIZED);        if (!(grammar instanceof RuleGrammar)) {            throw new ResultStateError("Result is not a FinalRuleResult");        }        return tags;    }//////////////////////// End FinalRuleResult Methods

⌨️ 快捷键说明

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