📄 basesynthesizer.java
字号:
/** * Cancels a specific object on the queue. * * @param source * object to be removed from the speech output queue * * @throws IllegalArgumentException * if the source object is not found in the speech output queue. * @throws EngineStateError * if this <code>Synthesizer</code> in the <code>DEALLOCATED</code> or * <code>DEALLOCATING_RESOURCES</code> states */ abstract public void cancel(Object source) throws IllegalArgumentException, EngineStateError; /** * Cancels all items on the output queue. * * @throws EngineStateError * if this <code>Synthesizer</code> in the <code>DEALLOCATED</code> or * <code>DEALLOCATING_RESOURCES</code> states */ abstract public void cancelAll() throws EngineStateError; /** * Returns the <code>SynthesizerProperties</code> object (a JavaBean). * The method returns exactly the same object as the * <code>getEngineProperties</code> method in the <code>Engine</code> * interface. However, with the <code>getSynthesizerProperties</code> * method, an application does not need to cast the return value. * * @return the <code>SynthesizerProperties</code> object for this * <code>Synthesizer</code> */ public SynthesizerProperties getSynthesizerProperties() { checkEngineState(DEALLOCATED | DEALLOCATING_RESOURCES); return (SynthesizerProperties) getEngineProperties(); } /** * Adds a <code>SpeakableListener</code> to this <code>Synthesizer</code>. * * @param listener the listener to add * * @see #removeSpeakableListener */ public void addSpeakableListener(SpeakableListener listener) { if (!speakableListeners.contains(listener)) { speakableListeners.addElement(listener); } } /** * Removes a <code>SpeakableListener</code> from this * <code>Synthesizer</code>. * * @param listener the listener to remove * * @see #addSpeakableListener */ public void removeSpeakableListener(SpeakableListener listener) { speakableListeners.removeElement(listener); } /** * Factory constructor for <code>EngineProperties</code> object. * Gets the default speaking voice from the * <code>SynthesizerModeDesc</code>. * Takes the default prosody values (pitch, range, volume, rate) * from the default voice. Override to set engine-specific defaults. * * @return a <code>BaseEngineProperties</code> object specific to * a subclass. */ protected BaseEngineProperties createEngineProperties() { SynthesizerModeDesc desc = (SynthesizerModeDesc)engineModeDesc; BaseVoice defaultVoice = (BaseVoice)(desc.getVoices()[0]); float defaultPitch = defaultVoice.defaultPitch; float defaultPitchRange = defaultVoice.defaultPitchRange; float defaultSpeakingRate = defaultVoice.defaultSpeakingRate; float defaultVolume = defaultVoice.defaultVolume; return new BaseSynthesizerProperties(defaultVoice, defaultPitch, defaultPitchRange, defaultSpeakingRate, defaultVolume); } /** * Factory method that creates a <code>BaseSynthesizerQueueItem</code>. * Override if the synthesizer specializes the * <code>BaseSynthesizerQueueItem</code> class. */ protected BaseSynthesizerQueueItem createQueueItem() { return new BaseSynthesizerQueueItem(); } /** * Returns the list of voices for this <code>Synthesizer</code>. * * @return the list of voices for this <code>Synthesizer</code>. */ protected VoiceList getVoiceList() { return voiceList; } /** * Utility function that generates <code>QUEUE_UPDATED</code> * event and posts it to the event queue. Eventually * <code>fireQueueUpdated</code> will be called * by <code>dispatchSpeechEvent</code> as a result of this action. * * @param topOfQueueChanged <code>true</code> if the top of the * queue has changed * @param oldState the old state of this <code>Synthesizer</code> * @param newState the new state of this <code>Synthesizer</code> * * @see #fireQueueUpdated * @see #dispatchSpeechEvent * */ public void postQueueUpdated(boolean topOfQueueChanged, long oldState, long newState) { SpeechEventUtilities.postSpeechEvent( this, new SynthesizerEvent(this, SynthesizerEvent.QUEUE_UPDATED, topOfQueueChanged, oldState, newState)); } /** * Utility function that sends a <code>QUEUE_UPDATED</code> * event to all <code>SynthesizerListeners</code>. * * @param event the <code>QUEUE_UPDATED</code> event * * @see #postQueueUpdated * @see #dispatchSpeechEvent */ public void fireQueueUpdated(SynthesizerEvent event) { if (engineListeners == null) { return; } Enumeration E = engineListeners.elements(); while (E.hasMoreElements()) { EngineListener el = (EngineListener) E.nextElement(); if (el instanceof SynthesizerListener) { SynthesizerListener sl = (SynthesizerListener)el; sl.queueUpdated(event); } } } /** * Utility function that generates <code>QUEUE_EMPTIED</code> * event and posts it to the event queue. Eventually * <code>fireQueueEmptied</code> will be called * by <code>dispatchSpeechEvent</code> as a result of this action. * * @param oldState the old state of this <code>Synthesizer</code> * @param newState the new state of this <code>Synthesizer</code> * * @see #fireQueueEmptied * @see #dispatchSpeechEvent */ public void postQueueEmptied(long oldState, long newState) { SpeechEventUtilities.postSpeechEvent( this, new SynthesizerEvent(this, SynthesizerEvent.QUEUE_EMPTIED, false, oldState, newState)); } /** * Utility function that sends a <code>QUEUE_EMPTIED</code> * event to all <code>SynthesizerListeners</code>. * * @param event the <code>QUEUE_EMPTIED</code> event * * @see #postQueueEmptied * @see #dispatchSpeechEvent */ public void fireQueueEmptied(SynthesizerEvent event) { if (engineListeners == null) { return; } Enumeration E = engineListeners.elements(); while (E.hasMoreElements()) { EngineListener el = (EngineListener) E.nextElement(); if (el instanceof SynthesizerListener) { SynthesizerListener sl = (SynthesizerListener)el; sl.queueEmptied(event); } } } /** * Dispatches a <code>SpeechEvent</code>. * The dispatcher should notify all <code>SynthesizerListeners</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 #postQueueUpdated * @see #postQueueEmptied */ public void dispatchSpeechEvent(SpeechEvent event) { switch (event.getId()) { case SynthesizerEvent.QUEUE_EMPTIED: fireQueueEmptied((SynthesizerEvent) event); break; case SynthesizerEvent.QUEUE_UPDATED: fireQueueUpdated((SynthesizerEvent) event); break; // Defer to BaseEngine to handle the rest. // default: super.dispatchSpeechEvent(event); break; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -