java.lang.Object | |
↳ | android.speech.tts.TextToSpeech |
Synthesizes speech from text for immediate playback or to create a sound file.
A TextToSpeech instance can only be used to synthesize text once it has completed its
initialization. Implement the TextToSpeech.OnInitListener
to be
notified of the completion of the initialization.
When you are done using the TextToSpeech instance, call the shutdown()
method
to release the native resources used by the TextToSpeech engine.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
TextToSpeech.Engine | Internal constants for the TextToSpeech functionality | ||||||||||
TextToSpeech.OnInitListener | Interface definition of a callback to be invoked indicating the completion of the TextToSpeech engine initialization. | ||||||||||
TextToSpeech.OnUtteranceCompletedListener | Interface definition of a callback to be invoked indicating the TextToSpeech engine has completed synthesizing an utterance with an utterance ID set. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | ACTION_TTS_QUEUE_PROCESSING_COMPLETED | Broadcast Action: The TextToSpeech synthesizer has completed processing of all the text in the speech queue. | |||||||||
int | ERROR | Denotes a generic operation failure. | |||||||||
int | LANG_AVAILABLE | Denotes the language is available for the language by the locale, but not the country and variant. | |||||||||
int | LANG_COUNTRY_AVAILABLE | Denotes the language is available for the language and country specified by the locale, but not the variant. | |||||||||
int | LANG_COUNTRY_VAR_AVAILABLE | Denotes the language is available exactly as specified by the locale. | |||||||||
int | LANG_MISSING_DATA | Denotes the language data is missing. | |||||||||
int | LANG_NOT_SUPPORTED | Denotes the language is not supported. | |||||||||
int | QUEUE_ADD | Queue mode where the new entry is added at the end of the playback queue. | |||||||||
int | QUEUE_FLUSH | Queue mode where all entries in the playback queue (media to be played and text to be synthesized) are dropped and replaced by the new entry. | |||||||||
int | SUCCESS | Denotes a successful operation. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
The constructor for the TextToSpeech class.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a mapping between a string of text and a sound file.
| |||||||||||
Adds a mapping between a string of text and a sound resource in a
package.
| |||||||||||
Adds a mapping between a string of text and a sound resource in a
package.
| |||||||||||
Adds a mapping between a string of text and a sound file.
| |||||||||||
Returns whether or not the user is forcing their defaults to override the
Text-To-Speech settings set by applications.
| |||||||||||
Gets the packagename of the default speech synthesis engine.
| |||||||||||
Returns a Locale instance describing the language currently being used by the TextToSpeech
engine.
| |||||||||||
Checks if the specified language as represented by the Locale is available and supported.
| |||||||||||
Returns whether or not the TextToSpeech engine is busy speaking.
| |||||||||||
Plays the earcon using the specified queueing mode and parameters.
| |||||||||||
Plays silence for the specified amount of time using the specified
queue mode.
| |||||||||||
Sets the speech synthesis engine to be used by its packagename.
| |||||||||||
Sets the language for the TextToSpeech engine.
| |||||||||||
Sets the OnUtteranceCompletedListener that will fire when an utterance completes.
| |||||||||||
Sets the speech pitch for the TextToSpeech engine.
| |||||||||||
Sets the speech rate for the TextToSpeech engine.
| |||||||||||
Releases the resources used by the TextToSpeech engine.
| |||||||||||
Speaks the string using the specified queuing strategy and speech
parameters.
| |||||||||||
Interrupts the current utterance (whether played or rendered to file) and discards other
utterances in the queue.
| |||||||||||
Synthesizes the given text to a file using the specified parameters.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Broadcast Action: The TextToSpeech synthesizer has completed processing of all the text in the speech queue.
Denotes a generic operation failure.
Denotes the language is available for the language by the locale, but not the country and variant.
Denotes the language is available for the language and country specified by the locale, but not the variant.
Denotes the language is available exactly as specified by the locale.
Denotes the language data is missing.
Denotes the language is not supported.
Queue mode where the new entry is added at the end of the playback queue.
Queue mode where all entries in the playback queue (media to be played and text to be synthesized) are dropped and replaced by the new entry.
Denotes a successful operation.
The constructor for the TextToSpeech class. This will also initialize the associated TextToSpeech engine if it isn't already running.
context | The context this instance is running in. |
---|---|
listener | The TextToSpeech.OnInitListener that will be called when the
TextToSpeech engine has initialized.
|
Adds a mapping between a string of text and a sound file. Use this to add custom earcons.
earcon | The name of the earcon.
Example: "[tick]" |
---|---|
filename | The full path to the sound file (for example: "/sdcard/mysounds/tick.wav") |
Adds a mapping between a string of text and a sound resource in a package. Use this to add custom earcons.
earcon | The name of the earcon.
Example: "[tick]" |
---|---|
packagename | the package name of the application that contains the
resource. This can for instance be the package name of your own application.
Example: "com.google.marvin.compass" The package name can be found in the AndroidManifest.xml of the application containing the resource.
|
resourceId | Example: R.raw.tick_snd |
Adds a mapping between a string of text and a sound resource in a
package. After a call to this method, subsequent calls to
speak(String, int, HashMap)
will play the specified sound resource
if it is available, or synthesize the text it is missing.
text | The string of text. Example: "south_south_east" |
---|---|
packagename | Pass the packagename of the application that contains the
resource. If the resource is in your own application (this is
the most common case), then put the packagename of your
application here. Example: "com.google.marvin.compass" The packagename can be found in the AndroidManifest.xml of your application.
|
resourceId | Example: R.raw.south_south_east |
Adds a mapping between a string of text and a sound file. Using this, it
is possible to add custom pronounciations for a string of text.
After a call to this method, subsequent calls to speak(String, int, HashMap)
will play the specified sound resource if it is available, or synthesize the text it is
missing.
text | The string of text. Example: "south_south_east" |
---|---|
filename | The full path to the sound file (for example: "/sdcard/mysounds/hello.wav") |
Returns whether or not the user is forcing their defaults to override the Text-To-Speech settings set by applications.
Gets the packagename of the default speech synthesis engine.
Returns a Locale instance describing the language currently being used by the TextToSpeech engine.
Checks if the specified language as represented by the Locale is available and supported.
loc | The Locale describing the language to be used. |
---|
LANG_AVAILABLE
,
LANG_COUNTRY_AVAILABLE
, LANG_COUNTRY_VAR_AVAILABLE
,
LANG_MISSING_DATA
and LANG_NOT_SUPPORTED
.
Returns whether or not the TextToSpeech engine is busy speaking.
Plays the earcon using the specified queueing mode and parameters.
earcon | The earcon that should be played |
---|---|
queueMode | QUEUE_ADD or QUEUE_FLUSH . |
params | The list of parameters to be used. Can be null if no parameters are given.
They are specified using a (key, value) pair, where the key can be
KEY_PARAM_STREAM or
KEY_PARAM_UTTERANCE_ID . |
Plays silence for the specified amount of time using the specified queue mode.
durationInMs | A long that indicates how long the silence should last. |
---|---|
queueMode | QUEUE_ADD or QUEUE_FLUSH . |
params | The list of parameters to be used. Can be null if no parameters are given.
They are specified using a (key, value) pair, where the key can be
KEY_PARAM_UTTERANCE_ID . |
Sets the language for the TextToSpeech engine.
The TextToSpeech engine will try to use the closest match to the specified
language as represented by the Locale, but there is no guarantee that the exact same Locale
will be used. Use isLanguageAvailable(Locale)
to check the level of support
before choosing the language to use for the next utterances.
loc | The locale describing the language to be used. |
---|
LANG_AVAILABLE
,
LANG_COUNTRY_AVAILABLE
, LANG_COUNTRY_VAR_AVAILABLE
,
LANG_MISSING_DATA
and LANG_NOT_SUPPORTED
.
Sets the speech pitch for the TextToSpeech engine. This has no effect on any pre-recorded speech.
pitch | The pitch for the TextToSpeech engine. 1 is the normal pitch, lower values lower the tone of the synthesized voice, greater values increase it. |
---|
Sets the speech rate for the TextToSpeech engine. This has no effect on any pre-recorded speech.
speechRate | The speech rate for the TextToSpeech engine. 1 is the normal speed, lower values slow down the speech (0.5 is half the normal speech rate), greater values accelerate it (2 is twice the normal speech rate). |
---|
Releases the resources used by the TextToSpeech engine. It is good practice for instance to call this method in the onDestroy() method of an Activity so the TextToSpeech engine can be cleanly stopped.
Speaks the string using the specified queuing strategy and speech parameters.
text | The string of text to be spoken. |
---|---|
queueMode | The queuing strategy to use.
QUEUE_ADD or QUEUE_FLUSH . |
params | The list of parameters to be used. Can be null if no parameters are given.
They are specified using a (key, value) pair, where the key can be
KEY_PARAM_STREAM or
KEY_PARAM_UTTERANCE_ID . |
Synthesizes the given text to a file using the specified parameters.
text | The String of text that should be synthesized |
---|---|
params | The list of parameters to be used. Can be null if no parameters are given.
They are specified using a (key, value) pair, where the key can be
KEY_PARAM_UTTERANCE_ID . |
filename | The string that gives the full output filename; it should be something like "/sdcard/myappsounds/mysound.wav". |