Callback
open class Callback
kotlin.Any | |
↳ | 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)
method. Recognizers may call these methods on any thread.
Summary
Public methods | |
---|---|
open Unit |
The service should call this method when the user has started to speak. |
open Unit |
bufferReceived(buffer: ByteArray!) The service should call this method when sound has been received. |
open Unit |
The service should call this method to end a segmented session. |
open Unit |
The service should call this method after the user stops speaking. |
open Unit |
The service should call this method when a network or recognition error occurred. |
open AttributionSource |
Gets the permission identity of the calling app. |
open Int |
Return the Linux uid assigned to the process that sent you the current transaction that is being processed. |
open Unit |
languageDetection(results: Bundle) The service should call this method when the language detection (and switching) results are available. |
open Unit |
partialResults(partialResults: Bundle!) The service should call this method when partial recognition results are available. |
open Unit |
readyForSpeech(params: Bundle!) The service should call this method when the endpointer is ready for the user to start speaking. |
open Unit |
The service should call this method when recognition results are ready. |
open Unit |
rmsChanged(rmsdB: Float) The service should call this method when the sound level in the audio stream has changed. |
open Unit |
segmentResults(results: Bundle) The service should call this method for each ready segment of a long recognition session. |
Public methods
beginningOfSpeech
open fun beginningOfSpeech(): Unit
The service should call this method when the user has started to speak.
bufferReceived
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!: a buffer containing a sequence of big-endian 16-bit integers representing a single channel audio stream. The sample rate is implementation dependent. |
endOfSegmentedSession
open fun endOfSegmentedSession(): Unit
The service should call this method to end a segmented session.
endOfSpeech
open fun endOfSpeech(): Unit
The service should call this method after the user stops speaking.
error
open fun error(error: Int): Unit
The service should call this method when a network or recognition error occurred.
getCallingAttributionSource
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)
and passing this identity to android.content.ContextParams.Builder#setNextAttributionSource(AttributionSource)
.
Return | |
---|---|
AttributionSource |
The permission identity of the calling app. This value cannot be null . |
getCallingUid
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()
.
languageDetection
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()
and endOfSpeech()
, depending on the speech recognition service implementation.
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 |
partialResults
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()
and 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)
, depending on the speech recognition service implementation.
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 |
readyForSpeech
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!: parameters set by the recognition service. Reserved for future use. |
results
open fun results(results: Bundle!): Unit
The service should call this method when recognition results are ready.
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 |
rmsChanged
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: the new RMS dB value |
segmentResults
open fun segmentResults(results: Bundle): Unit
The service should call this method for each ready segment of a long recognition 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 This value cannot be null . |