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 |
onBufferReceived(buffer: ByteArray!) 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 |
A network or recognition error occurred. |
abstract Unit |
Reserved for adding future events. |
open Unit |
onLanguageDetection(results: Bundle) Called when the language detection (and switching) results are available. |
abstract Unit |
onPartialResults(partialResults: Bundle!) Called when partial recognition results are available. |
abstract Unit |
onReadyForSpeech(params: Bundle!) Called when the endpointer is ready for the user to start speaking. |
abstract Unit |
Called when recognition results are ready. |
abstract Unit |
onRmsChanged(rmsdB: Float) 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
abstract fun onBeginningOfSpeech(): Unit
The user has started to speak.
onBufferReceived
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
open fun onEndOfSegmentedSession(): Unit
Called at the end of a segmented recognition request. To request segmented speech results use RecognizerIntent#EXTRA_SEGMENTED_SESSION
.
onEndOfSpeech
abstract fun onEndOfSpeech(): Unit
Called after the user stops speaking.
onError
abstract fun onError(error: Int): Unit
A network or recognition error occurred.
onEvent
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
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 To retrieve the language detection confidence level represented by a value prefixed by To retrieve the alternative locales for the same language retrieved by the key To retrieve the language switching results represented by a value prefixed by |
onPartialResults
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
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
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
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
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 . |