java.lang.Object | |
↳ | android.speech.tts.TextToSpeech |
Synthesizes speech from text for immediate playback or to create a sound file.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
TextToSpeech.Engine | Internal constants for the TTS functionality | ||||||||||
TextToSpeech.OnInitListener | Called when the TTS has initialized. | ||||||||||
TextToSpeech.OnUtteranceCompletedListener | Called when the TTS has completed saying something that has 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 by the current TTS engine. | |||||||||
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 TTS.
|
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 file.
| |||||||||||
Adds a mapping between a string of text and a sound resource in a
package.
| |||||||||||
Returns a Locale instance describing the language currently being used by the TTS engine.
| |||||||||||
Checks if the specified language as represented by the Locale is available.
| |||||||||||
Returns whether or not the TTS 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 language for the TTS engine.
| |||||||||||
Sets the OnUtteranceCompletedListener that will fire when an utterance completes.
| |||||||||||
Sets the speech pitch for the TTS engine.
| |||||||||||
Sets the speech rate for the TTS engine.
| |||||||||||
Shuts down the TTS.
| |||||||||||
Speaks the string using the specified queuing strategy and speech
parameters.
| |||||||||||
Stops speech from the TTS.
| |||||||||||
Synthesizes the given text to a file using the specified parameters.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
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 by the current TTS engine.
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 TTS.
context | The context |
---|---|
listener | The InitListener that will be called when the TTS has initialized successfully. |
Adds a mapping between a string of text and a sound resource in a package.
earcon | The name of the earcon
Example: "[tick]" |
---|---|
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.tick_snd |
Adds a mapping between a string of text and a sound file. Using this, it is possible to add custom pronounciations for text.
text | The string of text |
---|---|
filename | The full path to the sound file (for example: "/sdcard/mysounds/hello.wav") |
Adds a mapping between a string of text and a sound resource in a package.
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 |
Returns a Locale instance describing the language currently being used by the TTS engine.
Checks if the specified language as represented by the Locale is available.
loc | The Locale describing the language to be used. |
---|
Returns whether or not the TTS is busy speaking.
Sets the language for the TTS engine. Note that the language is not universally supported by all engines and will be treated as a hint. The TTS library will try to use the specified language as represented by the Locale, but there is no guarantee.
loc | The locale describing the language to be used. |
---|
Sets the speech pitch for the TTS engine. Note that the pitch is not universally supported by all engines and will be treated as a hint. The TTS library will try to use the specified pitch, but there is no guarantee. This has no effect on any pre-recorded speech.
pitch | The pitch for the TTS 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 TTS engine. Note that the speech rate is not universally supported by all engines and will be treated as a hint. The TTS library will try to use the specified speech rate, but there is no guarantee. This has no effect on any pre-recorded speech.
speechRate | The speech rate for the TTS 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). |
---|
Shuts down the TTS. It is good practice to call this in the onDestroy method of the Activity that is using the TTS so that the TTS is stopped cleanly.
Speaks the string using the specified queuing strategy and speech parameters. Note that the speech parameters are not universally supported by all engines and will be treated as a hint. The TTS library will try to fulfill these parameters as much as possible, but there is no guarantee that the voice used will have the properties specified.
text | The string of text to be spoken. |
---|---|
queueMode | The queuing strategy to use. See QUEUE_ADD and QUEUE_FLUSH. |
params | The hashmap of speech parameters to be used. |
Synthesizes the given text to a file using the specified parameters.
text | The String of text that should be synthesized |
---|---|
params | A hashmap of parameters. |
filename | The string that gives the full output filename; it should be something like "/sdcard/myappsounds/mysound.wav". |