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

📄 basegrammar.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. */package com.sun.speech.engine.recognition;import java.util.*;import javax.speech.*;import javax.speech.recognition.*;import java.io.Serializable;import com.sun.speech.engine.SpeechEventUtilities;import com.sun.speech.engine.SpeechEventDispatcher;/** * Implementation of javax.speech.recognition.Grammar. * * @version 1.9 01/27/99 13:43:51 */public class BaseGrammar    implements Grammar, Serializable, SpeechEventDispatcher {    public    transient BaseRecognizer myRec;    protected transient Vector grammarListeners;    protected transient Vector resultListeners;    protected String    myName;        protected boolean grammarActive;  // only changed by commit and rec focus    protected boolean grammarEnabled;    protected boolean grammarChanged; // changed since last commit?    protected int     activationMode;        /**     * Create a new BaseGrammar     * @param R the BaseRecognizer for this Grammar.     * @param name the name of this Grammar.     */    public BaseGrammar(BaseRecognizer R, String name) {        grammarListeners = new Vector();        resultListeners = new Vector();        myRec = R;        myName = name;        grammarActive=false;        grammarEnabled=true;        grammarChanged=true;        activationMode=RECOGNIZER_FOCUS;    }//////////////////////// Begin Grammar Methods//////////////////////    /**     * Return a reference to the recognizer that owns this Grammar.     * From javax.speech.recognition.Grammar.     */    public Recognizer getRecognizer() {        return myRec;    }        /**     * Get the name of the Grammar.     * From javax.speech.recognition.Grammar.     */    public String getName() {        return myName;    }      /**     * Set the enabled property of the Grammar.     * From javax.speech.recognition.Grammar.     * @param enabled the new desired state of the enabled property.     */    public void setEnabled(boolean enabled) {        if (enabled != grammarEnabled) {	  //sjagrammarChanged=true;                    grammarEnabled = enabled;        }    }        /**     * Determine if this Grammar is enabled or not.     * From javax.speech.recognition.Grammar.     */    public boolean isEnabled() {        return grammarEnabled;    }    /**     * Set the activation mode of this Grammar.     * From javax.speech.recognition.Grammar     *      * @param mode the new activation mode.     */    public void setActivationMode(int mode) throws IllegalArgumentException {        if ((mode != GLOBAL)            && (mode != RECOGNIZER_MODAL)            && (mode != RECOGNIZER_FOCUS)) {            throw new IllegalArgumentException("Invalid ActivationMode");        } else if (mode != activationMode) {	  //sjagrammarChanged=true;                    activationMode = mode;        }    }        /**     * Get the activation mode of this Grammar.     * From javax.speech.recognition.Grammar     */    public int getActivationMode() {        return activationMode;    }        /**     * Determine if the Grammar is active or not.  This is a combination     * of the enabled state and activation conditions of the Grammar.     * From javax.speech.recognition.Grammar.     */    public boolean isActive() {        return myRec.isActive(this);    }        /**     * Add a new GrammarListener to the listener list if it is not      * already in the list.     * From javax.speech.recognition.Grammar.     * @param listener the listener to add.     */    public void addGrammarListener(GrammarListener listener) {        if (!grammarListeners.contains(listener)) {            grammarListeners.addElement(listener);        }    }    /**     * Remove a GrammarListener from the listener list.     * From javax.speech.recognition.Grammar.     * @param listener the listener to remove.     */    public void removeGrammarListener(GrammarListener listener) {        grammarListeners.removeElement(listener);    }    /**     * Add a new ResultListener to the listener list if it is not      * already in the list.     * From javax.speech.recognition.Grammar.     * @param listener the listener to add.     */    public void addResultListener(ResultListener listener) {        if (!resultListeners.contains(listener)) {            resultListeners.addElement(listener);        }    }    /**     * Remove a ResultListener from the listener list.     * From javax.speech.recognition.Grammar.     * @param listener the listener to remove.     */    public void removeResultListener(ResultListener listener) {        resultListeners.removeElement(listener);    }//////////////////////// End Grammar Methods////////////////////////////////////////////// Begin utility methods for sending GrammarEvents//////////////////////    /**     * Utility function to generate GRAMMAR_ACTIVATED event and post it     * to the event queue.  Eventually fireGrammarActivated will be called     * by dispatchSpeechEvent as a result of this action.     */    public void postGrammarActivated() {        SpeechEventUtilities.postSpeechEvent(            this,            new GrammarEvent(this, GrammarEvent.GRAMMAR_ACTIVATED));    }    /**     * Utility function to send a GRAMMAR_ACTIVATED event to all result     * listeners.       */    protected void fireGrammarActivated(GrammarEvent event) {	if (grammarListeners == null) {	    return;        }        Enumeration E = grammarListeners.elements();        while (E.hasMoreElements()) {            GrammarListener gl = (GrammarListener) E.nextElement();            gl.grammarActivated(event);        }    }    /**     * Utility function to generate GRAMMAR_CHANGES_COMMITTED event and post it     * to the event queue.  Eventually fireGrammarChangesCommitted will be     * called by dispatchSpeechEvent as a result of this action.     */    public void postGrammarChangesCommitted() {        SpeechEventUtilities.postSpeechEvent(            this,            new GrammarEvent(this, GrammarEvent.GRAMMAR_CHANGES_COMMITTED));    }    /**     * Utility function to send a GRAMMAR_CHANGES_COMMITTED event to all result     * listeners.       */    protected void fireGrammarChangesCommitted(GrammarEvent event) {	if (grammarListeners == null) {	    return;        }        Enumeration E = grammarListeners.elements();        while (E.hasMoreElements()) {            GrammarListener gl = (GrammarListener) E.nextElement();            gl.grammarChangesCommitted(event);        }    }    /**     * Utility function to generate GRAMMAR_DEACTIVATED event and post it     * to the event queue.  Eventually fireGrammarDeactivated will be called     * by dispatchSpeechEvent as a result of this action.     */    public void postGrammarDeactivated() {        SpeechEventUtilities.postSpeechEvent(            this,            new GrammarEvent(this, GrammarEvent.GRAMMAR_DEACTIVATED));    }    /**     * Utility function to send a GRAMMAR_DEACTIVATED event to all result     * listeners.       */    protected void fireGrammarDeactivated(GrammarEvent event) {	if (grammarListeners == null) {	    return;        }        Enumeration E = grammarListeners.elements();        while (E.hasMoreElements()) {            GrammarListener gl = (GrammarListener) E.nextElement();            gl.grammarDeactivated(event);        }

⌨️ 快捷键说明

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