Android APIs
public class

TextToSpeech

extends Object
java.lang.Object
   ↳ android.speech.tts.TextToSpeech

Class Overview

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.

Summary

Nested Classes
class TextToSpeech.Engine Constants and parameter names for controlling text-to-speech. 
class TextToSpeech.EngineInfo Information about an installed text-to-speech engine. 
interface TextToSpeech.OnInitListener Interface definition of a callback to be invoked indicating the completion of the TextToSpeech engine initialization. 
interface TextToSpeech.OnUtteranceCompletedListener This interface was deprecated in API level 18. Use UtteranceProgressListener instead.  
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 ERROR_INVALID_REQUEST Denotes a failure caused by an invalid request.
int ERROR_NETWORK Denotes a failure caused by a network connectivity problems.
int ERROR_NETWORK_TIMEOUT Denotes a failure caused by network timeout.
int ERROR_NOT_INSTALLED_YET Denotes a failure caused by an unfinished download of the voice data.
int ERROR_OUTPUT Denotes a failure related to the output (audio device or a file).
int ERROR_SERVICE Denotes a failure of a TTS service.
int ERROR_SYNTHESIS Denotes a failure of a TTS engine to synthesize the given input.
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 STOPPED Denotes a stop requested by a client.
int SUCCESS Denotes a successful operation.
Public Constructors
TextToSpeech(Context context, TextToSpeech.OnInitListener listener)
The constructor for the TextToSpeech class, using the default TTS engine.
TextToSpeech(Context context, TextToSpeech.OnInitListener listener, String engine)
The constructor for the TextToSpeech class, using the given TTS engine.
Public Methods
int addEarcon(String earcon, String filename)
This method was deprecated in API level 21. As of API level 21, replaced by addEarcon(String, File).
int addEarcon(String earcon, File file)
Adds a mapping between a string of text and a sound file.
int addEarcon(String earcon, String packagename, int resourceId)
Adds a mapping between a string of text and a sound resource in a package.
int addSpeech(String text, String packagename, int resourceId)
Adds a mapping between a string of text and a sound resource in a package.
int addSpeech(String text, String filename)
Adds a mapping between a string of text and a sound file.
int addSpeech(CharSequence text, File file)
Adds a mapping between a CharSequence (may be spanned with TtsSpans and a sound file.
int addSpeech(CharSequence text, String packagename, int resourceId)
Adds a mapping between a CharSequence (may be spanned with TtsSpans) of text and a sound resource in a package.
boolean areDefaultsEnforced()
Checks whether the user's settings should override settings requested by the calling application.
Set<Locale> getAvailableLanguages()
Query the engine about the set of available languages.
String getDefaultEngine()
Gets the package name of the default speech synthesis engine.
Locale getDefaultLanguage()
This method was deprecated in API level 21. As of API level 21, use getDefaultVoice().getLocale() (getDefaultVoice())
Voice getDefaultVoice()
Returns a Voice instance that's the default voice for the default Text-to-speech language.
List<TextToSpeech.EngineInfo> getEngines()
Gets a list of all installed TTS engines.
Set<String> getFeatures(Locale locale)
This method was deprecated in API level 21. As of API level 21, please use voices. In order to query features of the voice, call getVoices() to retrieve the list of available voices and getFeatures() to retrieve the set of features.
Locale getLanguage()
This method was deprecated in API level 21. As of API level 21, please use getVoice().getLocale() (getVoice()).
static int getMaxSpeechInputLength()
Limit of length of input string passed to speak and synthesizeToFile.
Voice getVoice()
Returns a Voice instance describing the voice currently being used for synthesis requests sent to the TextToSpeech engine.
Set<Voice> getVoices()
Query the engine about the set of available voices.
int isLanguageAvailable(Locale loc)
Checks if the specified language as represented by the Locale is available and supported.
boolean isSpeaking()
Checks whether the TTS engine is busy speaking.
int playEarcon(String earcon, int queueMode, Bundle params, String utteranceId)
Plays the earcon using the specified queueing mode and parameters.
int playEarcon(String earcon, int queueMode, HashMap<StringString> params)
This method was deprecated in API level 21. As of API level 21, replaced by playEarcon(String, int, Bundle, String).
int playSilence(long durationInMs, int queueMode, HashMap<StringString> params)
This method was deprecated in API level 21. As of API level 21, replaced by playSilentUtterance(long, int, String).
int playSilentUtterance(long durationInMs, int queueMode, String utteranceId)
Plays silence for the specified amount of time using the specified queue mode.
int setAudioAttributes(AudioAttributes audioAttributes)
Sets the audio attributes to be used when speaking text or playing back a file.
int setEngineByPackageName(String enginePackageName)
This method was deprecated in API level 14. This doesn't inform callers when the TTS engine has been initialized. TextToSpeech(Context, OnInitListener, String) can be used with the appropriate engine name. Also, there is no guarantee that the engine specified will be loaded. If it isn't installed or disabled, the user / system wide defaults will apply.
int setLanguage(Locale loc)
Sets the text-to-speech language.
int setOnUtteranceCompletedListener(TextToSpeech.OnUtteranceCompletedListener listener)
This method was deprecated in API level 15. Use setOnUtteranceProgressListener(UtteranceProgressListener) instead.
int setOnUtteranceProgressListener(UtteranceProgressListener listener)
Sets the listener that will be notified of various events related to the synthesis of a given utterance.
int setPitch(float pitch)
Sets the speech pitch for the TextToSpeech engine.
int setSpeechRate(float speechRate)
Sets the speech rate.
int setVoice(Voice voice)
Sets the text-to-speech voice.
void shutdown()
Releases the resources used by the TextToSpeech engine.
int speak(CharSequence text, int queueMode, Bundle params, String utteranceId)
Speaks the text using the specified queuing strategy and speech parameters, the text may be spanned with TtsSpans.
int speak(String text, int queueMode, HashMap<StringString> params)
This method was deprecated in API level 21. As of API level 21, replaced by speak(CharSequence, int, Bundle, String).
int stop()
Interrupts the current utterance (whether played or rendered to file) and discards other utterances in the queue.
int synthesizeToFile(String text, HashMap<StringString> params, String filename)
This method was deprecated in API level 21. As of API level 21, replaced by synthesizeToFile(CharSequence, Bundle, File, String).
int synthesizeToFile(CharSequence text, Bundle params, File file, String utteranceId)
Synthesizes the given text to a file using the specified parameters.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String ACTION_TTS_QUEUE_PROCESSING_COMPLETED

Added in API level 4

Broadcast Action: The TextToSpeech synthesizer has completed processing of all the text in the speech queue. Note that this notifies callers when the engine has finished has processing text data. Audio playback might not have completed (or even started) at this point. If you wish to be notified when this happens, see TextToSpeech.OnUtteranceCompletedListener.

Constant Value: "android.speech.tts.TTS_QUEUE_PROCESSING_COMPLETED"

public static final int ERROR

Added in API level 4

Denotes a generic operation failure.

Constant Value: -1 (0xffffffff)

public static final int ERROR_INVALID_REQUEST

Added in API level 21

Denotes a failure caused by an invalid request.

Constant Value: -8 (0xfffffff8)

public static final int ERROR_NETWORK

Added in API level 21

Denotes a failure caused by a network connectivity problems.

Constant Value: -6 (0xfffffffa)

public static final int ERROR_NETWORK_TIMEOUT

Added in API level 21

Denotes a failure caused by network timeout.

Constant Value: -7 (0xfffffff9)

public static final int ERROR_NOT_INSTALLED_YET

Added in API level 21

Denotes a failure caused by an unfinished download of the voice data.

Constant Value: -9 (0xfffffff7)

public static final int ERROR_OUTPUT

Added in API level 21

Denotes a failure related to the output (audio device or a file).

Constant Value: -5 (0xfffffffb)

public static final int ERROR_SERVICE

Added in API level 21

Denotes a failure of a TTS service.

Constant Value: -4 (0xfffffffc)

public static final int ERROR_SYNTHESIS

Added in API level 21

Denotes a failure of a TTS engine to synthesize the given input.

Constant Value: -3 (0xfffffffd)

public static final int LANG_AVAILABLE

Added in API level 4

Denotes the language is available for the language by the locale, but not the country and variant.

Constant Value: 0 (0x00000000)

public static final int LANG_COUNTRY_AVAILABLE

Added in API level 4

Denotes the language is available for the language and country specified by the locale, but not the variant.

Constant Value: 1 (0x00000001)

public static final int LANG_COUNTRY_VAR_AVAILABLE

Added in API level 4

Denotes the language is available exactly as specified by the locale.

Constant Value: 2 (0x00000002)

public static final int LANG_MISSING_DATA

Added in API level 4

Denotes the language data is missing.

Constant Value: -1 (0xffffffff)

public static final int LANG_NOT_SUPPORTED

Added in API level 4

Denotes the language is not supported.

Constant Value: -2 (0xfffffffe)

public static final int QUEUE_ADD

Added in API level 4

Queue mode where the new entry is added at the end of the playback queue.

Constant Value: 1 (0x00000001)

public static final int QUEUE_FLUSH

Added in API level 4

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. Queues are flushed with respect to a given calling app. Entries in the queue from other callees are not discarded.

Constant Value: 0 (0x00000000)

public static final int STOPPED

Added in API level 21

Denotes a stop requested by a client. It's used only on the service side of the API, client should never expect to see this result code.

Constant Value: -2 (0xfffffffe)

public static final int SUCCESS

Added in API level 4

Denotes a successful operation.

Constant Value: 0 (0x00000000)

Public Constructors

public TextToSpeech (Context context, TextToSpeech.OnInitListener listener)

Added in API level 4

The constructor for the TextToSpeech class, using the default TTS engine. This will also initialize the associated TextToSpeech engine if it isn't already running.

Parameters
context The context this instance is running in.
listener The TextToSpeech.OnInitListener that will be called when the TextToSpeech engine has initialized. In a case of a failure the listener may be called immediately, before TextToSpeech instance is fully constructed.

public TextToSpeech (Context context, TextToSpeech.OnInitListener listener, String engine)

Added in API level 14

The constructor for the TextToSpeech class, using the given TTS engine. This will also initialize the associated TextToSpeech engine if it isn't already running.

Parameters
context The context this instance is running in.
listener The TextToSpeech.OnInitListener that will be called when the TextToSpeech engine has initialized. In a case of a failure the listener may be called immediately, before TextToSpeech instance is fully constructed.
engine Package name of the TTS engine to use.

Public Methods

public int addEarcon (String earcon, String filename)

Added in API level 4

This method was deprecated in API level 21.
As of API level 21, replaced by addEarcon(String, File).

Adds a mapping between a string of text and a sound file. Use this to add custom earcons.

Parameters
earcon The name of the earcon. Example: "[tick]"
filename The full path to the sound file (for example: "/sdcard/mysounds/tick.wav")
Returns

public int addEarcon (String earcon, File file)

Added in API level 21

Adds a mapping between a string of text and a sound file. Use this to add custom earcons.

Parameters
earcon The name of the earcon. Example: "[tick]"
file File object pointing to the sound file.
Returns

public int addEarcon (String earcon, String packagename, int resourceId)

Added in API level 4

Adds a mapping between a string of text and a sound resource in a package. Use this to add custom earcons.

Parameters
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.

<manifest xmlns:android="..." package="com.google.marvin.compass">

resourceId Example: R.raw.tick_snd
Returns

public int addSpeech (String text, String packagename, int resourceId)

Added in API level 4

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.

Parameters
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.

<manifest xmlns:android="..." package="com.google.marvin.compass">

resourceId Example: R.raw.south_south_east
Returns

public int addSpeech (String text, String filename)

Added in API level 4

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.

Parameters
text The string of text. Example: "south_south_east"
filename The full path to the sound file (for example: "/sdcard/mysounds/hello.wav")
Returns

public int addSpeech (CharSequence text, File file)

Added in API level 21

Adds a mapping between a CharSequence (may be spanned with TtsSpans 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.

Parameters
text The string of text. Example: "south_south_east"
file File object pointing to the sound file.
Returns

public int addSpeech (CharSequence text, String packagename, int resourceId)

Added in API level 21

Adds a mapping between a CharSequence (may be spanned with TtsSpans) 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.

Parameters
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.

<manifest xmlns:android="..." package="com.google.marvin.compass">

resourceId Example: R.raw.south_south_east
Returns

public boolean areDefaultsEnforced ()

Added in API level 8

Checks whether the user's settings should override settings requested by the calling application. As of the Ice cream sandwich release, user settings never forcibly override the app's settings.

public Set<Locale> getAvailableLanguages ()

Added in API level 21

Query the engine about the set of available languages.

public String getDefaultEngine ()

Added in API level 8

Gets the package name of the default speech synthesis engine.

Returns
  • Package name of the TTS engine that the user has chosen as their default.

public Locale getDefaultLanguage ()

Added in API level 18

This method was deprecated in API level 21.
As of API level 21, use getDefaultVoice().getLocale() (getDefaultVoice())

Returns a Locale instance describing the language currently being used as the default Text-to-speech language. The locale object returned by this method is NOT a valid one. It has identical form to the one in getLanguage(). Please refer to getLanguage() for more information.

Returns
  • language, country (if any) and variant (if any) used by the client stored in a Locale instance, or null on error.

public Voice getDefaultVoice ()

Added in API level 21

Returns a Voice instance that's the default voice for the default Text-to-speech language.

Returns
  • The default voice instance for the default language, or null if not set or on error.

public List<TextToSpeech.EngineInfo> getEngines ()

Added in API level 14

Gets a list of all installed TTS engines.

Returns
  • A list of engine info objects. The list can be empty, but never null.

public Set<String> getFeatures (Locale locale)

Added in API level 15

This method was deprecated in API level 21.
As of API level 21, please use voices. In order to query features of the voice, call getVoices() to retrieve the list of available voices and getFeatures() to retrieve the set of features.

Queries the engine for the set of features it supports for a given locale. Features can either be framework defined, e.g. KEY_FEATURE_NETWORK_SYNTHESIS or engine specific. Engine specific keys must be prefixed by the name of the engine they are intended for. These keys can be used as parameters to speak(String, int, java.util.HashMap) and synthesizeToFile(String, java.util.HashMap, String). Features values are strings and their values must meet restrictions described in their documentation.

Parameters
locale The locale to query features for.
Returns
  • Set instance. May return null on error.

public Locale getLanguage ()

Added in API level 4

This method was deprecated in API level 21.
As of API level 21, please use getVoice().getLocale() (getVoice()).

Returns a Locale instance describing the language currently being used for synthesis requests sent to the TextToSpeech engine. In Android 4.2 and before (API <= 17) this function returns the language that is currently being used by the TTS engine. That is the last language set by this or any other client by a setLanguage(Locale) call to the same engine. In Android versions after 4.2 this function returns the language that is currently being used for the synthesis requests sent from this client. That is the last language set by a setLanguage(Locale) call on this instance. If a voice is set (by setVoice(Voice)), getLanguage will return the language of the currently set voice. Please note that the Locale object returned by this method is NOT a valid Locale object. Its language field contains a three-letter ISO 639-2/T code (where a proper Locale would use a two-letter ISO 639-1 code), and the country field contains a three-letter ISO 3166 country code (where a proper Locale would use a two-letter ISO 3166-1 code).

Returns
  • language, country (if any) and variant (if any) used by the client stored in a Locale instance, or null on error.

public static int getMaxSpeechInputLength ()

Added in API level 18

Limit of length of input string passed to speak and synthesizeToFile.

public Voice getVoice ()

Added in API level 21

Returns a Voice instance describing the voice currently being used for synthesis requests sent to the TextToSpeech engine.

Returns
  • Voice instance used by the client, or null if not set or on error.

public Set<Voice> getVoices ()

Added in API level 21

Query the engine about the set of available voices. Each TTS Engine can expose multiple voices for each locale, each with a different set of features.

public int isLanguageAvailable (Locale loc)

Added in API level 4

Checks if the specified language as represented by the Locale is available and supported.

Parameters
loc The Locale describing the language to be used.
Returns

public boolean isSpeaking ()

Added in API level 4

Checks whether the TTS engine is busy speaking. Note that a speech item is considered complete once it's audio data has been sent to the audio mixer, or written to a file. There might be a finite lag between this point, and when the audio hardware completes playback.

Returns
  • true if the TTS engine is speaking.

public int playEarcon (String earcon, int queueMode, Bundle params, String utteranceId)

Added in API level 21

Plays the earcon using the specified queueing mode and parameters. The earcon must already have been added with addEarcon(String, String) or addEarcon(String, String, int). This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener(UtteranceProgressListener)) and using the KEY_PARAM_UTTERANCE_ID parameter.

Parameters
earcon The earcon that should be played
queueMode QUEUE_ADD or QUEUE_FLUSH.
params Parameters for the request. Can be null. Supported parameter names: KEY_PARAM_STREAM, Engine specific parameters may be passed in but the parameter keys must be prefixed by the name of the engine they are intended for. For example the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the engine named "com.svox.pico" if it is being used.
Returns

public int playEarcon (String earcon, int queueMode, HashMap<StringString> params)

Added in API level 4

This method was deprecated in API level 21.
As of API level 21, replaced by playEarcon(String, int, Bundle, String).

Plays the earcon using the specified queueing mode and parameters. The earcon must already have been added with addEarcon(String, String) or addEarcon(String, String, int). This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener(UtteranceProgressListener)) and using the KEY_PARAM_UTTERANCE_ID parameter.

Parameters
earcon The earcon that should be played
queueMode QUEUE_ADD or QUEUE_FLUSH.
params Parameters for the request. Can be null. Supported parameter names: KEY_PARAM_STREAM, KEY_PARAM_UTTERANCE_ID. Engine specific parameters may be passed in but the parameter keys must be prefixed by the name of the engine they are intended for. For example the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the engine named "com.svox.pico" if it is being used.
Returns

public int playSilence (long durationInMs, int queueMode, HashMap<StringString> params)

Added in API level 4

This method was deprecated in API level 21.
As of API level 21, replaced by playSilentUtterance(long, int, String).

Plays silence for the specified amount of time using the specified queue mode. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener(UtteranceProgressListener)) and using the KEY_PARAM_UTTERANCE_ID parameter.

Parameters
durationInMs The duration of the silence.
queueMode QUEUE_ADD or QUEUE_FLUSH.
params Parameters for the request. Can be null. Supported parameter names: KEY_PARAM_UTTERANCE_ID. Engine specific parameters may be passed in but the parameter keys must be prefixed by the name of the engine they are intended for. For example the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the engine named "com.svox.pico" if it is being used.
Returns

public int playSilentUtterance (long durationInMs, int queueMode, String utteranceId)

Added in API level 21

Plays silence for the specified amount of time using the specified queue mode. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener(UtteranceProgressListener)) and using the KEY_PARAM_UTTERANCE_ID parameter.

Parameters
durationInMs The duration of the silence.
queueMode QUEUE_ADD or QUEUE_FLUSH.
utteranceId An unique identifier for this request.
Returns
  • ERROR or SUCCESS of queuing the playSilentUtterance operation.

public int setAudioAttributes (AudioAttributes audioAttributes)

Added in API level 21

Sets the audio attributes to be used when speaking text or playing back a file.

Parameters
audioAttributes Valid AudioAttributes instance.
Returns

public int setEngineByPackageName (String enginePackageName)

Added in API level 8

This method was deprecated in API level 14.
This doesn't inform callers when the TTS engine has been initialized. TextToSpeech(Context, OnInitListener, String) can be used with the appropriate engine name. Also, there is no guarantee that the engine specified will be loaded. If it isn't installed or disabled, the user / system wide defaults will apply.

Sets the TTS engine to use.

Parameters
enginePackageName The package name for the synthesis engine (e.g. "com.svox.pico")
Returns

public int setLanguage (Locale loc)

Added in API level 4

Sets the text-to-speech language. The TTS 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. This method sets the current voice to the default one for the given Locale; getVoice() can be used to retrieve it.

Parameters
loc The locale describing the language to be used.
Returns

public int setOnUtteranceCompletedListener (TextToSpeech.OnUtteranceCompletedListener listener)

Added in API level 4

This method was deprecated in API level 15.
Use setOnUtteranceProgressListener(UtteranceProgressListener) instead.

Sets the listener that will be notified when synthesis of an utterance completes.

Parameters
listener The listener to use.
Returns

public int setOnUtteranceProgressListener (UtteranceProgressListener listener)

Added in API level 15

Sets the listener that will be notified of various events related to the synthesis of a given utterance. See UtteranceProgressListener and KEY_PARAM_UTTERANCE_ID.

Parameters
listener the listener to use.
Returns

public int setPitch (float pitch)

Added in API level 4

Sets the speech pitch for the TextToSpeech engine. This has no effect on any pre-recorded speech.

Parameters
pitch Speech pitch. 1.0 is the normal pitch, lower values lower the tone of the synthesized voice, greater values increase it.
Returns

public int setSpeechRate (float speechRate)

Added in API level 4

Sets the speech rate. This has no effect on any pre-recorded speech.

Parameters
speechRate Speech rate. 1.0 is the normal speech rate, lower values slow down the speech (0.5 is half the normal speech rate), greater values accelerate it (2.0 is twice the normal speech rate).
Returns

public int setVoice (Voice voice)

Added in API level 21

Sets the text-to-speech voice.

Parameters
voice One of objects returned by getVoices().
Returns
See Also

public void shutdown ()

Added in API level 4

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.

public int speak (CharSequence text, int queueMode, Bundle params, String utteranceId)

Added in API level 21

Speaks the text using the specified queuing strategy and speech parameters, the text may be spanned with TtsSpans. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener(UtteranceProgressListener)) and using the KEY_PARAM_UTTERANCE_ID parameter.

Parameters
text The string of text to be spoken. No longer than getMaxSpeechInputLength() characters.
queueMode The queuing strategy to use, QUEUE_ADD or QUEUE_FLUSH.
params Parameters for the request. Can be null. Supported parameter names: KEY_PARAM_STREAM, KEY_PARAM_VOLUME, KEY_PARAM_PAN. Engine specific parameters may be passed in but the parameter keys must be prefixed by the name of the engine they are intended for. For example the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the engine named "com.svox.pico" if it is being used.
utteranceId An unique identifier for this request.
Returns

public int speak (String text, int queueMode, HashMap<StringString> params)

Added in API level 4

This method was deprecated in API level 21.
As of API level 21, replaced by speak(CharSequence, int, Bundle, String).

Speaks the string using the specified queuing strategy and speech parameters. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener(UtteranceProgressListener)) and using the KEY_PARAM_UTTERANCE_ID parameter.

Parameters
text The string of text to be spoken. No longer than getMaxSpeechInputLength() characters.
queueMode The queuing strategy to use, QUEUE_ADD or QUEUE_FLUSH.
params Parameters for the request. Can be null. Supported parameter names: KEY_PARAM_STREAM, KEY_PARAM_UTTERANCE_ID, KEY_PARAM_VOLUME, KEY_PARAM_PAN. Engine specific parameters may be passed in but the parameter keys must be prefixed by the name of the engine they are intended for. For example the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the engine named "com.svox.pico" if it is being used.
Returns

public int stop ()

Added in API level 4

Interrupts the current utterance (whether played or rendered to file) and discards other utterances in the queue.

Returns

public int synthesizeToFile (String text, HashMap<StringString> params, String filename)

Added in API level 4

This method was deprecated in API level 21.
As of API level 21, replaced by synthesizeToFile(CharSequence, Bundle, File, String).

Synthesizes the given text to a file using the specified parameters. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener(UtteranceProgressListener)) and using the KEY_PARAM_UTTERANCE_ID parameter.

Parameters
text The text that should be synthesized. No longer than getMaxSpeechInputLength() characters.
params Parameters for the request. Can be null. Supported parameter names: KEY_PARAM_UTTERANCE_ID. Engine specific parameters may be passed in but the parameter keys must be prefixed by the name of the engine they are intended for. For example the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the engine named "com.svox.pico" if it is being used.
filename Absolute file filename to write the generated audio data to.It should be something like "/sdcard/myappsounds/mysound.wav".
Returns

public int synthesizeToFile (CharSequence text, Bundle params, File file, String utteranceId)

Added in API level 21

Synthesizes the given text to a file using the specified parameters. This method is asynchronous, i.e. the method just adds the request to the queue of TTS requests and then returns. The synthesis might not have finished (or even started!) at the time when this method returns. In order to reliably detect errors during synthesis, we recommend setting an utterance progress listener (see setOnUtteranceProgressListener(UtteranceProgressListener)).

Parameters
text The text that should be synthesized. No longer than getMaxSpeechInputLength() characters.
params Parameters for the request. Can be null. Engine specific parameters may be passed in but the parameter keys must be prefixed by the name of the engine they are intended for. For example the keys "com.svox.pico_foo" and "com.svox.pico:bar" will be passed to the engine named "com.svox.pico" if it is being used.
file File to write the generated audio data to.
utteranceId An unique identifier for this request.
Returns
  • ERROR or SUCCESS of queuing the synthesizeToFile operation.