Class Voice
- All Implemented Interfaces:
Dumpable,UtteranceProcessor
- Direct Known Subclasses:
CMUVoice
UtteranceProcessors. It is the main conduit to the FreeTTS
speech synthesizer. It can perform TTS on ASCII text,
a JSML document, an InputStream, or a
FreeTTSSpeakable, by invoking the method speak.
Before a Voice can perform TTS, it must have a
Lexicon, from which it gets the vocabulary, and
an AudioPlayer, to which it sends the synthesized output.
Example (using the CMUDiphoneVoice,
CMULexicon and JavaClipAudioPlayer):
Voice voice = new CMUDiphoneVoice();
// sets the Lexicon
voice.setLexicon(new CMULexicon());
// sets the AudioPlayer
voice.setAudioPlayer(new JavaClipAudioPlayer());
// loads the Voice
voice.allocate();
// start talking
voice.speak("I can talk forever without getting tired!");
A user can override the AudioPlayer to use by defining the "com.sun.speech.freetts.voice.defaultAudioPlayer" system property. The value of this property must be the name of a class that implements the AudioPlayer interface, and which also has a no-arg constructor.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConstant that describes the name of the unit database used by this voice.static final StringFeature name for the default AudioPlayer class to use.static final StringThe default class to use for the DEFAULT_AUDIO_PLAYER.static final StringFeature name for the join type string.static final StringFeature name for the silence phone string.static final StringPrefix for System property names. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFeatureProcessor(String name, FeatureProcessor fp) Adds a language/voice specific Feature Processor to the set of FeatureProcessors supported by this voice.voidallocate()Allocate this Voice.static OutputQueueCreates an output thread that will asynchronously output utterances that are generated by this voice (and other voices).voidShuts down the voice processing.voiddump(PrintWriter output, int pad, String title) Dumps the voice in textual form.voiddumpProcessors(PrintWriter output, int pad, String title) Dumps the voice processors.voidendBatch()Ends a batch of utterances.getAge()Get the age of this voice.protected abstract UtteranceProcessorReturns the AudioOutput processor to be used by this voice.Gets the audio player associated with this voice.Gets the default audio player for this voice.Get the description of this voice.Get the domain of this voice.floatGets the duration StretchgetFeatureProcessor(String name) Returns a language/voice specific Feature Processor.Returns the feature set associated with this voice.Get the gender of this voice.Gets the lexicon for this voice.Get the locale of this voice.getName()Get the name of this voice.Gets the organization which created this voice.Returns the output queue associated with this voice.getPhoneFeature(String phone, String featureName) Given a phoneme and a feature name, returns the feature.floatgetPitch()Retreives the baseline pitch.floatGets the pitch range.floatGets the pitch shift.floatgetRate()Gets the rate of speech.protected URLgetResource(String resource) Get a resource for this voice.Gets the title for this run.getStyle()Gets the voice style.abstract TokenizerReturns the tokenizer associated with this voice.Return the list of UtteranceProcessor instances.floatGets the volume.Gets the dumpfile for this voice.booleanGets the state of the detailedMetrics mode.booleanGets the state of the dumpRelations mode.booleanGets the state of the dumpUtterance mode.booleanisLoaded()Returns true if this voice is loaded.booleanGets the state of the metrics mode.voidload()Deprecated.protected abstract voidloader()Loads voice specific data.protected StringBufferprocessNode(Node n, StringBuffer buf) Adds text for just this node and returns any text that might be needed to undo the effects of this node after it is processed.voidProcesses the given Utterance by passing it to each UtteranceProcessor managed by this Voice.protected voidSet the age of this voice.voidsetAudioPlayer(AudioPlayer player) Sets the audio player associated with this voice.protected voidsetDescription(String description) Set the description of this voice.voidsetDetailedMetrics(boolean detailedMetrics) Sets the state of the detailedMetrics mode.protected voidSet the domain of this voice.voidsetDumpRelations(boolean dumpRelations) Sets the state of the dumpRelations mode.voidsetDumpUtterance(boolean dumpUtterance) Sets the state of the dumpUtterance mode.voidsetDurationStretch(float stretch) Sets the duration stretchprotected voidSet the gender of this voice.voidsetLexicon(Lexicon lexicon) Sets the lexicon to be used by this voice.protected voidsetLoaded(boolean loaded) Sets the loaded stateprotected voidSet the locale of this voice.voidsetMetrics(boolean metrics) Sets the metrics mode.protected voidSet the name of this voice.protected voidsetOrganization(String organization) Sets the organization which created this voice.voidsetOutputQueue(OutputQueue queue) Sets the output queue for this voice.voidsetPitch(float hertz) Sets the baseline pitch.voidsetPitchRange(float range) Sets the pitch range.voidsetPitchShift(float shift) Sets the pitch shiftvoidsetRate(float wpm) Sets the rate of speech.voidsetRunTitle(String runTitle) Sets the title for this run.voidSets the voice style.voidsetVolume(float vol) Sets the volume.voidsetWaveDumpFile(String waveDumpFile) Sets the dumpfile for this voice.booleanspeak(FreeTTSSpeakable speakable) Speak the given queue item.booleanspeak(InputStream inputStream) Speaks the input stream.booleanSpeaks the given text.booleanSpeaks the given document.voidStarts a batch of utterances.toString()Returns the name of this Voice.
-
Field Details
-
DATABASE_NAME
Constant that describes the name of the unit database used by this voice.- See Also:
-
PROP_PREFIX
Prefix for System property names.- See Also:
-
FEATURE_SILENCE
Feature name for the silence phone string.- See Also:
-
FEATURE_JOIN_TYPE
Feature name for the join type string.- See Also:
-
DEFAULT_AUDIO_PLAYER
Feature name for the default AudioPlayer class to use.- See Also:
-
DEFAULT_AUDIO_PLAYER_DEFAULT
The default class to use for the DEFAULT_AUDIO_PLAYER.- See Also:
-
-
Constructor Details
-
Voice
public Voice()Creates a new Voice. Utterances are sent to an output queue to be rendered as audio. Utterances are placed on the queue by an output thread. This queue is usually created via a call to 'createOutputThread,' which creates a thread that waits on the queue and sends the output to the audio player associated with this voice. If the queue is null, the output is rendered in the calling thread.- See Also:
-
Voice
public Voice(String name, Gender gender, Age age, String description, Locale locale, String domain, String organization) Creates a new Voice like above, except that it also stores the properties of the voice.- Parameters:
name- the name of the voicegender- the gender of the voiceage- the age of the voicedescription- a human-readable string providing a description that can be displayed for the users.locale- the locale of the voicedomain- the domain of this voice. For example,organization- the organization which created the voice "general", "time", or "weather".- See Also:
-
-
Method Details
-
speak
Speaks the given text.- Parameters:
text- the text to speak- Returns:
trueif the given text is spoken properly; otherwisefalse
-
speak
Speaks the given document.- Parameters:
doc- the JSML document to speak- Returns:
trueif the given document is spoken properly; otherwisefalse
-
speak
Speaks the input stream.- Parameters:
inputStream- the inputStream to speak- Returns:
trueif the given input stream is spoken properly; otherwisefalse
-
speak
Speak the given queue item. This is a synchronous method that does not return until the speakable is completely spoken or has been cancelled.- Parameters:
speakable- the item to speak- Returns:
trueif the utterance was spoken properly,falseotherwise
-
load
public void load()Deprecated.As of FreeTTS 1.2, replaced byallocate(). -
allocate
public void allocate()Allocate this Voice. It loads the lexicon and the audio output handler, and creates an audio output thread by invokingcreateOutputThread(), if one is not already created. It then calls theloader()method to load Voice-specific data, which include utterance processors. -
isLoaded
public boolean isLoaded()Returns true if this voice is loaded.- Returns:
trueif the voice is loaded; otherwisefalse
-
setLoaded
protected void setLoaded(boolean loaded) Sets the loaded state- Parameters:
loaded- the new loaded state otherwisefalse
-
processUtterance
Processes the given Utterance by passing it to each UtteranceProcessor managed by this Voice. The UtteranceProcessors are called in the order they were added to the Voice.- Specified by:
processUtterancein interfaceUtteranceProcessor- Parameters:
u- the Utterance to process- Throws:
ProcessException- if an exception occurred while performing operations on the Utterance
-
createOutputThread
Creates an output thread that will asynchronously output utterances that are generated by this voice (and other voices).- Returns:
- the queue where utterances should be placed.
-
getTokenizer
Returns the tokenizer associated with this voice.- Returns:
- the tokenizer
-
getUtteranceProcessors
Return the list of UtteranceProcessor instances. Applications should use this to obtain and modify the contents of the UtteranceProcessor list.- Returns:
- a List containing UtteranceProcessor instances
-
getFeatures
Returns the feature set associated with this voice.- Returns:
- the feature set.
-
startBatch
public void startBatch()Starts a batch of utterances. Utterances are sometimes batched in groups for timing purposes.- See Also:
-
endBatch
public void endBatch()Ends a batch of utterances.- See Also:
-
setOutputQueue
Sets the output queue for this voice. If no output queue is set for the voice when the voice is loaded, a queue and thread will be created when the voice is loaded. If the outputQueue is set by an external entity by calling setOutputQueue, the caller is responsible for shutting down the output thread. That is, if you call 'setOutputQueue' then you are responsible for shutting down the output thread on your own. This is necessary since the output queue may be shared by a number of voices.Utterances are placed on the queue to be output by an output thread. This queue is usually created via a call to 'createOutputThread' which creates a thread that waits on the queue and sends the output to the audio player associated with this voice. If the queue is null, the output is rendered in the calling thread.
- Parameters:
queue- the output queue
-
getOutputQueue
Returns the output queue associated with this voice.- Returns:
- the output queue associated with this voice
-
loader
Loads voice specific data. Subclasses of voice should implement this to perform class specific loading.- Throws:
IOException
-
processNode
Adds text for just this node and returns any text that might be needed to undo the effects of this node after it is processed.- Parameters:
n- the node to traverse in depth-first orderbuf- the buffer to append text to- Returns:
- a
Stringcontaining text to undo the effects of the node
-
dump
Dumps the voice in textual form. -
dumpProcessors
Dumps the voice processors.- Parameters:
output- where to send the formatted outputpad- the initial paddingtitle- the title to print when dumping out
-
getFeatureProcessor
Returns a language/voice specific Feature Processor.- Parameters:
name- the name of the processor- Returns:
- the processor associated with the name or null if none could be found
-
addFeatureProcessor
Adds a language/voice specific Feature Processor to the set of FeatureProcessors supported by this voice.- Parameters:
name- the name of the processorfp- the processor
-
isMetrics
public boolean isMetrics()Gets the state of the metrics mode.- Returns:
- true if metrics mode is on
-
setMetrics
public void setMetrics(boolean metrics) Sets the metrics mode.- Parameters:
metrics- true if metrics mode should be on
-
isDetailedMetrics
public boolean isDetailedMetrics()Gets the state of the detailedMetrics mode.- Returns:
- true if detailedMetrics mode is on
-
setDetailedMetrics
public void setDetailedMetrics(boolean detailedMetrics) Sets the state of the detailedMetrics mode.- Parameters:
detailedMetrics- true if detailedMetrics mode should be on
-
isDumpUtterance
public boolean isDumpUtterance()Gets the state of the dumpUtterance mode.- Returns:
- true if dumpUtterance mode is on
-
setDumpUtterance
public void setDumpUtterance(boolean dumpUtterance) Sets the state of the dumpUtterance mode.- Parameters:
dumpUtterance- true if dumpUtterance mode should be on
-
isDumpRelations
public boolean isDumpRelations()Gets the state of the dumpRelations mode.- Returns:
- true if dumpRelations mode is on
-
setDumpRelations
public void setDumpRelations(boolean dumpRelations) Sets the state of the dumpRelations mode.- Parameters:
dumpRelations- true if dumpRelations mode should be on
-
setRunTitle
Sets the title for this run.- Parameters:
runTitle- the title for the run
-
getRunTitle
Gets the title for this run.- Returns:
- the title for the run
-
getPhoneFeature
Given a phoneme and a feature name, returns the feature.- Parameters:
phone- the phoneme of interestfeatureName- the name of the feature of interest- Returns:
- the feature with the given name
-
deallocate
public void deallocate()Shuts down the voice processing. -
setPitch
public void setPitch(float hertz) Sets the baseline pitch.- Parameters:
hertz- the baseline pitch in hertz
-
getPitch
public float getPitch()Retreives the baseline pitch.- Returns:
- the baseline pitch in hertz
-
setPitchRange
public void setPitchRange(float range) Sets the pitch range.- Parameters:
range- the range in hertz
-
getPitchRange
public float getPitchRange()Gets the pitch range.- Returns:
- the range in hertz
-
setPitchShift
public void setPitchShift(float shift) Sets the pitch shift- Parameters:
shift- the pitch shift (1.0 is no shift)
-
getPitchShift
public float getPitchShift()Gets the pitch shift.- Returns:
- the pitch shift
-
setDurationStretch
public void setDurationStretch(float stretch) Sets the duration stretch- Parameters:
stretch- the duration stretch (1.0 is no stretch)
-
getDurationStretch
public float getDurationStretch()Gets the duration Stretch- Returns:
- the duration stretch
-
setRate
public void setRate(float wpm) Sets the rate of speech.- Parameters:
wpm- words per minute
-
getRate
public float getRate()Gets the rate of speech.- Returns:
- words per minute
-
setVolume
public void setVolume(float vol) Sets the volume.- Parameters:
vol- the volume (0 to 1.0)
-
getVolume
public float getVolume()Gets the volume.- Returns:
- the volume (0 to 1.0)
-
getLexicon
Gets the lexicon for this voice.- Returns:
- the lexicon (or null if there is no lexicon)
-
setLexicon
Sets the lexicon to be used by this voice.- Parameters:
lexicon- the lexicon to use
-
setWaveDumpFile
Sets the dumpfile for this voice.- Parameters:
waveDumpFile- the dumpfile
-
getWaveDumpFile
Gets the dumpfile for this voice.- Returns:
- the dumpfile
-
setAudioPlayer
Sets the audio player associated with this voice. The caller is responsible for closing this player.- Parameters:
player- the audio player
-
getDefaultAudioPlayer
Gets the default audio player for this voice. The return value will be non-null only if the DEFAULT_AUDIO_PLAYER system property has been set to the name of an AudioPlayer class, and that class is able to be instantiated via a no arg constructor. getAudioPlayer will automatically set the audio player for this voice to the default audio player if the audio player has not yet been set.- Returns:
- the default AudioPlayer
- Throws:
InstantiationException- See Also:
-
getAudioPlayer
Gets the audio player associated with this voice. If the audio player has not yet been set, the value will default to the return value of getDefaultAudioPlayer.- Returns:
- the audio player
- See Also:
-
getResource
Get a resource for this voice. By default, the voice is searched for in the package to which the voice class belongs. Subclasses are free to override this behaviour. -
setName
Set the name of this voice. [[[TODO: any standard format to the name?]]]- Parameters:
name- the name to assign this voice
-
getName
Get the name of this voice.- Returns:
- the name
-
toString
Returns the name of this Voice. -
setGender
Set the gender of this voice.- Parameters:
gender- the gender to assign
-
getGender
Get the gender of this voice.- Returns:
- the gender of this voice
-
setAge
Set the age of this voice.- Parameters:
age- the age to assign
-
getAge
Get the age of this voice.- Returns:
- the age of this voice
-
setDescription
Set the description of this voice.- Parameters:
description- the human readable description to assign
-
getDescription
Get the description of this voice.- Returns:
- the human readable description of this voice
-
setLocale
Set the locale of this voice.- Parameters:
locale- the locale of this voice.
-
getLocale
Get the locale of this voice.- Returns:
- the locale of this voice.
-
setDomain
Set the domain of this voice.- Parameters:
domain- the domain of this voice. For example, "general", "time", or "weather".
-
getDomain
Get the domain of this voice.- Returns:
- the domain of this voice. For example, "general", "time", or "weather".
-
setStyle
Sets the voice style. This parameter is designed for human interpretation. Values might include "business", "casual", "robotic", "breathy"- Parameters:
style- the stile of this voice.
-
getStyle
Gets the voice style. This parameter is designed for human interpretation. Values might include "business", "casual", "robotic", "breathy". -
setOrganization
Sets the organization which created this voice. For example "cmu", "sun", ...- Parameters:
organization- the name of the organization
-
getOrganization
Gets the organization which created this voice. For example "cmu", "sun", ...- Returns:
- the name of the organization
-
getAudioOutput
Returns the AudioOutput processor to be used by this voice. Derived voices typically override this to customize behaviors.- Returns:
- the audio output processor
- Throws:
IOException- if an IO error occurs while getting processor
-
allocate().