Added in API level 8

RecognitionListener


interface RecognitionListener
android.speech.RecognitionListener

Used for receiving notifications from the SpeechRecognizer when the recognition related events occur. All the callbacks are executed on the Application main thread.

Summary

Public methods
abstract Unit

The user has started to speak.

abstract Unit

More sound has been received.

open Unit

Called at the end of a segmented recognition request.

abstract Unit

Called after the user stops speaking.

abstract Unit
onError(error: Int)

A network or recognition error occurred.

abstract Unit
onEvent(eventType: Int, params: Bundle!)

Reserved for adding future events.

open Unit

Called when the language detection (and switching) results are available.

abstract Unit
onPartialResults(partialResults: Bundle!)

Called when partial recognition results are available.

abstract Unit

Called when the endpointer is ready for the user to start speaking.

abstract Unit
onResults(results: Bundle!)

Called when recognition results are ready.

abstract Unit

The sound level in the audio stream has changed.

open Unit
onSegmentResults(segmentResults: Bundle)

Called for each ready segment of a recognition request.

Public methods

onBeginningOfSpeech

Added in API level 8
abstract fun onBeginningOfSpeech(): Unit

The user has started to speak.

onBufferReceived

Added in API level 8
abstract fun onBufferReceived(buffer: ByteArray!): Unit

More sound has been received. The purpose of this function is to allow giving feedback to the user regarding the captured audio. There is no guarantee that this method will be called.

Parameters
buffer ByteArray!: a buffer containing a sequence of big-endian 16-bit integers representing a single channel audio stream. The sample rate is implementation dependent.

onEndOfSegmentedSession

Added in API level 33
open fun onEndOfSegmentedSession(): Unit

Called at the end of a segmented recognition request. To request segmented speech results use RecognizerIntent#EXTRA_SEGMENTED_SESSION.

onEndOfSpeech

Added in API level 8
abstract fun onEndOfSpeech(): Unit

Called after the user stops speaking.

onEvent

Added in API level 8
abstract fun onEvent(
    eventType: Int,
    params: Bundle!
): Unit

Reserved for adding future events.

Parameters
eventType Int: the type of the occurred event
params Bundle!: a Bundle containing the passed parameters

onLanguageDetection

Added in API level 34
open fun onLanguageDetection(results: Bundle): Unit

Called when the language detection (and switching) results are available. This callback can be invoked on any number of occasions at any time between onBeginningOfSpeech() and onEndOfSpeech(), depending on the speech recognition service implementation.

To request language detection, use RecognizerIntent#EXTRA_ENABLE_LANGUAGE_DETECTION.

To request automatic language switching, use RecognizerIntent#EXTRA_ENABLE_LANGUAGE_SWITCH.

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) with SpeechRecognizer#DETECTED_LANGUAGE as the parameter.

To retrieve the language detection confidence level represented by a value prefixed by LANGUAGE_DETECTION_CONFIDENCE_LEVEL_ and defined in SpeechRecognizer, use Bundle#getInt(String) with SpeechRecognizer#LANGUAGE_DETECTION_CONFIDENCE_LEVEL as the parameter.

To retrieve the alternative locales for the same language retrieved by the key SpeechRecognizer#DETECTED_LANGUAGE, use Bundle#getStringArrayList(String) with 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, use Bundle#getInt(String) with SpeechRecognizer#LANGUAGE_SWITCH_RESULT as the parameter. This value cannot be null.

onPartialResults

Added in API level 8
abstract fun onPartialResults(partialResults: Bundle!): Unit

Called when partial recognition results are available. The callback might be called at any time between onBeginningOfSpeech() and onResults(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), depending on the speech recognition service implementation. To request partial results, use RecognizerIntent#EXTRA_PARTIAL_RESULTS

Parameters
partialResults Bundle!: the returned results. To retrieve the results in ArrayList<String> format use Bundle#getStringArrayList(String) with SpeechRecognizer#RESULTS_RECOGNITION as a parameter

onReadyForSpeech

Added in API level 8
abstract fun onReadyForSpeech(params: Bundle!): Unit

Called when the endpointer is ready for the user to start speaking.

Parameters
params Bundle!: parameters set by the recognition service. Reserved for future use.

onResults

Added in API level 8
abstract fun onResults(results: Bundle!): Unit

Called when recognition results are ready.

Called with the results for the full speech since onReadyForSpeech(android.os.Bundle). To get recognition results in segments rather than for the full session see RecognizerIntent#EXTRA_SEGMENTED_SESSION.

Parameters
results Bundle!: the recognition results. To retrieve the results in ArrayList<String> format use Bundle#getStringArrayList(String) with SpeechRecognizer#RESULTS_RECOGNITION as a parameter. A float array of confidence values might also be given in SpeechRecognizer#CONFIDENCE_SCORES.

onRmsChanged

Added in API level 8
abstract fun onRmsChanged(rmsdB: Float): Unit

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

Parameters
rmsdB Float: the new RMS dB value

onSegmentResults

Added in API level 33
open fun onSegmentResults(segmentResults: Bundle): Unit

Called for each ready segment of a recognition request. To request segmented speech results use RecognizerIntent#EXTRA_SEGMENTED_SESSION. The callback might be called any number of times between onReadyForSpeech(android.os.Bundle) and onEndOfSegmentedSession().

Parameters
segmentResults Bundle: the returned results. To retrieve the results in ArrayList<String> format use Bundle#getStringArrayList(String) with SpeechRecognizer#RESULTS_RECOGNITION as a parameter This value cannot be null.