# RecognitionService.Callback

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

# Callback

*** ** * ** ***

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

```
open class Callback
```

|---|------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                           ||
| ↳ | [android.speech.RecognitionService.Callback](https://developer.android.com/reference/kotlin/android/speech/RecognitionService.Callback#) |

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/kotlin/android/speech/RecognitionService#onStartListening(android.content.Intent,%20android.speech.RecognitionService.Callback))method. Recognizers may call these methods on any thread.

## Summary

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

## Public methods

### beginningOfSpeech

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

```
open fun beginningOfSpeech(): Unit
```

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

### bufferReceived

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

```
open fun bufferReceived(buffer: ByteArray!): Unit
```

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.

|                                                                                                                        Parameters                                                                                                                        ||
|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `buffer` | [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!:a buffer containing a sequence of big-endian 16-bit integers representing a single channel audio stream. The sample rate is implementation dependent. |

### endOfSegmentedSession

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

```
open fun endOfSegmentedSession(): Unit
```

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

### endOfSpeech

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

```
open fun endOfSpeech(): Unit
```

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

### error

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

```
open fun error(error: Int): Unit
```

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

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              ||
|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `error` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):code is defined in[SpeechRecognizer](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer)Value is[android.speech.SpeechRecognizer#ERROR_NETWORK_TIMEOUT](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#ERROR_NETWORK_TIMEOUT:kotlin.Int),[android.speech.SpeechRecognizer#ERROR_NETWORK](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#ERROR_NETWORK:kotlin.Int),[android.speech.SpeechRecognizer#ERROR_AUDIO](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#ERROR_AUDIO:kotlin.Int),[android.speech.SpeechRecognizer#ERROR_SERVER](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#ERROR_SERVER:kotlin.Int),[android.speech.SpeechRecognizer#ERROR_CLIENT](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#ERROR_CLIENT:kotlin.Int),[android.speech.SpeechRecognizer#ERROR_SPEECH_TIMEOUT](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#ERROR_SPEECH_TIMEOUT:kotlin.Int),[android.speech.SpeechRecognizer#ERROR_NO_MATCH](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#ERROR_NO_MATCH:kotlin.Int),[android.speech.SpeechRecognizer#ERROR_RECOGNIZER_BUSY](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#ERROR_RECOGNIZER_BUSY:kotlin.Int),[android.speech.SpeechRecognizer#ERROR_INSUFFICIENT_PERMISSIONS](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#ERROR_INSUFFICIENT_PERMISSIONS:kotlin.Int),[android.speech.SpeechRecognizer#ERROR_TOO_MANY_REQUESTS](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#ERROR_TOO_MANY_REQUESTS:kotlin.Int),[android.speech.SpeechRecognizer#ERROR_SERVER_DISCONNECTED](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#ERROR_SERVER_DISCONNECTED:kotlin.Int),[android.speech.SpeechRecognizer#ERROR_LANGUAGE_NOT_SUPPORTED](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#ERROR_LANGUAGE_NOT_SUPPORTED:kotlin.Int),[android.speech.SpeechRecognizer#ERROR_LANGUAGE_UNAVAILABLE](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#ERROR_LANGUAGE_UNAVAILABLE:kotlin.Int),[android.speech.SpeechRecognizer#ERROR_CANNOT_CHECK_SUPPORT](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#ERROR_CANNOT_CHECK_SUPPORT:kotlin.Int), or[android.speech.SpeechRecognizer#ERROR_CANNOT_LISTEN_TO_DOWNLOAD_EVENTS](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#ERROR_CANNOT_LISTEN_TO_DOWNLOAD_EVENTS:kotlin.Int) |

### getCallingAttributionSource

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

```
open fun getCallingAttributionSource(): AttributionSource
```

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[android.content.Context#createContext(android.content.ContextParams)](https://developer.android.com/reference/kotlin/android/content/Context.html#createContext(android.content.ContextParams))and passing this identity to[android.content.ContextParams.Builder#setNextAttributionSource(AttributionSource)](https://developer.android.com/reference/kotlin/android/content/ContextParams.Builder.html#setNextAttributionSource(android.content.AttributionSource)).

|                                                                                        Return                                                                                        ||
|-------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------|
| [AttributionSource](https://developer.android.com/reference/kotlin/android/content/AttributionSource.html#) | The permission identity of the calling app. This value cannot be`null`. |

**See Also**

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

### getCallingUid

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

```
open fun getCallingUid(): Int
```

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/kotlin/android/os/Binder.html#getCallingUid()).  

### languageDetection

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

```
open fun languageDetection(results: Bundle): Unit
```

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/kotlin/android/speech/RecognitionService.Callback#beginningOfSpeech())and[endOfSpeech()](https://developer.android.com/reference/kotlin/android/speech/RecognitionService.Callback#endOfSpeech()), depending on the speech recognition service implementation.

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ||
|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `results` | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#):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/kotlin/android/os/BaseBundle.html#getString(kotlin.String))with[SpeechRecognizer.DETECTED_LANGUAGE](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#DETECTED_LANGUAGE:kotlin.String)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/kotlin/android/speech/SpeechRecognizer), use[Bundle.getInt(String)](https://developer.android.com/reference/kotlin/android/os/BaseBundle.html#getInt(kotlin.String))with[SpeechRecognizer.LANGUAGE_DETECTION_CONFIDENCE_LEVEL](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#LANGUAGE_DETECTION_CONFIDENCE_LEVEL:kotlin.String)as the parameter. To retrieve the alternative locales for the same language retrieved by the key[SpeechRecognizer.DETECTED_LANGUAGE](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#DETECTED_LANGUAGE:kotlin.String), use[Bundle.getStringArrayList(String)](https://developer.android.com/reference/kotlin/android/os/Bundle.html#getStringArrayList(kotlin.String))with[SpeechRecognizer.TOP_LOCALE_ALTERNATIVES](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#TOP_LOCALE_ALTERNATIVES:kotlin.String)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/kotlin/android/speech/SpeechRecognizer), use[Bundle.getInt(String)](https://developer.android.com/reference/kotlin/android/os/BaseBundle.html#getInt(kotlin.String))with[SpeechRecognizer.LANGUAGE_SWITCH_RESULT](https://developer.android.com/reference/kotlin/android/speech/SpeechRecognizer#LANGUAGE_SWITCH_RESULT:kotlin.String)as the parameter. This value cannot be`null`. |

### partialResults

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

```
open fun partialResults(partialResults: Bundle!): Unit
```

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/kotlin/android/speech/RecognitionService.Callback#beginningOfSpeech())and[results(android.os.Bundle)](https://developer.android.com/reference/kotlin/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/kotlin/android/speech/SpeechRecognizer#startListening(android.content.Intent)), depending on the speech recognition service implementation.

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

### readyForSpeech

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

```
open fun readyForSpeech(params: Bundle!): Unit
```

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

|                                                                           Parameters                                                                            ||
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| `params` | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)!:parameters set by the recognition service. Reserved for future use. |

### results

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

```
open fun results(results: Bundle!): Unit
```

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

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

### rmsChanged

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

```
open fun rmsChanged(rmsdB: Float): Unit
```

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.

|                                                  Parameters                                                  ||
|---------|-----------------------------------------------------------------------------------------------------|
| `rmsdB` | [Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html):the new RMS dB value |

### segmentResults

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

```
open fun segmentResults(results: Bundle): Unit
```

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

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