Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/speech/tts/TextToSpeech#nestedclasses) \| [Constants](https://developer.android.com/reference/android/speech/tts/TextToSpeech#constants) \| [Ctors](https://developer.android.com/reference/android/speech/tts/TextToSpeech#pubctors) \| [Methods](https://developer.android.com/reference/android/speech/tts/TextToSpeech#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/speech/tts/TextToSpeech#inhmethods)

# TextToSpeech

*** ** * ** ***


`
public


class
TextToSpeech
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.speech.tts.TextToSpeech |

<br />

*** ** * ** ***

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 `https://developer.android.com/reference/android/speech/tts/TextToSpeech.OnInitListener` to be
notified of the completion of the initialization.  

When you are done using the TextToSpeech instance, call the `https://developer.android.com/reference/android/speech/tts/TextToSpeech#shutdown()` method
to release the native resources used by the TextToSpeech engine.

Apps targeting Android 11 that use text-to-speech should declare `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#INTENT_ACTION_TTS_SERVICE` in the `queries` elements of their
manifest:

```
<queries>
  ...
 <intent>
     <action android:name="android.intent.action.TTS_SERVICE" />
 </intent>
</queries>
```

<br />

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine` Constants and parameter names for controlling text-to-speech. |
| ` class` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech.EngineInfo` Information about an installed text-to-speech engine. |
| ` interface` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech.OnInitListener` Interface definition of a callback to be invoked indicating the completion of the TextToSpeech engine initialization. |
| ` interface` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech.OnUtteranceCompletedListener` *This interface was deprecated in API level 18. Use `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener` instead.* |

| ### Constants ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ACTION_TTS_QUEUE_PROCESSING_COMPLETED` Broadcast Action: The TextToSpeech synthesizer has completed processing of all the text in the speech queue. |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` Denotes a generic operation failure. |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR_INVALID_REQUEST` Denotes a failure caused by an invalid request. |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR_NETWORK` Denotes a failure caused by a network connectivity problems. |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR_NETWORK_TIMEOUT` Denotes a failure caused by network timeout. |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR_NOT_INSTALLED_YET` Denotes a failure caused by an unfinished download of the voice data. |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR_OUTPUT` Denotes a failure related to the output (audio device or a file). |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR_SERVICE` Denotes a failure of a TTS service. |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR_SYNTHESIS` Denotes a failure of a TTS engine to synthesize the given input. |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#LANG_AVAILABLE` Denotes the language is available for the language by the locale, but not the country and variant. |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#LANG_COUNTRY_AVAILABLE` Denotes the language is available for the language and country specified by the locale, but not the variant. |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#LANG_COUNTRY_VAR_AVAILABLE` Denotes the language is available exactly as specified by the locale. |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#LANG_MISSING_DATA` Denotes the language data is missing. |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#LANG_NOT_SUPPORTED` Denotes the language is not supported. |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#QUEUE_ADD` Queue mode where the new entry is added at the end of the playback queue. |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#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` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#STOPPED` Denotes a stop requested by a client. |
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS` Denotes a successful operation. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#TextToSpeech(android.content.Context,%20android.speech.tts.TextToSpeech.OnInitListener)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/speech/tts/TextToSpeech.OnInitListener listener) ` The constructor for the TextToSpeech class, using the default TTS engine. |
| ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#TextToSpeech(android.content.Context,%20android.speech.tts.TextToSpeech.OnInitListener,%20java.lang.String)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/speech/tts/TextToSpeech.OnInitListener listener, https://developer.android.com/reference/java/lang/String engine) ` The constructor for the TextToSpeech class, using the given TTS engine. |

| ### Public methods ||
|---|---|
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#addEarcon(java.lang.String,%20java.lang.String,%20int)(https://developer.android.com/reference/java/lang/String earcon, https://developer.android.com/reference/java/lang/String packagename, int resourceId) ` Adds a mapping between a string of text and a sound resource in a package. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#addEarcon(java.lang.String,%20java.lang.String)(https://developer.android.com/reference/java/lang/String earcon, https://developer.android.com/reference/java/lang/String filename) ` *This method was deprecated in API level 21. As of API level 21, replaced by `https://developer.android.com/reference/android/speech/tts/TextToSpeech#addEarcon(java.lang.String,%20java.io.File)`.* |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#addEarcon(java.lang.String,%20java.io.File)(https://developer.android.com/reference/java/lang/String earcon, https://developer.android.com/reference/java/io/File file) ` Adds a mapping between a string of text and a sound file. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#addEarcon(java.lang.String,%20android.net.Uri)(https://developer.android.com/reference/java/lang/String earcon, https://developer.android.com/reference/android/net/Uri uri) ` Adds a mapping between a string of text and a sound file. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#addSpeech(java.lang.CharSequence,%20java.io.File)(https://developer.android.com/reference/java/lang/CharSequence text, https://developer.android.com/reference/java/io/File file) ` Adds a mapping between a CharSequence (may be spanned with TtsSpans) and a sound file. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#addSpeech(java.lang.String,%20java.lang.String,%20int)(https://developer.android.com/reference/java/lang/String text, https://developer.android.com/reference/java/lang/String packagename, int resourceId) ` Adds a mapping between a string of text and a sound resource in a package. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#addSpeech(java.lang.CharSequence,%20java.lang.String,%20int)(https://developer.android.com/reference/java/lang/CharSequence text, https://developer.android.com/reference/java/lang/String packagename, int resourceId) ` Adds a mapping between a CharSequence (may be spanned with TtsSpans) of text and a sound resource in a package. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#addSpeech(java.lang.String,%20java.lang.String)(https://developer.android.com/reference/java/lang/String text, https://developer.android.com/reference/java/lang/String filename) ` Adds a mapping between a string of text and a sound file. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#addSpeech(java.lang.CharSequence,%20android.net.Uri)(https://developer.android.com/reference/java/lang/CharSequence text, https://developer.android.com/reference/android/net/Uri uri) ` Adds a mapping between a CharSequence (may be spanned with TtsSpans) and a sound file. |
| ` boolean` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#areDefaultsEnforced()() ` Checks whether the user's settings should override settings requested by the calling application. |
| ` https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/util/Locale>` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#getAvailableLanguages()() ` Query the engine about the set of available languages. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#getDefaultEngine()() ` Gets the package name of the default speech synthesis engine. |
| ` https://developer.android.com/reference/java/util/Locale` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#getDefaultLanguage()() ` *This method was deprecated in API level 21. As of API level 21, use `getDefaultVoice().getLocale()` (`https://developer.android.com/reference/android/speech/tts/TextToSpeech#getDefaultVoice()`)* |
| ` https://developer.android.com/reference/android/speech/tts/Voice` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#getDefaultVoice()() ` Returns a Voice instance that's the default voice for the default Text-to-speech language. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/speech/tts/TextToSpeech.EngineInfo>` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#getEngines()() ` Gets a list of all installed TTS engines. |
| ` https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/lang/String>` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#getFeatures(java.util.Locale)(https://developer.android.com/reference/java/util/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 `https://developer.android.com/reference/android/speech/tts/TextToSpeech#getVoices()` to retrieve the list of available voices and `https://developer.android.com/reference/android/speech/tts/Voice#getFeatures()` to retrieve the set of features.* |
| ` https://developer.android.com/reference/java/util/Locale` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#getLanguage()() ` *This method was deprecated in API level 21. As of API level 21, please use `getVoice().getLocale()` (`https://developer.android.com/reference/android/speech/tts/TextToSpeech#getVoice()`).* |
| ` static int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#getMaxSpeechInputLength()() ` Limit of length of input string passed to speak and synthesizeToFile. |
| ` https://developer.android.com/reference/android/speech/tts/Voice` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#getVoice()() ` Returns a Voice instance describing the voice currently being used for synthesis requests sent to the TextToSpeech engine. |
| ` https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/android/speech/tts/Voice>` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#getVoices()() ` Query the engine about the set of available voices. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#isLanguageAvailable(java.util.Locale)(https://developer.android.com/reference/java/util/Locale loc) ` Checks if the specified language as represented by the Locale is available and supported. |
| ` boolean` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#isSpeaking()() ` Checks whether the TTS engine is busy speaking. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#playEarcon(java.lang.String,%20int,%20java.util.HashMap<java.lang.String,java.lang.String>)(https://developer.android.com/reference/java/lang/String earcon, int queueMode, https://developer.android.com/reference/java/util/HashMap<https://developer.android.com/reference/java/lang/String, https://developer.android.com/reference/java/lang/String> params) ` *This method was deprecated in API level 21. As of API level 21, replaced by `https://developer.android.com/reference/android/speech/tts/TextToSpeech#playEarcon(java.lang.String,%20int,%20android.os.Bundle,%20java.lang.String)`.* |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#playEarcon(java.lang.String,%20int,%20android.os.Bundle,%20java.lang.String)(https://developer.android.com/reference/java/lang/String earcon, int queueMode, https://developer.android.com/reference/android/os/Bundle params, https://developer.android.com/reference/java/lang/String utteranceId) ` Plays the earcon using the specified queueing mode and parameters. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#playSilence(long,%20int,%20java.util.HashMap<java.lang.String,java.lang.String>)(long durationInMs, int queueMode, https://developer.android.com/reference/java/util/HashMap<https://developer.android.com/reference/java/lang/String, https://developer.android.com/reference/java/lang/String> params) ` *This method was deprecated in API level 21. As of API level 21, replaced by `https://developer.android.com/reference/android/speech/tts/TextToSpeech#playSilentUtterance(long,%20int,%20java.lang.String)`.* |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#playSilentUtterance(long,%20int,%20java.lang.String)(long durationInMs, int queueMode, https://developer.android.com/reference/java/lang/String utteranceId) ` Plays silence for the specified amount of time using the specified queue mode. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#setAudioAttributes(android.media.AudioAttributes)(https://developer.android.com/reference/android/media/AudioAttributes audioAttributes) ` Sets the audio attributes to be used when speaking text or playing back a file. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#setEngineByPackageName(java.lang.String)(https://developer.android.com/reference/java/lang/String enginePackageName) ` *This method was deprecated in API level 15. This doesn't inform callers when the TTS engine has been initialized. `https://developer.android.com/reference/android/speech/tts/TextToSpeech#TextToSpeech(android.content.Context,%20android.speech.tts.TextToSpeech.OnInitListener,%20java.lang.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` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#setLanguage(java.util.Locale)(https://developer.android.com/reference/java/util/Locale loc) ` Sets the text-to-speech language. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#setOnUtteranceCompletedListener(android.speech.tts.TextToSpeech.OnUtteranceCompletedListener)(https://developer.android.com/reference/android/speech/tts/TextToSpeech.OnUtteranceCompletedListener listener) ` *This method was deprecated in API level 15. Use `https://developer.android.com/reference/android/speech/tts/TextToSpeech#setOnUtteranceProgressListener(android.speech.tts.UtteranceProgressListener)` instead.* |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#setOnUtteranceProgressListener(android.speech.tts.UtteranceProgressListener)(https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener listener) ` Sets the listener that will be notified of various events related to the synthesis of a given utterance. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#setPitch(float)(float pitch) ` Sets the speech pitch for the TextToSpeech engine. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#setSpeechRate(float)(float speechRate) ` Sets the speech rate. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#setVoice(android.speech.tts.Voice)(https://developer.android.com/reference/android/speech/tts/Voice voice) ` Sets the text-to-speech voice. |
| ` void` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#shutdown()() ` Releases the resources used by the TextToSpeech engine. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#speak(java.lang.CharSequence,%20int,%20android.os.Bundle,%20java.lang.String)(https://developer.android.com/reference/java/lang/CharSequence text, int queueMode, https://developer.android.com/reference/android/os/Bundle params, https://developer.android.com/reference/java/lang/String utteranceId) ` Speaks the text using the specified queuing strategy and speech parameters, the text may be spanned with TtsSpans. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#speak(java.lang.String,%20int,%20java.util.HashMap<java.lang.String,java.lang.String>)(https://developer.android.com/reference/java/lang/String text, int queueMode, https://developer.android.com/reference/java/util/HashMap<https://developer.android.com/reference/java/lang/String, https://developer.android.com/reference/java/lang/String> params) ` *This method was deprecated in API level 21. As of API level 21, replaced by `https://developer.android.com/reference/android/speech/tts/TextToSpeech#speak(java.lang.CharSequence,%20int,%20android.os.Bundle,%20java.lang.String)`.* |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#stop()() ` Interrupts the current utterance (whether played or rendered to file) and discards other utterances in the queue. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#synthesizeToFile(java.lang.CharSequence,%20android.os.Bundle,%20android.os.ParcelFileDescriptor,%20java.lang.String)(https://developer.android.com/reference/java/lang/CharSequence text, https://developer.android.com/reference/android/os/Bundle params, https://developer.android.com/reference/android/os/ParcelFileDescriptor fileDescriptor, https://developer.android.com/reference/java/lang/String utteranceId) ` Synthesizes the given text to a ParcelFileDescriptor using the specified parameters. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#synthesizeToFile(java.lang.CharSequence,%20android.os.Bundle,%20java.io.File,%20java.lang.String)(https://developer.android.com/reference/java/lang/CharSequence text, https://developer.android.com/reference/android/os/Bundle params, https://developer.android.com/reference/java/io/File file, https://developer.android.com/reference/java/lang/String utteranceId) ` Synthesizes the given text to a file using the specified parameters. |
| ` int` | ` https://developer.android.com/reference/android/speech/tts/TextToSpeech#synthesizeToFile(java.lang.String,%20java.util.HashMap<java.lang.String,java.lang.String>,%20java.lang.String)(https://developer.android.com/reference/java/lang/String text, https://developer.android.com/reference/java/util/HashMap<https://developer.android.com/reference/java/lang/String, https://developer.android.com/reference/java/lang/String> params, https://developer.android.com/reference/java/lang/String filename) ` *This method was deprecated in API level 21. As of API level 21, replaced by `https://developer.android.com/reference/android/speech/tts/TextToSpeech#synthesizeToFile(java.lang.CharSequence,%20android.os.Bundle,%20java.io.File,%20java.lang.String)`.* |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Constants

### ACTION_TTS_QUEUE_PROCESSING_COMPLETED

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final String ACTION_TTS_QUEUE_PROCESSING_COMPLETED
```

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
`https://developer.android.com/reference/android/speech/tts/TextToSpeech.OnUtteranceCompletedListener`.

<br />

Constant Value:

"android.speech.tts.TTS_QUEUE_PROCESSING_COMPLETED"


### ERROR

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int ERROR
```

Denotes a generic operation failure.

<br />

Constant Value:

-1
(0xffffffff)


### ERROR_INVALID_REQUEST

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int ERROR_INVALID_REQUEST
```

Denotes a failure caused by an invalid request.

<br />

Constant Value:

-8
(0xfffffff8)


### ERROR_NETWORK

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int ERROR_NETWORK
```

Denotes a failure caused by a network connectivity problems.

<br />

Constant Value:

-6
(0xfffffffa)


### ERROR_NETWORK_TIMEOUT

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int ERROR_NETWORK_TIMEOUT
```

Denotes a failure caused by network timeout.

<br />

Constant Value:

-7
(0xfffffff9)


### ERROR_NOT_INSTALLED_YET

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int ERROR_NOT_INSTALLED_YET
```

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

<br />

**See also:**

- `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_FEATURE_NOT_INSTALLED`

Constant Value:

-9
(0xfffffff7)


### ERROR_OUTPUT

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int ERROR_OUTPUT
```

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

<br />

Constant Value:

-5
(0xfffffffb)


### ERROR_SERVICE

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int ERROR_SERVICE
```

Denotes a failure of a TTS service.

<br />

Constant Value:

-4
(0xfffffffc)


### ERROR_SYNTHESIS

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int ERROR_SYNTHESIS
```

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

<br />

Constant Value:

-3
(0xfffffffd)


### LANG_AVAILABLE

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int LANG_AVAILABLE
```

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

<br />

Constant Value:

0
(0x00000000)


### LANG_COUNTRY_AVAILABLE

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int LANG_COUNTRY_AVAILABLE
```

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

<br />

Constant Value:

1
(0x00000001)


### LANG_COUNTRY_VAR_AVAILABLE

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int LANG_COUNTRY_VAR_AVAILABLE
```

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

<br />

Constant Value:

2
(0x00000002)


### LANG_MISSING_DATA

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int LANG_MISSING_DATA
```

Denotes the language data is missing.

<br />

Constant Value:

-1
(0xffffffff)


### LANG_NOT_SUPPORTED

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int LANG_NOT_SUPPORTED
```

Denotes the language is not supported.

<br />

Constant Value:

-2
(0xfffffffe)


### QUEUE_ADD

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int QUEUE_ADD
```

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

<br />

Constant Value:

1
(0x00000001)


### QUEUE_FLUSH

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

<br />

Constant Value:

0
(0x00000000)


### STOPPED

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int STOPPED
```

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.

<br />

Constant Value:

-2
(0xfffffffe)


### SUCCESS

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SUCCESS
```

Denotes a successful operation.

<br />

Constant Value:

0
(0x00000000)


## Public constructors

### TextToSpeech

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public TextToSpeech (Context context, 
                TextToSpeech.OnInitListener listener)
```

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.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The context this instance is running in. <br /> |
| `listener` | `TextToSpeech.OnInitListener`: The `https://developer.android.com/reference/android/speech/tts/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. <br /> |

### TextToSpeech

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

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.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The context this instance is running in. <br /> |
| `listener` | `TextToSpeech.OnInitListener`: The `https://developer.android.com/reference/android/speech/tts/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. <br /> |
| `engine` | `String`: Package name of the TTS engine to use. <br /> |

## Public methods

### addEarcon

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

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

<br />

| Parameters ||
|---|---|
| `earcon` | `String`: The name of the earcon. Example: `"[tick]"` <br /> |
| `packagename` | `String`: 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">` <br /> |
| `resourceId` | `int`: Example: `R.raw.tick_snd` <br /> |

| Returns ||
|---|---|
| `int` | Code indicating success or failure. See `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` and `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/speech/tts/TextToSpeech#playEarcon(java.lang.String,%20int,%20java.util.HashMap<java.lang.String,java.lang.String>)`

### addEarcon

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int addEarcon (String earcon, 
                String filename)
```


**This method was deprecated
in API level 21.**   

As of API level 21, replaced by
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#addEarcon(java.lang.String,%20java.io.File)`.

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

<br />

| Parameters ||
|---|---|
| `earcon` | `String`: The name of the earcon. Example: `"[tick]"` <br /> |
| `filename` | `String`: The full path to the sound file (for example: "/sdcard/mysounds/tick.wav") <br /> |

| Returns ||
|---|---|
| `int` | Code indicating success or failure. See `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` and `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/speech/tts/TextToSpeech#playEarcon(java.lang.String,%20int,%20java.util.HashMap<java.lang.String,java.lang.String>)`

### addEarcon

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int addEarcon (String earcon, 
                File file)
```

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

<br />

| Parameters ||
|---|---|
| `earcon` | `String`: The name of the earcon. Example: `"[tick]"` <br /> |
| `file` | `File`: File object pointing to the sound file. <br /> |

| Returns ||
|---|---|
| `int` | Code indicating success or failure. See `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` and `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/speech/tts/TextToSpeech#playEarcon(java.lang.String,%20int,%20java.util.HashMap<java.lang.String,java.lang.String>)`

### addEarcon

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int addEarcon (String earcon, 
                Uri uri)
```

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

<br />

| Parameters ||
|---|---|
| `earcon` | `String`: The name of the earcon. Example: `"[tick]"`. This value cannot be `null`. <br /> |
| `uri` | `Uri`: Uri object pointing to the sound file. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `int` | Code indicating success or failure. See `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` and `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/speech/tts/TextToSpeech#playEarcon(java.lang.String,%20int,%20java.util.HashMap<java.lang.String,java.lang.String>)`

### addSpeech

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int addSpeech (CharSequence text, 
                File file)
```

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 `https://developer.android.com/reference/android/speech/tts/TextToSpeech#speak(java.lang.CharSequence,%20int,%20android.os.Bundle,%20java.lang.String)`
will play the specified sound resource if it is available, or synthesize the text it is
missing.

<br />

| Parameters ||
|---|---|
| `text` | `CharSequence`: The string of text. Example: `"south_south_east"` <br /> |
| `file` | `File`: File object pointing to the sound file. <br /> |

| Returns ||
|---|---|
| `int` | Code indicating success or failure. See `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` and `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

### addSpeech

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Adds a mapping between a string of text and a sound resource in a
package. After a call to this method, subsequent calls to
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#speak(java.lang.CharSequence,%20int,%20android.os.Bundle,%20java.lang.String)` will play the specified sound resource
if it is available, or synthesize the text it is missing.

<br />

| Parameters ||
|---|---|
| `text` | `String`: The string of text. Example: `"south_south_east"` <br /> |
| `packagename` | `String`: 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">` <br /> |
| `resourceId` | `int`: Example: `R.raw.south_south_east` <br /> |

| Returns ||
|---|---|
| `int` | Code indicating success or failure. See `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` and `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

### addSpeech

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public 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. After a call to this method, subsequent calls to
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#speak(java.lang.CharSequence,%20int,%20android.os.Bundle,%20java.lang.String)` will play the specified sound resource
if it is available, or synthesize the text it is missing.

<br />

| Parameters ||
|---|---|
| `text` | `CharSequence`: The string of text. Example: `"south_south_east"` <br /> |
| `packagename` | `String`: 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">` <br /> |
| `resourceId` | `int`: Example: `R.raw.south_south_east` <br /> |

| Returns ||
|---|---|
| `int` | Code indicating success or failure. See `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` and `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

### addSpeech

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int addSpeech (String text, 
                String filename)
```

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 `https://developer.android.com/reference/android/speech/tts/TextToSpeech#speak(java.lang.CharSequence,%20int,%20android.os.Bundle,%20java.lang.String)` will play the specified sound
resource if it is available, or synthesize the text it is missing.

<br />

| Parameters ||
|---|---|
| `text` | `String`: The string of text. Example: `"south_south_east"` <br /> |
| `filename` | `String`: The full path to the sound file (for example: "/sdcard/mysounds/hello.wav") <br /> |

| Returns ||
|---|---|
| `int` | Code indicating success or failure. See `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` and `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

### addSpeech

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int addSpeech (CharSequence text, 
                Uri uri)
```

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 `https://developer.android.com/reference/android/speech/tts/TextToSpeech#speak(java.lang.CharSequence,%20int,%20android.os.Bundle,%20java.lang.String)`
will play the specified sound resource if it is available, or synthesize the text it is
missing.

<br />

| Parameters ||
|---|---|
| `text` | `CharSequence`: The string of text. Example: `"south_south_east"`. This value cannot be `null`. <br /> |
| `uri` | `Uri`: Uri object pointing to the sound file. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `int` | Code indicating success or failure. See `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` and `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

### areDefaultsEnforced

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean areDefaultsEnforced ()
```

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.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### getAvailableLanguages

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Set<Locale> getAvailableLanguages ()
```

Query the engine about the set of available languages.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/util/Locale>` | <br /> |

### getDefaultEngine

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getDefaultEngine ()
```

Gets the package name of the default speech synthesis engine.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | Package name of the TTS engine that the user has chosen as their default. <br /> |

### getDefaultLanguage

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Locale getDefaultLanguage ()
```


**This method was deprecated
in API level 21.**   

As of API level 21, use `getDefaultVoice().getLocale()` (`https://developer.android.com/reference/android/speech/tts/TextToSpeech#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 `https://developer.android.com/reference/android/speech/tts/TextToSpeech#getLanguage()`. Please refer to `https://developer.android.com/reference/android/speech/tts/TextToSpeech#getLanguage()` for more information.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Locale` | language, country (if any) and variant (if any) used by the client stored in a Locale instance, or `null` on error. <br /> |

### getDefaultVoice

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Voice getDefaultVoice ()
```

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/speech/tts/Voice` | The default voice instance for the default language, or `null` if not set or on error. <br /> |

### getEngines

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public List<TextToSpeech.EngineInfo> getEngines ()
```

Gets a list of all installed TTS engines.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/speech/tts/TextToSpeech.EngineInfo>` | A list of engine info objects. The list can be empty, but never `null`. <br /> |

### getFeatures

Added in [API level 15](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public 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 `https://developer.android.com/reference/android/speech/tts/TextToSpeech#getVoices()` to retrieve the list of available voices and
`https://developer.android.com/reference/android/speech/tts/Voice#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.
`https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#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
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#speak(java.lang.String,%20int,%20java.util.HashMap<java.lang.String,java.lang.String>)` and
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#synthesizeToFile(java.lang.String,%20java.util.HashMap<java.lang.String,java.lang.String>,%20java.lang.String)`.

Features values are strings and their values must meet restrictions described in their
documentation.

<br />

| Parameters ||
|---|---|
| `locale` | `Locale`: The locale to query features for. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/lang/String>` | Set instance. May return `null` on error. <br /> |

### getLanguage

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Locale getLanguage ()
```


**This method was deprecated
in API level 21.**   

As of API level 21, please use `getVoice().getLocale()`
(`https://developer.android.com/reference/android/speech/tts/TextToSpeech#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 `https://developer.android.com/reference/android/speech/tts/TextToSpeech#setLanguage(java.util.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 `https://developer.android.com/reference/android/speech/tts/TextToSpeech#setLanguage(java.util.Locale)` call on this instance.

If a voice is set (by `https://developer.android.com/reference/android/speech/tts/TextToSpeech#setVoice(android.speech.tts.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).

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Locale` | language, country (if any) and variant (if any) used by the client stored in a Locale instance, or `null` on error. <br /> |

### getMaxSpeechInputLength

Added in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static int getMaxSpeechInputLength ()
```

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

<br />

| Returns ||
|---|---|
| `int` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/speech/tts/TextToSpeech#speak(java.lang.CharSequence,%20int,%20android.os.Bundle,%20java.lang.String)`
- `https://developer.android.com/reference/android/speech/tts/TextToSpeech#synthesizeToFile(java.lang.CharSequence,%20android.os.Bundle,%20android.os.ParcelFileDescriptor,%20java.lang.String)`

### getVoice

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Voice getVoice ()
```

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/speech/tts/Voice` | Voice instance used by the client, or `null` if not set or on error. <br /> |

**See also:**

- `https://developer.android.com/reference/android/speech/tts/TextToSpeech#getVoices()`
- `https://developer.android.com/reference/android/speech/tts/TextToSpeech#setVoice(android.speech.tts.Voice)`
- `https://developer.android.com/reference/android/speech/tts/Voice`

### getVoices

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Set<Voice> getVoices ()
```

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.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/android/speech/tts/Voice>` | <br /> |

**See also:**

- `https://developer.android.com/reference/android/speech/tts/TextToSpeech#setVoice(android.speech.tts.Voice)`
- `https://developer.android.com/reference/android/speech/tts/Voice`

### isLanguageAvailable

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int isLanguageAvailable (Locale loc)
```

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

<br />

| Parameters ||
|---|---|
| `loc` | `Locale`: The Locale describing the language to be used. <br /> |

| Returns ||
|---|---|
| `int` | Code indicating the support status for the locale. See `https://developer.android.com/reference/android/speech/tts/TextToSpeech#LANG_AVAILABLE`, `https://developer.android.com/reference/android/speech/tts/TextToSpeech#LANG_COUNTRY_AVAILABLE`, `https://developer.android.com/reference/android/speech/tts/TextToSpeech#LANG_COUNTRY_VAR_AVAILABLE`, `https://developer.android.com/reference/android/speech/tts/TextToSpeech#LANG_MISSING_DATA` and `https://developer.android.com/reference/android/speech/tts/TextToSpeech#LANG_NOT_SUPPORTED`. <br /> |

### isSpeaking

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isSpeaking ()
```

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.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if the TTS engine is speaking. <br /> |

### playEarcon

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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


**This method was deprecated
in API level 21.**   

As of API level 21, replaced by
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#playEarcon(java.lang.String,%20int,%20android.os.Bundle,%20java.lang.String)`.

Plays the earcon using the specified queueing mode and parameters.
The earcon must already have been added with `https://developer.android.com/reference/android/speech/tts/TextToSpeech#addEarcon(java.lang.String,%20java.lang.String)` or
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#addEarcon(java.lang.String,%20java.lang.String,%20int)`.
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
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#setOnUtteranceProgressListener(android.speech.tts.UtteranceProgressListener)`) and using the
`https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_PARAM_UTTERANCE_ID` parameter.

<br />

| Parameters ||
|---|---|
| `earcon` | `String`: The earcon that should be played <br /> |
| `queueMode` | `int`: `https://developer.android.com/reference/android/speech/tts/TextToSpeech#QUEUE_ADD` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#QUEUE_FLUSH`. <br /> |
| `params` | `HashMap`: Parameters for the request. Can be null. Supported parameter names: `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_PARAM_STREAM`, `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#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. <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS` of **queuing** the playEarcon operation. <br /> |

### playEarcon

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Plays the earcon using the specified queueing mode and parameters.
The earcon must already have been added with `https://developer.android.com/reference/android/speech/tts/TextToSpeech#addEarcon(java.lang.String,%20java.lang.String)` or
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#addEarcon(java.lang.String,%20java.lang.String,%20int)`.
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
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#setOnUtteranceProgressListener(android.speech.tts.UtteranceProgressListener)`) and using the
`https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_PARAM_UTTERANCE_ID` parameter.

<br />

| Parameters ||
|---|---|
| `earcon` | `String`: The earcon that should be played <br /> |
| `queueMode` | `int`: `https://developer.android.com/reference/android/speech/tts/TextToSpeech#QUEUE_ADD` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#QUEUE_FLUSH`. <br /> |
| `params` | `Bundle`: Parameters for the request. Can be null. Supported parameter names: `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#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. <br /> |
| `utteranceId` | `String` <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS` of **queuing** the playEarcon operation. <br /> |

### playSilence

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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


**This method was deprecated
in API level 21.**   

As of API level 21, replaced by
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#playSilentUtterance(long,%20int,%20java.lang.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
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#setOnUtteranceProgressListener(android.speech.tts.UtteranceProgressListener)`) and using the
`https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_PARAM_UTTERANCE_ID` parameter.

<br />

| Parameters ||
|---|---|
| `durationInMs` | `long`: The duration of the silence. <br /> |
| `queueMode` | `int`: `https://developer.android.com/reference/android/speech/tts/TextToSpeech#QUEUE_ADD` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#QUEUE_FLUSH`. <br /> |
| `params` | `HashMap`: Parameters for the request. Can be null. Supported parameter names: `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#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. <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS` of **queuing** the playSilence operation. <br /> |

### playSilentUtterance

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

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
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#setOnUtteranceProgressListener(android.speech.tts.UtteranceProgressListener)`) and using the
`https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_PARAM_UTTERANCE_ID` parameter.

<br />

| Parameters ||
|---|---|
| `durationInMs` | `long`: The duration of the silence. <br /> |
| `queueMode` | `int`: `https://developer.android.com/reference/android/speech/tts/TextToSpeech#QUEUE_ADD` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#QUEUE_FLUSH`. <br /> |
| `utteranceId` | `String`: An unique identifier for this request. <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS` of **queuing** the playSilentUtterance operation. <br /> |

### setAudioAttributes

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int setAudioAttributes (AudioAttributes audioAttributes)
```

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

<br />

| Parameters ||
|---|---|
| `audioAttributes` | `AudioAttributes`: Valid AudioAttributes instance. <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

### setEngineByPackageName

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
15](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int setEngineByPackageName (String enginePackageName)
```


**This method was deprecated
in API level 15.**   

This doesn't inform callers when the TTS engine has been
initialized. `https://developer.android.com/reference/android/speech/tts/TextToSpeech#TextToSpeech(android.content.Context,%20android.speech.tts.TextToSpeech.OnInitListener,%20java.lang.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.

<br />

| Parameters ||
|---|---|
| `enginePackageName` | `String`: The package name for the synthesis engine (e.g. "com.svox.pico") <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

### setLanguage

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int setLanguage (Locale loc)
```

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 `https://developer.android.com/reference/android/speech/tts/TextToSpeech#isLanguageAvailable(java.util.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;
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#getVoice()` can be used to retrieve it.

<br />

| Parameters ||
|---|---|
| `loc` | `Locale`: The locale describing the language to be used. <br /> |

| Returns ||
|---|---|
| `int` | Code indicating the support status for the locale. See `https://developer.android.com/reference/android/speech/tts/TextToSpeech#LANG_AVAILABLE`, `https://developer.android.com/reference/android/speech/tts/TextToSpeech#LANG_COUNTRY_AVAILABLE`, `https://developer.android.com/reference/android/speech/tts/TextToSpeech#LANG_COUNTRY_VAR_AVAILABLE`, `https://developer.android.com/reference/android/speech/tts/TextToSpeech#LANG_MISSING_DATA` and `https://developer.android.com/reference/android/speech/tts/TextToSpeech#LANG_NOT_SUPPORTED`. <br /> |

### setOnUtteranceCompletedListener

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
15](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int setOnUtteranceCompletedListener (TextToSpeech.OnUtteranceCompletedListener listener)
```


**This method was deprecated
in API level 15.**   

Use `https://developer.android.com/reference/android/speech/tts/TextToSpeech#setOnUtteranceProgressListener(android.speech.tts.UtteranceProgressListener)`
instead.

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

<br />

| Parameters ||
|---|---|
| `listener` | `TextToSpeech.OnUtteranceCompletedListener`: The listener to use. <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

### setOnUtteranceProgressListener

Added in [API level 15](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int setOnUtteranceProgressListener (UtteranceProgressListener listener)
```

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

See `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener` and
`https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_PARAM_UTTERANCE_ID`.

<br />

| Parameters ||
|---|---|
| `listener` | `UtteranceProgressListener`: the listener to use. <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS` <br /> |

### setPitch

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int setPitch (float pitch)
```

Sets the speech pitch for the TextToSpeech engine.

This has no effect on any pre-recorded speech.

<br />

| Parameters ||
|---|---|
| `pitch` | `float`: Speech pitch. `1.0` is the normal pitch, lower values lower the tone of the synthesized voice, greater values increase it. <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

### setSpeechRate

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int setSpeechRate (float speechRate)
```

Sets the speech rate.

This has no effect on any pre-recorded speech.

<br />

| Parameters ||
|---|---|
| `speechRate` | `float`: 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). <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

### setVoice

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int setVoice (Voice voice)
```

Sets the text-to-speech voice.

<br />

| Parameters ||
|---|---|
| `voice` | `Voice`: One of objects returned by `https://developer.android.com/reference/android/speech/tts/TextToSpeech#getVoices()`. <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/speech/tts/TextToSpeech#getVoices()`
- `https://developer.android.com/reference/android/speech/tts/Voice`

### shutdown

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void shutdown ()
```

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.

<br />

### speak

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public 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.
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
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#setOnUtteranceProgressListener(android.speech.tts.UtteranceProgressListener)`) and using the
`https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_PARAM_UTTERANCE_ID` parameter.

<br />

| Parameters ||
|---|---|
| `text` | `CharSequence`: The string of text to be spoken. No longer than `https://developer.android.com/reference/android/speech/tts/TextToSpeech#getMaxSpeechInputLength()` characters. <br /> |
| `queueMode` | `int`: The queuing strategy to use, `https://developer.android.com/reference/android/speech/tts/TextToSpeech#QUEUE_ADD` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#QUEUE_FLUSH`. <br /> |
| `params` | `Bundle`: Parameters for the request. Can be null. Supported parameter names: `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_PARAM_STREAM`, `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_PARAM_VOLUME`, `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#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. <br /> |
| `utteranceId` | `String`: An unique identifier for this request. <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS` of **queuing** the speak operation. <br /> |

### speak

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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


**This method was deprecated
in API level 21.**   

As of API level 21, replaced by
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#speak(java.lang.CharSequence,%20int,%20android.os.Bundle,%20java.lang.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
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#setOnUtteranceProgressListener(android.speech.tts.UtteranceProgressListener)`) and using the
`https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_PARAM_UTTERANCE_ID` parameter.

<br />

| Parameters ||
|---|---|
| `text` | `String`: The string of text to be spoken. No longer than `https://developer.android.com/reference/android/speech/tts/TextToSpeech#getMaxSpeechInputLength()` characters. <br /> |
| `queueMode` | `int`: The queuing strategy to use, `https://developer.android.com/reference/android/speech/tts/TextToSpeech#QUEUE_ADD` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#QUEUE_FLUSH`. <br /> |
| `params` | `HashMap`: Parameters for the request. Can be null. Supported parameter names: `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_PARAM_STREAM`, `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_PARAM_UTTERANCE_ID`, `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_PARAM_VOLUME`, `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#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. <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS` of **queuing** the speak operation. <br /> |

### stop

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int stop ()
```

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

<br />

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS`. <br /> |

### synthesizeToFile

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int synthesizeToFile (CharSequence text, 
                Bundle params, 
                ParcelFileDescriptor fileDescriptor, 
                String utteranceId)
```

Synthesizes the given text to a ParcelFileDescriptor 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
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#setOnUtteranceProgressListener(android.speech.tts.UtteranceProgressListener)`).

<br />

| Parameters ||
|---|---|
| `text` | `CharSequence`: The text that should be synthesized. No longer than `https://developer.android.com/reference/android/speech/tts/TextToSpeech#getMaxSpeechInputLength()` characters. This value cannot be `null`. <br /> |
| `params` | `Bundle`: Parameters for the request. 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. This value cannot be `null`. <br /> |
| `fileDescriptor` | `ParcelFileDescriptor`: ParcelFileDescriptor to write the generated audio data to. This value cannot be `null`. <br /> |
| `utteranceId` | `String`: An unique identifier for this request. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS` of **queuing** the synthesizeToFile operation. <br /> |

### synthesizeToFile

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

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
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#setOnUtteranceProgressListener(android.speech.tts.UtteranceProgressListener)`).

<br />

| Parameters ||
|---|---|
| `text` | `CharSequence`: The text that should be synthesized. No longer than `https://developer.android.com/reference/android/speech/tts/TextToSpeech#getMaxSpeechInputLength()` characters. <br /> |
| `params` | `Bundle`: Parameters for the request. Cannot 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. <br /> |
| `file` | `File`: File to write the generated audio data to. <br /> |
| `utteranceId` | `String`: An unique identifier for this request. <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS` of **queuing** the synthesizeToFile operation. <br /> |

### synthesizeToFile

Added in [API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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


**This method was deprecated
in API level 21.**   

As of API level 21, replaced by
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#synthesizeToFile(java.lang.CharSequence,%20android.os.Bundle,%20java.io.File,%20java.lang.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
`https://developer.android.com/reference/android/speech/tts/TextToSpeech#setOnUtteranceProgressListener(android.speech.tts.UtteranceProgressListener)`) and using the
`https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_PARAM_UTTERANCE_ID` parameter.

<br />

| Parameters ||
|---|---|
| `text` | `String`: The text that should be synthesized. No longer than `https://developer.android.com/reference/android/speech/tts/TextToSpeech#getMaxSpeechInputLength()` characters. <br /> |
| `params` | `HashMap`: Parameters for the request. Cannot be null. Supported parameter names: `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#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. <br /> |
| `filename` | `String`: Absolute file filename to write the generated audio data to.It should be something like "/sdcard/myappsounds/mysound.wav". <br /> |

| Returns ||
|---|---|
| `int` | `https://developer.android.com/reference/android/speech/tts/TextToSpeech#ERROR` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#SUCCESS` of **queuing** the synthesizeToFile operation. <br /> |