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

📄 baseengine.java

📁 It is the Speech recognition software. It is platform independent. To execute the source code,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @param listener the listener to add.     */    public void addEngineListener(EngineListener listener) {        synchronized (engineListeners) {            if (!engineListeners.contains(listener)) {                engineListeners.addElement(listener);            }        }    }    /**     * Removes an <code>EngineListener</code> from the list of     * <code>EngineListeners</code>.     *     * @param listener the listener to remove.     */    public void removeEngineListener(EngineListener listener) {        synchronized (engineListeners) {            engineListeners.removeElement(listener);        }    }        /**     * Utility function that generates an     * <code>ENGINE_ALLOCATED</code> event and posts it     * to the event queue.  Eventually     * <code>fireEngineAllocated</code> will be called     * by the <code>dispatchSpeechEvent</code> as a result of this     * action.     *     * @param oldState the old state of this <code>Engine</code>     * @param newState the new state of this <code>Engine</code>     *     * @see #fireEngineAllocated     * @see #dispatchSpeechEvent     */    protected void postEngineAllocated(long oldState, long newState) {        SpeechEventUtilities.postSpeechEvent(            this,            new EngineEvent(                this,                EngineEvent.ENGINE_ALLOCATED,                oldState, newState));    }        /**     * Utility function that sends an <code>ENGINE_ALLOCATED</code>     * event to all <code>EngineListeners</code> registered with this     * <code>Engine</code>.  Called by <code>dispatchSpeechEvent</code>.     *     * @param event the <code>ENGINE_ALLOCATED</code> event     *     * @see #postEngineAllocated     * @see #dispatchSpeechEvent     */    public void fireEngineAllocated(EngineEvent event) {	if (engineListeners == null) {	    return;	}        Enumeration E = engineListeners.elements();        while (E.hasMoreElements()) {            EngineListener el = (EngineListener) E.nextElement();            el.engineAllocated(event);        }    }        /**     * Utility function that generates an     * <code>ENGINE_ALLOCATING_RESOURCES</code> event and     * posts it to the event queue.  Eventually     * <code>fireEngineAllocatingResources</code>     * will be called by <code>dispatchSpeechEvent</code> as a     * result of this action.     *     * @param oldState the old state of this <code>Engine</code>     * @param newState the new state of this <code>Engine</code>     *     * @see #fireEngineAllocatingResources     * @see #dispatchSpeechEvent     */    protected void postEngineAllocatingResources(long oldState,                                                 long newState) {        SpeechEventUtilities.postSpeechEvent(            this,            new EngineEvent(                this,                EngineEvent.ENGINE_ALLOCATING_RESOURCES,                oldState, newState));    }        /**     * Utility function that sends an     * <code>ENGINE_ALLOCATING_RESOURCES</code> event to all     * <code>EngineListeners</code> registered with this     * <code>Engine</code>.  Called by <code>dispatchSpeechEvent</code>.     *     * @param event the <code>ENGINE_ALLOCATING_RESOURCES</code> event     *     * @see #postEngineAllocatingResources     * @see #dispatchSpeechEvent     */    public void fireEngineAllocatingResources(EngineEvent event) {	if (engineListeners == null) {	    return;	}        Enumeration E = engineListeners.elements();        while (E.hasMoreElements()) {            EngineListener el = (EngineListener) E.nextElement();            el.engineAllocatingResources(event);        }    }        /**     * Utility function that generates an     * <code>ENGINE_DEALLOCATED</code> event and posts it     * to the event queue.  Eventually     * <code>fireEngineDeallocated</code> will be called     * by <code>dispatchSpeechEvent</code> as a result of this action.     *     * @param oldState the old state of this <code>Engine</code>     * @param newState the new state of this <code>Engine</code>     *     * @see #fireEngineDeallocated     * @see #dispatchSpeechEvent     */    protected void postEngineDeallocated(long oldState, long newState) {        SpeechEventUtilities.postSpeechEvent(            this,            new EngineEvent(                this,                EngineEvent.ENGINE_DEALLOCATED,                oldState, newState));    }        /**     * Utility function that sends an     * <code>ENGINE_DEALLOCATED</code> event to all     * <code>EngineListeners</code> registered with this     * <code>Engine</code>.  Called by <code>dispatchSpeechEvent</code>.     *     * @param event the <code>ENGINE_DEALLOCATED</code> event     *     * @see #postEngineDeallocated     * @see #dispatchSpeechEvent     */    public void fireEngineDeallocated(EngineEvent event) {	if (engineListeners == null) {	    return;	}        Enumeration E = engineListeners.elements();        while (E.hasMoreElements()) {            EngineListener el = (EngineListener) E.nextElement();            el.engineDeallocated(event);        }    }        /**     * Utility function that generates     * <code>ENGINE_DEALLOCATING_RESOURCES</code> event and     * posts it to the event queue.  Eventually     * <code>fireEngineAllocatingResources</code> will be called     * by <code>dispatchSpeechEvent</code> as a result of this action.     *     * @param oldState the old state of this <code>Engine</code>     * @param newState the new state of this <code>Engine</code>     *     * @see #fireEngineDeallocatingResources     * @see #dispatchSpeechEvent     */    protected void postEngineDeallocatingResources(long oldState,                                                   long newState) {        SpeechEventUtilities.postSpeechEvent(            this,            new EngineEvent(                this,                EngineEvent.ENGINE_DEALLOCATING_RESOURCES,                oldState, newState));    }        /**     * Utility function that sends a     * <code>ENGINE_DEALLOCATING_RESOURCES</code> event to all     * <code>EngineListeners</code> registered with this     * <code>Engine</code>.  Called by <code>dispatchSpeechEvent</code>.     *     * @param event the <code>ENGINE_DEALLOCATING_RESOURCES</code> event     *     * @see #postEngineDeallocatingResources     * @see #dispatchSpeechEvent     */    public void fireEngineDeallocatingResources(EngineEvent event) {	if (engineListeners == null) {	    return;	}        Enumeration E = engineListeners.elements();        while (E.hasMoreElements()) {            EngineListener el = (EngineListener) E.nextElement();            el.engineDeallocatingResources(event);        }    }        /**     * Utility function that generates an     * <code>ENGINE_PAUSED</code> event and posts it     * to the event queue.  Eventually     * <code>fireEnginePaused</code> will be called     * by <code>dispatchSpeechEvent</code> as a result of this action.     *     * @param oldState the old state of this <code>Engine</code>     * @param newState the new state of this <code>Engine</code>     *     * @see #fireEnginePaused     * @see #dispatchSpeechEvent     */    protected void postEnginePaused(long oldState, long newState) {        SpeechEventUtilities.postSpeechEvent(            this,            new EngineEvent(                this,                EngineEvent.ENGINE_PAUSED,                oldState, newState));    }        /**     * Utility function that sends an <code>ENGINE_PAUSED</code> event     * to all     * <code>EngineListeners</code> registered with this     * <code>Engine</code>.  Called by <code>dispatchSpeechEvent</code>.     *     * @param event the <code>ENGINE_PAUSED</code> event     *     * @see #postEnginePaused     * @see #dispatchSpeechEvent     */    public void fireEnginePaused(EngineEvent event) {	if (engineListeners == null) {	    return;	}        Enumeration E = engineListeners.elements();        while (E.hasMoreElements()) {            EngineListener el = (EngineListener) E.nextElement();            el.enginePaused(event);        }    }    /**     * Utility function that generates an <code>ENGINE_RESUMED</code>     * event and posts it to the event queue.  Eventually     * <code>fireEngineResumed</code> will be called     * by <code>dispatchSpeechEvent</code> as a result of this action.     *     * @param oldState the old state of this <code>Engine</code>     * @param newState the new state of this <code>Engine</code>     *     * @see #fireEngineResumed     * @see #dispatchSpeechEvent     */    protected void postEngineResumed(long oldState, long newState) {        SpeechEventUtilities.postSpeechEvent(            this,            new EngineEvent(                this,                EngineEvent.ENGINE_RESUMED,                oldState, newState));    }        /**     * Utility function that sends an <code>ENGINE_RESUMED</code> event     * to all     * <code>EngineListeners</code> registered with this     * <code>Engine</code>.  Called by <code>dispatchSpeechEvent</code>.     *     * @param event the <code>ENGINE_RESUMED</code> event     *     * @see #postEngineResumed     * @see #dispatchSpeechEvent     */    public void fireEngineResumed(EngineEvent event) {	if (engineListeners == null) {	    return;	}        Enumeration E = engineListeners.elements();        while (E.hasMoreElements()) {            EngineListener el = (EngineListener) E.nextElement();            el.engineResumed(event);        }    }    /**     * Factory constructor for EngineProperties object.     *     * @return a <code>BaseEngineProperties</code> object specific to     *   a subclass.     */    abstract protected BaseEngineProperties createEngineProperties();    /**     * Convenience method that throws an <code>EngineStateError</code>     * if any of the bits in the passed state are set in the     * <code>state</code>.     *     * @param state the <code>Engine</code> state to check     *     * @throws EngineStateError if any of the bits in the passed state     *   are set in the <code>state</code>     */    protected void checkEngineState(long state) throws EngineStateError {        long currentState = getEngineState();        if ((currentState & state) != 0) {            throw new EngineStateError		("Invalid EngineState: expected=(" 		 + stateToString(state) + ") current state=("		 + stateToString(currentState) + ")");        }    }    /**     * Returns a <code>String</code> of the names of all the     * <code>Engine</code> states in the given <code>Engine</code>     * state.     *     * @param state the bitmask of states     *     * @return a <code>String</code> containing the names of all the     *   states set in <code>state</code>     */    protected String stateToString(long state) {	StringBuffer buf = new StringBuffer();        if ((state & Engine.DEALLOCATED) != 0)            buf.append(" DEALLOCATED ");        if ((state & Engine.ALLOCATING_RESOURCES) != 0)            buf.append(" ALLOCATING_RESOURCES ");        if ((state & Engine.ALLOCATED) != 0)            buf.append(" ALLOCATED ");        if ((state & Engine.DEALLOCATING_RESOURCES) != 0)            buf.append(" DEALLOCATING_RESOURCES ");        if ((state & Engine.PAUSED) != 0)            buf.append(" PAUSED ");        if ((state & Engine.RESUMED) != 0)            buf.append(" RESUMED ");        return buf.toString();    }        /**     * Dispatches a <code>SpeechEvent</code>.     * The dispatcher should notify all <code>EngineListeners</code>     * from this method.  The <code>SpeechEvent</code> was added     * via the various post methods of this class.     *     * @param event the <code>SpeechEvent</code> to dispatch     *     * @see #postEngineAllocatingResources     * @see #postEngineAllocated     * @see #postEngineDeallocatingResources     * @see #postEngineDeallocated     * @see #postEnginePaused     * @see #postEngineResumed     */    public void dispatchSpeechEvent(SpeechEvent event) {        switch (event.getId()) {            case EngineEvent.ENGINE_ALLOCATED:                fireEngineAllocated((EngineEvent) event);                break;            case EngineEvent.ENGINE_ALLOCATING_RESOURCES:                fireEngineAllocatingResources((EngineEvent) event);                break;            case EngineEvent.ENGINE_DEALLOCATED:                fireEngineDeallocated((EngineEvent) event);                break;            case EngineEvent.ENGINE_DEALLOCATING_RESOURCES:                fireEngineDeallocatingResources((EngineEvent) event);                break;            //case EngineEvent.ENGINE_ERROR:            //fireEngineError((EngineErrorEvent) event);            //break;            case EngineEvent.ENGINE_PAUSED:                fireEnginePaused((EngineEvent) event);                break;            case EngineEvent.ENGINE_RESUMED:                fireEngineResumed((EngineEvent) event);                break;        }    }    /**     * Returns the engine name and mode for debug purposes.     *     * @return the engine name and mode.     */    public String toString() {        return getEngineModeDesc().getEngineName() +             ":" + getEngineModeDesc().getModeName();    }}

⌨️ 快捷键说明

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