public abstract class Voice extends Object implements UtteranceProcessor, Dumpable
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.
VoiceManager
,
VoiceDirectory
Modifier and Type | Class and Description |
---|---|
private class |
Voice.FreeTTSSpeakableTokenizer
Tokenizes a FreeTTSSpeakable
|
Modifier and Type | Field and Description |
---|---|
private Age |
age |
private UtteranceProcessor |
audioOutput |
private AudioPlayer |
audioPlayer |
static String |
DATABASE_NAME
Constant that describes the name of the unit database used by
this voice.
|
static String |
DEFAULT_AUDIO_PLAYER
Feature name for the default AudioPlayer class to use.
|
static String |
DEFAULT_AUDIO_PLAYER_DEFAULT
The default class to use for the DEFAULT_AUDIO_PLAYER.
|
private AudioPlayer |
defaultAudioPlayer |
private String |
description |
private boolean |
detailedMetrics |
private String |
domain |
private boolean |
dumpRelations |
private boolean |
dumpUtterance |
private float |
durationStretch |
private boolean |
externalAudioPlayer |
private boolean |
externalOutputQueue |
static String |
FEATURE_JOIN_TYPE
Feature name for the join type string.
|
static String |
FEATURE_SILENCE
Feature name for the silence phone string.
|
private Map |
featureProcessors |
private FeatureSetImpl |
features |
private Gender |
gender |
private Lexicon |
lexicon |
private boolean |
loaded |
private Locale |
locale |
private static Logger |
LOGGER
Logger instance.
|
private boolean |
metrics |
private String |
name |
private float |
nominalRate |
private String |
organization |
private OutputQueue |
outputQueue |
private float |
pitch |
private float |
pitchShift |
static String |
PROP_PREFIX
Prefix for System property names.
|
private float |
range |
private BulkTimer |
runTimer |
private String |
runTitle |
private String |
style |
private BulkTimer |
threadTimer |
private List<UtteranceProcessor> |
utteranceProcessors |
private float |
volume |
private String |
waveDumpFile |
Constructor and Description |
---|
Voice()
Creates a new Voice.
|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
addFeatureProcessor(String name,
FeatureProcessor fp)
Adds a language/voice specific Feature Processor to the set of
FeatureProcessors supported by this voice.
|
void |
allocate()
Allocate this Voice.
|
static OutputQueue |
createOutputThread()
Creates an output thread that will asynchronously
output utterances that are generated by this voice (and other
voices).
|
void |
deallocate()
Shuts down the voice processing.
|
private String |
documentToString(Document dom)
Converts the document to a string (a placeholder for more
sophisticated logic to be done).
|
void |
dump(PrintWriter output,
int pad,
String title)
Dumps the voice in textual form.
|
private void |
dumpASCII(Utterance utterance)
Dumps the wave for the given utterance.
|
void |
dumpProcessors(PrintWriter output,
int pad,
String title)
Dumps the voice processors.
|
void |
endBatch()
Ends a batch of utterances.
|
Age |
getAge()
Get the age of this voice.
|
protected abstract UtteranceProcessor |
getAudioOutput()
Returns the AudioOutput processor to be used by this voice.
|
AudioPlayer |
getAudioPlayer()
Gets the audio player associated with this voice.
|
AudioPlayer |
getDefaultAudioPlayer()
Gets the default audio player for this voice.
|
String |
getDescription()
Get the description of this voice.
|
String |
getDomain()
Get the domain of this voice.
|
float |
getDurationStretch()
Gets the duration Stretch
|
FeatureProcessor |
getFeatureProcessor(String name)
Returns a language/voice specific Feature Processor.
|
FeatureSet |
getFeatures()
Returns the feature set associated with this voice.
|
Gender |
getGender()
Get the gender of this voice.
|
Lexicon |
getLexicon()
Gets the lexicon for this voice.
|
Locale |
getLocale()
Get the locale of this voice.
|
String |
getName()
Get the name of this voice.
|
String |
getOrganization()
Gets the organization which created this voice.
|
OutputQueue |
getOutputQueue()
Returns the output queue associated with this voice.
|
String |
getPhoneFeature(String phone,
String featureName)
Given a phoneme and a feature name, returns the feature.
|
float |
getPitch()
Retreives the baseline pitch.
|
float |
getPitchRange()
Gets the pitch range.
|
float |
getPitchShift()
Gets the pitch shift.
|
float |
getRate()
Gets the rate of speech.
|
protected URL |
getResource(String resource)
Get a resource for this voice.
|
String |
getRunTitle()
Gets the title for this run.
|
String |
getStyle()
Gets the voice style.
|
abstract Tokenizer |
getTokenizer()
Returns the tokenizer associated with this voice.
|
List<UtteranceProcessor> |
getUtteranceProcessors()
Return the list of UtteranceProcessor instances.
|
float |
getVolume()
Gets the volume.
|
String |
getWaveDumpFile()
Gets the dumpfile for this voice.
|
boolean |
isDetailedMetrics()
Gets the state of the detailedMetrics mode.
|
boolean |
isDumpRelations()
Gets the state of the dumpRelations mode.
|
boolean |
isDumpUtterance()
Gets the state of the dumpUtterance mode.
|
boolean |
isLoaded()
Returns true if this voice is loaded.
|
boolean |
isMetrics()
Gets the state of the metrics mode.
|
private void |
linearize(Node n,
StringBuffer buf)
Appends the text for this node to the given StringBuffer.
|
void |
load()
Deprecated.
As of FreeTTS 1.2, replaced by
allocate() . |
protected abstract void |
loader()
Loads voice specific data.
|
private boolean |
outputUtterance(Utterance utterance,
BulkTimer timer)
Sends the given utterance to the audio output processor
associated with this voice.
|
protected StringBuffer |
processNode(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.
|
void |
processUtterance(Utterance u)
Processes the given Utterance by passing it to each
UtteranceProcessor managed by this Voice.
|
private void |
runProcessor(UtteranceProcessor processor,
Utterance utterance,
BulkTimer timer)
Runs the given utterance processor.
|
protected void |
setAge(Age age)
Set the age of this voice.
|
void |
setAudioPlayer(AudioPlayer player)
Sets the audio player associated with this voice.
|
protected void |
setDescription(String description)
Set the description of this voice.
|
void |
setDetailedMetrics(boolean detailedMetrics)
Sets the state of the detailedMetrics mode.
|
protected void |
setDomain(String domain)
Set the domain of this voice.
|
void |
setDumpRelations(boolean dumpRelations)
Sets the state of the dumpRelations mode.
|
void |
setDumpUtterance(boolean dumpUtterance)
Sets the state of the dumpUtterance mode.
|
void |
setDurationStretch(float stretch)
Sets the duration stretch
|
protected void |
setGender(Gender gender)
Set the gender of this voice.
|
void |
setLexicon(Lexicon lexicon)
Sets the lexicon to be used by this voice.
|
protected void |
setLoaded(boolean loaded)
Sets the loaded state
|
protected void |
setLocale(Locale locale)
Set the locale of this voice.
|
void |
setMetrics(boolean metrics)
Sets the metrics mode.
|
protected void |
setName(String name)
Set the name of this voice.
|
protected void |
setOrganization(String organization)
Sets the organization which created this voice.
|
void |
setOutputQueue(OutputQueue queue)
Sets the output queue for this voice.
|
void |
setPitch(float hertz)
Sets the baseline pitch.
|
void |
setPitchRange(float range)
Sets the pitch range.
|
void |
setPitchShift(float shift)
Sets the pitch shift
|
void |
setRate(float wpm)
Sets the rate of speech.
|
void |
setRunTitle(String runTitle)
Sets the title for this run.
|
void |
setStyle(String style)
Sets the voice style.
|
void |
setVolume(float vol)
Sets the volume.
|
void |
setWaveDumpFile(String waveDumpFile)
Sets the dumpfile for this voice.
|
boolean |
speak(Document doc)
Speaks the given document.
|
boolean |
speak(FreeTTSSpeakable speakable)
Speak the given queue item.
|
boolean |
speak(InputStream inputStream)
Speaks the input stream.
|
boolean |
speak(String text)
Speaks the given text.
|
void |
startBatch()
Starts a batch of utterances.
|
private Iterator |
tokenize(FreeTTSSpeakable speakable)
tokenizes the given the queue item.
|
String |
toString()
Returns the name of this Voice.
|
public static final String DATABASE_NAME
private List<UtteranceProcessor> utteranceProcessors
private Map featureProcessors
private FeatureSetImpl features
private boolean metrics
private boolean detailedMetrics
private boolean dumpUtterance
private boolean dumpRelations
private AudioPlayer defaultAudioPlayer
private AudioPlayer audioPlayer
private UtteranceProcessor audioOutput
private OutputQueue outputQueue
private String waveDumpFile
private BulkTimer threadTimer
private boolean externalOutputQueue
private boolean externalAudioPlayer
private float nominalRate
private float pitch
private float range
private float pitchShift
private float volume
private float durationStretch
private boolean loaded
private String description
private String organization
public static final String PROP_PREFIX
public static final String FEATURE_SILENCE
public static final String FEATURE_JOIN_TYPE
public static final String DEFAULT_AUDIO_PLAYER
public static final String DEFAULT_AUDIO_PLAYER_DEFAULT
public Voice()
createOutputThread()
public Voice(String name, Gender gender, Age age, String description, Locale locale, String domain, String organization)
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".Voice()
public boolean speak(String text)
text
- the text to speaktrue
if the given text is spoken properly;
otherwise false
public boolean speak(Document doc)
doc
- the JSML document to speaktrue
if the given document is spoken properly;
otherwise false
public boolean speak(InputStream inputStream)
inputStream
- the inputStream to speaktrue
if the given input stream is spoken properly;
otherwise false
public boolean speak(FreeTTSSpeakable speakable)
speakable
- the item to speaktrue
if the utterance was spoken properly,
false
otherwisepublic void load()
allocate()
.public void allocate()
createOutputThread()
, if
one is not already created. It then calls the loader()
method to load Voice-specific data, which include utterance processors.public boolean isLoaded()
true
if the voice is loaded;
otherwise false
protected void setLoaded(boolean loaded)
loaded
- the new loaded state
otherwise false
public void processUtterance(Utterance u) throws ProcessException
processUtterance
in interface UtteranceProcessor
u
- the Utterance to processProcessException
- if an exception occurred while performing
operations on the Utteranceprivate void dumpASCII(Utterance utterance)
utterance
- the utterance of interestpublic static OutputQueue createOutputThread()
private boolean outputUtterance(Utterance utterance, BulkTimer timer)
utterance
- the utterance to be outputtimer
- the timer for gathering performance metricsprivate void runProcessor(UtteranceProcessor processor, Utterance utterance, BulkTimer timer) throws ProcessException
processor
- the processor to run. If the processor
is null, it is ignoredutterance
- the utterance to processProcessException
- if an exceptin occurs while processing
the utterancepublic abstract Tokenizer getTokenizer()
public List<UtteranceProcessor> getUtteranceProcessors()
public FeatureSet getFeatures()
public void startBatch()
endBatch()
public void endBatch()
startBatch()
public void setOutputQueue(OutputQueue queue)
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.
queue
- the output queuepublic OutputQueue getOutputQueue()
protected abstract void loader() throws IOException
IOException
private Iterator tokenize(FreeTTSSpeakable speakable)
private String documentToString(Document dom)
dom
- the jsml documentprivate void linearize(Node n, StringBuffer buf)
n
- the node to traverse in depth-first orderbuf
- the buffer to append text toprotected StringBuffer processNode(Node n, StringBuffer buf)
n
- the node to traverse in depth-first orderbuf
- the buffer to append text toString
containing text to undo the
effects of the nodepublic void dump(PrintWriter output, int pad, String title)
public void dumpProcessors(PrintWriter output, int pad, String title)
output
- where to send the formatted outputpad
- the initial paddingtitle
- the title to print when dumping outpublic FeatureProcessor getFeatureProcessor(String name)
name
- the name of the processorpublic void addFeatureProcessor(String name, FeatureProcessor fp)
name
- the name of the processorfp
- the processorpublic boolean isMetrics()
public void setMetrics(boolean metrics)
metrics
- true if metrics mode should be onpublic boolean isDetailedMetrics()
public void setDetailedMetrics(boolean detailedMetrics)
detailedMetrics
- true if detailedMetrics mode should be onpublic boolean isDumpUtterance()
public void setDumpUtterance(boolean dumpUtterance)
dumpUtterance
- true if dumpUtterance mode should be onpublic boolean isDumpRelations()
public void setDumpRelations(boolean dumpRelations)
dumpRelations
- true if dumpRelations mode should be onpublic void setRunTitle(String runTitle)
runTitle
- the title for the runpublic String getRunTitle()
public String getPhoneFeature(String phone, String featureName)
phone
- the phoneme of interestfeatureName
- the name of the feature of interestpublic void deallocate()
public void setPitch(float hertz)
hertz
- the baseline pitch in hertzpublic float getPitch()
public void setPitchRange(float range)
range
- the range in hertzpublic float getPitchRange()
public void setPitchShift(float shift)
shift
- the pitch shift (1.0 is no shift)public float getPitchShift()
public void setDurationStretch(float stretch)
stretch
- the duration stretch (1.0 is no stretch)public float getDurationStretch()
public void setRate(float wpm)
wpm
- words per minutepublic float getRate()
public void setVolume(float vol)
vol
- the volume (0 to 1.0)public float getVolume()
public Lexicon getLexicon()
public void setLexicon(Lexicon lexicon)
lexicon
- the lexicon to usepublic void setWaveDumpFile(String waveDumpFile)
waveDumpFile
- the dumpfilepublic String getWaveDumpFile()
public void setAudioPlayer(AudioPlayer player)
player
- the audio playerpublic AudioPlayer getDefaultAudioPlayer() throws InstantiationException
InstantiationException
DEFAULT_AUDIO_PLAYER
,
getAudioPlayer()
public AudioPlayer getAudioPlayer()
getDefaultAudioPlayer()
protected URL getResource(String resource)
protected void setName(String name)
name
- the name to assign this voiceprotected void setGender(Gender gender)
gender
- the gender to assignprotected void setAge(Age age)
age
- the age to assignprotected void setDescription(String description)
description
- the human readable description to assignpublic String getDescription()
protected void setLocale(Locale locale)
locale
- the locale of this voice.public Locale getLocale()
protected void setDomain(String domain)
domain
- the domain of this voice. For example,
"general", "time", or
"weather".public String getDomain()
public void setStyle(String style)
style
- the stile of this voice.public String getStyle()
protected void setOrganization(String organization)
organization
- the name of the organizationpublic String getOrganization()
protected abstract UtteranceProcessor getAudioOutput() throws IOException
IOException
- if an IO error occurs while getting
processorWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses