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

# UtteranceProgressListener

*** ** * ** ***

` public abstract class UtteranceProgressListener `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

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

<br />

*** ** * ** ***

Listener for events relating to the progress of an utterance through the synthesis queue. Each utterance is associated with a call to `https://developer.android.com/reference/android/speech/tts/TextToSpeech#speak(java.lang.CharSequence,%20int,%20android.os.Bundle,%20java.lang.String)` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#synthesizeToFile(java.lang.CharSequence,%20android.os.Bundle,%20android.os.ParcelFileDescriptor,%20java.lang.String)` with an associated utterance identifier, as per `https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#KEY_PARAM_UTTERANCE_ID`. The callbacks specified in this method can be called from multiple threads.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#UtteranceProgressListener()() ` |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onAudioAvailable(java.lang.String,%20byte[])(https://developer.android.com/reference/java/lang/String utteranceId, byte[] audio) ` This is called when a chunk of audio is ready for consumption. |
| ` void` | ` https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onBeginSynthesis(java.lang.String,%20int,%20int,%20int)(https://developer.android.com/reference/java/lang/String utteranceId, int sampleRateInHz, int audioFormat, int channelCount) ` Called when the TTS engine begins to synthesize the audio for a request. |
| ` abstract void` | ` https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onDone(java.lang.String)(https://developer.android.com/reference/java/lang/String utteranceId) ` Called when an utterance has successfully completed processing. |
| ` abstract void` | ` https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onError(java.lang.String)(https://developer.android.com/reference/java/lang/String utteranceId) ` *This method was deprecated in API level 21. Use `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onError(java.lang.String,%20int)` instead* |
| ` void` | ` https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onError(java.lang.String,%20int)(https://developer.android.com/reference/java/lang/String utteranceId, int errorCode) ` Called when an error has occurred during processing. |
| ` void` | ` https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onRangeStart(java.lang.String,%20int,%20int,%20int)(https://developer.android.com/reference/java/lang/String utteranceId, int start, int end, int frame) ` This is called when the TTS service is about to speak the specified range of the utterance with the given utteranceId. |
| ` abstract void` | ` https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onStart(java.lang.String)(https://developer.android.com/reference/java/lang/String utteranceId) ` Called when an utterance "starts" as perceived by the caller. |
| ` void` | ` https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onStop(java.lang.String,%20boolean)(https://developer.android.com/reference/java/lang/String utteranceId, boolean interrupted) ` Called when an utterance has been stopped while in progress or flushed from the synthesis queue. |

### 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*.

## Public constructors

### UtteranceProgressListener

```
public UtteranceProgressListener ()
```

<br />

<br />

## Public methods

### onAudioAvailable

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

```
public void onAudioAvailable (String utteranceId, 
                byte[] audio)
```

This is called when a chunk of audio is ready for consumption.

The audio parameter is a copy of what will be synthesized to the speakers (when synthesis was initiated with a `https://developer.android.com/reference/android/speech/tts/TextToSpeech#speak(java.lang.CharSequence,%20int,%20android.os.Bundle,%20java.lang.String)` call) or written to the file system (for `https://developer.android.com/reference/android/speech/tts/TextToSpeech#synthesizeToFile(java.lang.CharSequence,%20android.os.Bundle,%20android.os.ParcelFileDescriptor,%20java.lang.String)`). The audio bytes are delivered in one or more chunks; if `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onDone(java.lang.String)` or `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onError(java.lang.String)` is called all chunks have been received.

The audio received here may not be played for some time depending on buffer sizes and the amount of items on the synthesis queue.

<br />

<br />

| Parameters ||
|---|---|
| `utteranceId` | `String`: The utterance ID of the utterance. <br /> |
| `audio` | `byte`: A chunk of audio; the format can be known by listening to `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onBeginSynthesis(java.lang.String,%20int,%20int,%20int)`. <br /> |

### onBeginSynthesis

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

```
public void onBeginSynthesis (String utteranceId, 
                int sampleRateInHz, 
                int audioFormat, 
                int channelCount)
```

Called when the TTS engine begins to synthesize the audio for a request.

It provides information about the format of the byte array for subsequent `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onAudioAvailable(java.lang.String,%20byte[])` calls.

This is called when the TTS engine starts synthesizing audio for the request. If an application wishes to know when the audio is about to start playing, {#onStart(String)} should be used instead.

<br />

<br />

| Parameters ||
|---|---|
| `utteranceId` | `String`: The utterance ID of the utterance. <br /> |
| `sampleRateInHz` | `int`: Sample rate in hertz of the generated audio. <br /> |
| `audioFormat` | `int`: Audio format of the generated audio. Should be one of `https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_8BIT`, `https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_16BIT` or `https://developer.android.com/reference/android/media/AudioFormat#ENCODING_PCM_FLOAT`. <br /> |
| `channelCount` | `int`: The number of channels. <br /> |

### onDone

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

```
public abstract void onDone (String utteranceId)
```

Called when an utterance has successfully completed processing. All audio will have been played back by this point for audible output, and all output will have been written to disk for file synthesis requests. This request is guaranteed to be called after `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onStart(java.lang.String)`.

<br />

| Parameters ||
|---|---|
| `utteranceId` | `String`: The utterance ID of the utterance. <br /> |

### onError

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 abstract void onError (String utteranceId)
```

<br />

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

Use `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onError(java.lang.String,%20int)` instead

Called when an error has occurred during processing. This can be called at any point in the synthesis process. Note that there might be calls to `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onStart(java.lang.String)` for specified utteranceId but there will never be a call to both `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onDone(java.lang.String)` and `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onError(java.lang.String)` for the same utterance.

<br />

| Parameters ||
|---|---|
| `utteranceId` | `String`: The utterance ID of the utterance. <br /> |

### onError

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

```
public void onError (String utteranceId, 
                int errorCode)
```

Called when an error has occurred during processing. This can be called at any point in the synthesis process. Note that there might be calls to `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onStart(java.lang.String)` for specified utteranceId but there will never be a call to both `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onDone(java.lang.String)` and `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onError(java.lang.String,%20int)` for the same utterance. The default implementation calls `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onError(java.lang.String)`.

<br />

| Parameters ||
|---|---|
| `utteranceId` | `String`: The utterance ID of the utterance. <br /> |
| `errorCode` | `int`: one of the ERROR_\* codes from `https://developer.android.com/reference/android/speech/tts/TextToSpeech` <br /> |

### onRangeStart

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

```
public void onRangeStart (String utteranceId, 
                int start, 
                int end, 
                int frame)
```

This is called when the TTS service is about to speak the specified range of the utterance with the given utteranceId.

This method is called when the audio is expected to start playing on the speaker. Note that this is different from `https://developer.android.com/reference/android/speech/tts/UtteranceProgressListener#onAudioAvailable(java.lang.String,%20byte[])` which is called as soon as the audio is generated.

This information can be used, for example, to highlight ranges of the text while it is spoken.

Only called if the engine supplies timing information by calling `https://developer.android.com/reference/android/speech/tts/SynthesisCallback#rangeStart(int,%20int,%20int)`.

<br />

| Parameters ||
|---|---|
| `utteranceId` | `String`: Unique id identifying the synthesis request. <br /> |
| `start` | `int`: The start index of the range in the utterance text. <br /> |
| `end` | `int`: The end index of the range (exclusive) in the utterance text. <br /> |
| `frame` | `int`: The position in frames in the audio of the request where this range is spoken. <br /> |

### onStart

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

```
public abstract void onStart (String utteranceId)
```

Called when an utterance "starts" as perceived by the caller. This will be soon before audio is played back in the case of a `https://developer.android.com/reference/android/speech/tts/TextToSpeech#speak(java.lang.CharSequence,%20int,%20android.os.Bundle,%20java.lang.String)` or before the first bytes of a file are written to the file system in the case of `https://developer.android.com/reference/android/speech/tts/TextToSpeech#synthesizeToFile(java.lang.CharSequence,%20android.os.Bundle,%20android.os.ParcelFileDescriptor,%20java.lang.String)`.

<br />

| Parameters ||
|---|---|
| `utteranceId` | `String`: The utterance ID of the utterance. <br /> |

### onStop

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

```
public void onStop (String utteranceId, 
                boolean interrupted)
```

Called when an utterance has been stopped while in progress or flushed from the synthesis queue. This can happen if a client calls `https://developer.android.com/reference/android/speech/tts/TextToSpeech#stop()` or uses `https://developer.android.com/reference/android/speech/tts/TextToSpeech#QUEUE_FLUSH` as an argument with the `https://developer.android.com/reference/android/speech/tts/TextToSpeech#speak(java.lang.CharSequence,%20int,%20android.os.Bundle,%20java.lang.String)` or `https://developer.android.com/reference/android/speech/tts/TextToSpeech#synthesizeToFile(java.lang.CharSequence,%20android.os.Bundle,%20android.os.ParcelFileDescriptor,%20java.lang.String)` methods.

<br />

| Parameters ||
|---|---|
| `utteranceId` | `String`: The utterance ID of the utterance. <br /> |
| `interrupted` | `boolean`: If true, then the utterance was interrupted while being synthesized and its output is incomplete. If false, then the utterance was flushed before the synthesis started. <br /> |