# RecognitionService.Callback

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

# RecognitionService.Callback

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/speech/RecognitionService.Callback "View this page in Kotlin")\|Java

`
public


class
RecognitionService.Callback
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

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

<br />

*** ** * ** ***

This class receives callbacks from the speech recognition service and forwards them to the user. An instance of this class is passed to the[RecognitionService.onStartListening(Intent, Callback)](https://developer.android.com/reference/android/speech/RecognitionService#onStartListening(android.content.Intent,%20android.speech.RecognitionService.Callback))method. Recognizers may call these methods on any thread.

## Summary

|                                                                                                                                                                                                             ### Public methods                                                                                                                                                                                                              ||
|---------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`                                                                                           | ` `[beginningOfSpeech](https://developer.android.com/reference/android/speech/RecognitionService.Callback#beginningOfSpeech())`() ` The service should call this method when the user has started to speak.                                                                                                                              |
| ` void`                                                                                           | ` `[bufferReceived](https://developer.android.com/reference/android/speech/RecognitionService.Callback#bufferReceived(byte[]))`(byte[] buffer) ` The service should call this method when sound has been received.                                                                                                                       |
| ` void`                                                                                           | ` `[endOfSegmentedSession](https://developer.android.com/reference/android/speech/RecognitionService.Callback#endOfSegmentedSession())`() ` The service should call this method to end a segmented session.                                                                                                                              |
| ` void`                                                                                           | ` `[endOfSpeech](https://developer.android.com/reference/android/speech/RecognitionService.Callback#endOfSpeech())`() ` The service should call this method after the user stops speaking.                                                                                                                                               |
| ` void`                                                                                           | ` `[error](https://developer.android.com/reference/android/speech/RecognitionService.Callback#error(int))`(int error) ` The service should call this method when a network or recognition error occurred.                                                                                                                                |
| ` `[AttributionSource](https://developer.android.com/reference/android/content/AttributionSource) | ` `[getCallingAttributionSource](https://developer.android.com/reference/android/speech/RecognitionService.Callback#getCallingAttributionSource())`() ` Gets the permission identity of the calling app.                                                                                                                                 |
| ` int`                                                                                            | ` `[getCallingUid](https://developer.android.com/reference/android/speech/RecognitionService.Callback#getCallingUid())`() ` Return the Linux uid assigned to the process that sent you the current transaction that is being processed.                                                                                                  |
| ` void`                                                                                           | ` `[languageDetection](https://developer.android.com/reference/android/speech/RecognitionService.Callback#languageDetection(android.os.Bundle))`(`[Bundle](https://developer.android.com/reference/android/os/Bundle)` results) ` The service should call this method when the language detection (and switching) results are available. |
| ` void`                                                                                           | ` `[partialResults](https://developer.android.com/reference/android/speech/RecognitionService.Callback#partialResults(android.os.Bundle))`(`[Bundle](https://developer.android.com/reference/android/os/Bundle)` partialResults) ` The service should call this method when partial recognition results are available.                   |
| ` void`                                                                                           | ` `[readyForSpeech](https://developer.android.com/reference/android/speech/RecognitionService.Callback#readyForSpeech(android.os.Bundle))`(`[Bundle](https://developer.android.com/reference/android/os/Bundle)` params) ` The service should call this method when the endpointer is ready for the user to start speaking.              |
| ` void`                                                                                           | ` `[results](https://developer.android.com/reference/android/speech/RecognitionService.Callback#results(android.os.Bundle))`(`[Bundle](https://developer.android.com/reference/android/os/Bundle)` results) ` The service should call this method when recognition results are ready.                                                    |
| ` void`                                                                                           | ` `[rmsChanged](https://developer.android.com/reference/android/speech/RecognitionService.Callback#rmsChanged(float))`(float rmsdB) ` The service should call this method when the sound level in the audio stream has changed.                                                                                                          |
| ` void`                                                                                           | ` `[segmentResults](https://developer.android.com/reference/android/speech/RecognitionService.Callback#segmentResults(android.os.Bundle))`(`[Bundle](https://developer.android.com/reference/android/os/Bundle)` results) ` The service should call this method for each ready segment of a long recognition session.                    |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](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 `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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 methods

### beginningOfSpeech

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

```
public void beginningOfSpeech ()
```

The service should call this method when the user has started to speak.

<br />

|                                          Throws                                          ||
|---------------------------------------------------------------------------------------|---|
| [RemoteException](https://developer.android.com/reference/android/os/RemoteException) |   |

### bufferReceived

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

```
public void bufferReceived (byte[] buffer)
```

The service should call this method when sound has been received. The purpose of this function is to allow giving feedback to the user regarding the captured audio.

<br />

|                                                                                   Parameters                                                                                   ||
|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `buffer` | `byte`: a buffer containing a sequence of big-endian 16-bit integers representing a single channel audio stream. The sample rate is implementation dependent. <br /> |

|                                          Throws                                          ||
|---------------------------------------------------------------------------------------|---|
| [RemoteException](https://developer.android.com/reference/android/os/RemoteException) |   |

### endOfSegmentedSession

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

```
public void endOfSegmentedSession ()
```

The service should call this method to end a segmented session.

<br />

|                                          Throws                                          ||
|---------------------------------------------------------------------------------------|---|
| [RemoteException](https://developer.android.com/reference/android/os/RemoteException) |   |

### endOfSpeech

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

```
public void endOfSpeech ()
```

The service should call this method after the user stops speaking.

<br />

|                                          Throws                                          ||
|---------------------------------------------------------------------------------------|---|
| [RemoteException](https://developer.android.com/reference/android/os/RemoteException) |   |

### error

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

```
public void error (int error)
```

The service should call this method when a network or recognition error occurred.

<br />

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ||
|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `error` | `int`: code is defined in[SpeechRecognizer](https://developer.android.com/reference/android/speech/SpeechRecognizer)Value is[SpeechRecognizer.ERROR_NETWORK_TIMEOUT](https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_NETWORK_TIMEOUT),[SpeechRecognizer.ERROR_NETWORK](https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_NETWORK),[SpeechRecognizer.ERROR_AUDIO](https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_AUDIO),[SpeechRecognizer.ERROR_SERVER](https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_SERVER),[SpeechRecognizer.ERROR_CLIENT](https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_CLIENT),[SpeechRecognizer.ERROR_SPEECH_TIMEOUT](https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_SPEECH_TIMEOUT),[SpeechRecognizer.ERROR_NO_MATCH](https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_NO_MATCH),[SpeechRecognizer.ERROR_RECOGNIZER_BUSY](https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_RECOGNIZER_BUSY),[SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS](https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_INSUFFICIENT_PERMISSIONS),[SpeechRecognizer.ERROR_TOO_MANY_REQUESTS](https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_TOO_MANY_REQUESTS),[SpeechRecognizer.ERROR_SERVER_DISCONNECTED](https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_SERVER_DISCONNECTED),[SpeechRecognizer.ERROR_LANGUAGE_NOT_SUPPORTED](https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_LANGUAGE_NOT_SUPPORTED),[SpeechRecognizer.ERROR_LANGUAGE_UNAVAILABLE](https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_LANGUAGE_UNAVAILABLE),[SpeechRecognizer.ERROR_CANNOT_CHECK_SUPPORT](https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_CANNOT_CHECK_SUPPORT), or[SpeechRecognizer.ERROR_CANNOT_LISTEN_TO_DOWNLOAD_EVENTS](https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_CANNOT_LISTEN_TO_DOWNLOAD_EVENTS) <br /> |

|                                          Throws                                          ||
|---------------------------------------------------------------------------------------|---|
| [RemoteException](https://developer.android.com/reference/android/os/RemoteException) |   |

### getCallingAttributionSource

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

```
public AttributionSource getCallingAttributionSource ()
```

Gets the permission identity of the calling app. If you want to attribute the mic access to the calling app you can create an attribution context via[Context.createContext(android.content.ContextParams)](https://developer.android.com/reference/android/content/Context#createContext(android.content.ContextParams))and passing this identity to[ContextParams.Builder.setNextAttributionSource(AttributionSource)](https://developer.android.com/reference/android/content/ContextParams.Builder#setNextAttributionSource(android.content.AttributionSource)).

<br />

|                                                                                    Returns                                                                                     ||
|------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
| [AttributionSource](https://developer.android.com/reference/android/content/AttributionSource) | The permission identity of the calling app. This value cannot be`null`. <br /> |

**See also:**

- [ContextParams.Builder.setNextAttributionSource(AttributionSource)](https://developer.android.com/reference/android/content/ContextParams.Builder#setNextAttributionSource(android.content.AttributionSource))  

### getCallingUid

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

```
public int getCallingUid ()
```

Return the Linux uid assigned to the process that sent you the current transaction that is being processed. This is obtained from[Binder.getCallingUid()](https://developer.android.com/reference/android/os/Binder#getCallingUid()).

<br />

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

### languageDetection

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

```
public void languageDetection (Bundle results)
```

The service should call this method when the language detection (and switching) results are available. This method can be called on any number of occasions at any time between[beginningOfSpeech()](https://developer.android.com/reference/android/speech/RecognitionService.Callback#beginningOfSpeech())and[endOfSpeech()](https://developer.android.com/reference/android/speech/RecognitionService.Callback#endOfSpeech()), depending on the speech recognition service implementation.

<br />

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ||
|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `results` | `Bundle`: the returned language detection (and switching) results. To retrieve the most confidently detected language IETF tag (as defined by BCP 47, e.g., "en-US", "de-DE"), use[Bundle.getString(String)](https://developer.android.com/reference/android/os/BaseBundle#getString(java.lang.String))with[SpeechRecognizer.DETECTED_LANGUAGE](https://developer.android.com/reference/android/speech/SpeechRecognizer#DETECTED_LANGUAGE)as the parameter. To retrieve the language detection confidence level represented by a value prefixed by`LANGUAGE_DETECTION_CONFIDENCE_LEVEL_`defined in[SpeechRecognizer](https://developer.android.com/reference/android/speech/SpeechRecognizer), use[Bundle.getInt(String)](https://developer.android.com/reference/android/os/BaseBundle#getInt(java.lang.String))with[SpeechRecognizer.LANGUAGE_DETECTION_CONFIDENCE_LEVEL](https://developer.android.com/reference/android/speech/SpeechRecognizer#LANGUAGE_DETECTION_CONFIDENCE_LEVEL)as the parameter. To retrieve the alternative locales for the same language retrieved by the key[SpeechRecognizer.DETECTED_LANGUAGE](https://developer.android.com/reference/android/speech/SpeechRecognizer#DETECTED_LANGUAGE), use[Bundle.getStringArrayList(String)](https://developer.android.com/reference/android/os/Bundle#getStringArrayList(java.lang.String))with[SpeechRecognizer.TOP_LOCALE_ALTERNATIVES](https://developer.android.com/reference/android/speech/SpeechRecognizer#TOP_LOCALE_ALTERNATIVES)as the parameter. To retrieve the language switching results represented by a value prefixed by`LANGUAGE_SWITCH_RESULT_`and defined in[SpeechRecognizer](https://developer.android.com/reference/android/speech/SpeechRecognizer), use[Bundle.getInt(String)](https://developer.android.com/reference/android/os/BaseBundle#getInt(java.lang.String))with[SpeechRecognizer.LANGUAGE_SWITCH_RESULT](https://developer.android.com/reference/android/speech/SpeechRecognizer#LANGUAGE_SWITCH_RESULT)as the parameter. This value cannot be`null`. |

### partialResults

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

```
public void partialResults (Bundle partialResults)
```

The service should call this method when partial recognition results are available. This method can be called at any time between[beginningOfSpeech()](https://developer.android.com/reference/android/speech/RecognitionService.Callback#beginningOfSpeech())and[results(android.os.Bundle)](https://developer.android.com/reference/android/speech/RecognitionService.Callback#results(android.os.Bundle))when partial results are ready. This method may be called zero, one or multiple times for each call to[SpeechRecognizer.startListening(Intent)](https://developer.android.com/reference/android/speech/SpeechRecognizer#startListening(android.content.Intent)), depending on the speech recognition service implementation.

<br />

|                                                                                                                                                                                                 Parameters                                                                                                                                                                                                 ||
|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `partialResults` | `Bundle`: the returned results. To retrieve the results in ArrayList\<String\> format use[Bundle.getStringArrayList(String)](https://developer.android.com/reference/android/os/Bundle#getStringArrayList(java.lang.String))with[SpeechRecognizer.RESULTS_RECOGNITION](https://developer.android.com/reference/android/speech/SpeechRecognizer#RESULTS_RECOGNITION)as a parameter <br /> |

|                                          Throws                                          ||
|---------------------------------------------------------------------------------------|---|
| [RemoteException](https://developer.android.com/reference/android/os/RemoteException) |   |

### readyForSpeech

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

```
public void readyForSpeech (Bundle params)
```

The service should call this method when the endpointer is ready for the user to start speaking.

<br />

|                                           Parameters                                           ||
|----------|--------------------------------------------------------------------------------------|
| `params` | `Bundle`: parameters set by the recognition service. Reserved for future use. <br /> |

|                                          Throws                                          ||
|---------------------------------------------------------------------------------------|---|
| [RemoteException](https://developer.android.com/reference/android/os/RemoteException) |   |

### results

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

```
public void results (Bundle results)
```

The service should call this method when recognition results are ready.

<br />

|                                                                                                                                                                                              Parameters                                                                                                                                                                                              ||
|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `results` | `Bundle`: the recognition results. To retrieve the results in`ArrayList<String>`format use[Bundle.getStringArrayList(String)](https://developer.android.com/reference/android/os/Bundle#getStringArrayList(java.lang.String))with[SpeechRecognizer.RESULTS_RECOGNITION](https://developer.android.com/reference/android/speech/SpeechRecognizer#RESULTS_RECOGNITION)as a parameter <br /> |

|                                          Throws                                          ||
|---------------------------------------------------------------------------------------|---|
| [RemoteException](https://developer.android.com/reference/android/os/RemoteException) |   |

### rmsChanged

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

```
public void rmsChanged (float rmsdB)
```

The service should call this method when the sound level in the audio stream has changed. There is no guarantee that this method will be called.

<br />

|                  Parameters                   ||
|---------|--------------------------------------|
| `rmsdB` | `float`: the new RMS dB value <br /> |

|                                          Throws                                          ||
|---------------------------------------------------------------------------------------|---|
| [RemoteException](https://developer.android.com/reference/android/os/RemoteException) |   |

### segmentResults

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

```
public void segmentResults (Bundle results)
```

The service should call this method for each ready segment of a long recognition session.

<br />

|                                                                                                                                                                                                            Parameters                                                                                                                                                                                                            ||
|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `results` | `Bundle`: the recognition results. To retrieve the results in`ArrayList<String>`format use[Bundle.getStringArrayList(String)](https://developer.android.com/reference/android/os/Bundle#getStringArrayList(java.lang.String))with[SpeechRecognizer.RESULTS_RECOGNITION](https://developer.android.com/reference/android/speech/SpeechRecognizer#RESULTS_RECOGNITION)as a parameter This value cannot be`null`. <br /> |

|                                          Throws                                          ||
|---------------------------------------------------------------------------------------|---|
| [RemoteException](https://developer.android.com/reference/android/os/RemoteException) |   |