public
class
RecognizerIntent
extends Object
java.lang.Object | |
↳ | android.speech.RecognizerIntent |
Constants for supporting speech recognition through starting an Intent
Constants | |
---|---|
String |
ACTION_GET_LANGUAGE_DETAILS
A broadcast intent which can be fired to the |
String |
ACTION_RECOGNIZE_SPEECH
Starts an activity that will prompt the user for speech and send it through a speech recognizer. |
String |
ACTION_VOICE_SEARCH_HANDS_FREE
Starts an activity that will prompt the user for speech without requiring the user's visual attention or touch input. |
String |
ACTION_WEB_SEARCH
Starts an activity that will prompt the user for speech, send it through a speech recognizer, and either display a web search result or trigger another type of action based on the user's speech. |
String |
DETAILS_META_DATA
Meta-data name under which an |
String |
EXTRA_CALLING_PACKAGE
The extra key used in an intent to the speech recognizer for voice search. |
String |
EXTRA_CONFIDENCE_SCORES
A float array of confidence scores of the recognition results when performing
|
String |
EXTRA_LANGUAGE
Optional IETF language tag (as defined by BCP 47), for example "en-US". |
String |
EXTRA_LANGUAGE_MODEL
Informs the recognizer which speech model to prefer when performing
|
String |
EXTRA_LANGUAGE_PREFERENCE
The key to the extra in the |
String |
EXTRA_MAX_RESULTS
Optional limit on the maximum number of results to return. |
String |
EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE
Specify this boolean extra in a broadcast of |
String |
EXTRA_ORIGIN
Optional value which can be used to indicate the referer url of a page in which speech was requested. |
String |
EXTRA_PARTIAL_RESULTS
Optional boolean to indicate whether partial results should be returned by the recognizer as the user speaks (default is false). |
String |
EXTRA_PREFER_OFFLINE
Optional boolean, to be used with |
String |
EXTRA_PROMPT
Optional text prompt to show to the user when asking them to speak. |
String |
EXTRA_RESULTS
An ArrayList<String> of the recognition results when performing
|
String |
EXTRA_RESULTS_PENDINGINTENT
When the intent is |
String |
EXTRA_RESULTS_PENDINGINTENT_BUNDLE
If you use |
String |
EXTRA_SECURE
Optional boolean to indicate that a "hands free" voice search was performed while the device was in a secure mode. |
String |
EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS
The amount of time that it should take after we stop hearing speech to consider the input complete. |
String |
EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS
The minimum length of an utterance. |
String |
EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS
The amount of time that it should take after we stop hearing speech to consider the input possibly complete. |
String |
EXTRA_SUPPORTED_LANGUAGES
The key to the extra in the |
String |
EXTRA_WEB_SEARCH_ONLY
Optional boolean, to be used with |
String |
LANGUAGE_MODEL_FREE_FORM
Use a language model based on free-form speech recognition. |
String |
LANGUAGE_MODEL_WEB_SEARCH
Use a language model based on web search terms. |
int |
RESULT_AUDIO_ERROR
Result code returned when an audio error was encountered |
int |
RESULT_CLIENT_ERROR
Result code returned when there is a generic client error |
int |
RESULT_NETWORK_ERROR
Result code returned when a network error was encountered |
int |
RESULT_NO_MATCH
Result code returned when no matches are found for the given speech |
int |
RESULT_SERVER_ERROR
Result code returned when the recognition server returns an error |
Public methods | |
---|---|
static
final
Intent
|
getVoiceDetailsIntent(Context context)
Returns the broadcast intent to fire with
|
Inherited methods | |
---|---|
From
class
java.lang.Object
|
String ACTION_GET_LANGUAGE_DETAILS
A broadcast intent which can be fired to the BroadcastReceiver
component specified
in the meta-data defined in the DETAILS_META_DATA
meta-data of an
Activity
satisfying ACTION_WEB_SEARCH
.
When fired with
sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler, int, String, android.os.Bundle)
,
a Bundle
of extras will be returned to the provided result receiver, and should
ideally contain values for EXTRA_LANGUAGE_PREFERENCE
and
EXTRA_SUPPORTED_LANGUAGES
.
(Whether these are actually provided is up to the particular implementation. It is
recommended that Activity
s implementing ACTION_WEB_SEARCH
provide this
information, but it is not required.)
Constant Value: "android.speech.action.GET_LANGUAGE_DETAILS"
String ACTION_RECOGNIZE_SPEECH
Starts an activity that will prompt the user for speech and send it through a
speech recognizer. The results will be returned via activity results (in
onActivityResult(int, int, Intent)
, if you start the intent using
startActivityForResult(Intent, int)
), or forwarded via a PendingIntent
if one is provided.
Starting this intent with just startActivity(Intent)
is not supported.
You must either use startActivityForResult(Intent, int)
, or provide a
PendingIntent, to receive recognition results.
The implementation of this API is likely to stream audio to remote servers to perform speech recognition which can use a substantial amount of bandwidth.
Required extras:
Optional extras:
EXTRA_PROMPT
EXTRA_LANGUAGE
EXTRA_MAX_RESULTS
EXTRA_RESULTS_PENDINGINTENT
EXTRA_RESULTS_PENDINGINTENT_BUNDLE
Result extras (returned in the result, not to be specified in the request):
NOTE: There may not be any applications installed to handle this action, so you should
make sure to catch ActivityNotFoundException
.
Constant Value: "android.speech.action.RECOGNIZE_SPEECH"
String ACTION_VOICE_SEARCH_HANDS_FREE
Starts an activity that will prompt the user for speech without requiring the user's
visual attention or touch input. It will send it through a speech recognizer,
and either synthesize speech for a web search result or trigger
another type of action based on the user's speech.
This activity may be launched while device is locked in a secure mode.
Special care must be taken to ensure that the voice actions that are performed while
hands free cannot compromise the device's security.
The activity should check the value of the EXTRA_SECURE
extra to determine
whether the device has been securely locked. If so, the activity should either restrict
the set of voice actions that are permitted or require some form of secure
authentication before proceeding.
To ensure that the activity's user interface is visible while the lock screen is showing,
the activity should set the
FLAG_SHOW_WHEN_LOCKED
window flag.
Otherwise the activity's user interface may be hidden by the lock screen. The activity
should take care not to leak private information when the device is securely locked.
Optional extras:
Constant Value: "android.speech.action.VOICE_SEARCH_HANDS_FREE"
String ACTION_WEB_SEARCH
Starts an activity that will prompt the user for speech, send it through a speech recognizer, and either display a web search result or trigger another type of action based on the user's speech.
If you want to avoid triggering any type of action besides web search, you can use
the EXTRA_WEB_SEARCH_ONLY
extra.
Required extras:
Optional extras:
EXTRA_PROMPT
EXTRA_LANGUAGE
EXTRA_MAX_RESULTS
EXTRA_PARTIAL_RESULTS
EXTRA_WEB_SEARCH_ONLY
EXTRA_ORIGIN
Result extras (returned in the result, not to be specified in the request):
EXTRA_RESULTS
EXTRA_CONFIDENCE_SCORES
(optional)
NOTE: There may not be any applications installed to handle this action, so you should
make sure to catch ActivityNotFoundException
.
Constant Value: "android.speech.action.WEB_SEARCH"
String DETAILS_META_DATA
Meta-data name under which an Activity
implementing ACTION_WEB_SEARCH
can
use to expose the class name of a BroadcastReceiver
which can respond to request for
more information, from any of the broadcast intents specified in this class.
Broadcast intents can be directed to the class name specified in the meta-data by creating
an Intent
, setting the component with
setComponent(android.content.ComponentName)
, and using
sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler, int, String, android.os.Bundle)
with another BroadcastReceiver
which can receive the results.
The getVoiceDetailsIntent(Context)
method is provided as a convenience to create
a broadcast intent based on the value of this meta-data, if available.
This is optional and not all Activity
s which implement ACTION_WEB_SEARCH
are required to implement this. Thus retrieving this meta-data may be null.
Constant Value: "android.speech.DETAILS"
String EXTRA_CALLING_PACKAGE
The extra key used in an intent to the speech recognizer for voice search. Not generally to be used by developers. The system search dialog uses this, for example, to set a calling package for identification by a voice search API. If this extra is set by anyone but the system process, it should be overridden by the voice search implementation.
Constant Value: "calling_package"
String EXTRA_CONFIDENCE_SCORES
A float array of confidence scores of the recognition results when performing
ACTION_RECOGNIZE_SPEECH
. The array should be the same size as the ArrayList
returned in EXTRA_RESULTS
, and should contain values ranging from 0.0 to 1.0,
or -1 to represent an unavailable confidence score.
Confidence values close to 1.0 indicate high confidence (the speech recognizer is confident that the recognition result is correct), while values close to 0.0 indicate low confidence.
Returned in the results; not to be specified in the recognition request. This extra is
optional and might not be provided. Only present when RESULT_OK
is
returned in an activity result.
Constant Value: "android.speech.extra.CONFIDENCE_SCORES"
String EXTRA_LANGUAGE
Optional IETF language tag (as defined by BCP 47), for example "en-US". This tag informs the
recognizer to perform speech recognition in a language different than the one set in the
getDefault()
.
Constant Value: "android.speech.extra.LANGUAGE"
String EXTRA_LANGUAGE_MODEL
Informs the recognizer which speech model to prefer when performing
ACTION_RECOGNIZE_SPEECH
. The recognizer uses this
information to fine tune the results. This extra is required. Activities implementing
ACTION_RECOGNIZE_SPEECH
may interpret the values as they see fit.
Constant Value: "android.speech.extra.LANGUAGE_MODEL"
String EXTRA_LANGUAGE_PREFERENCE
The key to the extra in the Bundle
returned by ACTION_GET_LANGUAGE_DETAILS
which is a String
that represents the current language preference this user has
specified - a locale string like "en-US".
Constant Value: "android.speech.extra.LANGUAGE_PREFERENCE"
String EXTRA_MAX_RESULTS
Optional limit on the maximum number of results to return. If omitted the recognizer will choose how many results to return. Must be an integer.
Constant Value: "android.speech.extra.MAX_RESULTS"
String EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE
Specify this boolean extra in a broadcast of ACTION_GET_LANGUAGE_DETAILS
to
indicate that only the current language preference is needed in the response. This
avoids any additional computation if all you need is EXTRA_LANGUAGE_PREFERENCE
in the response.
Constant Value: "android.speech.extra.ONLY_RETURN_LANGUAGE_PREFERENCE"
String EXTRA_ORIGIN
Optional value which can be used to indicate the referer url of a page in which speech was requested. For example, a web browser may choose to provide this for uses of speech on a given page.
Constant Value: "android.speech.extra.ORIGIN"
String EXTRA_PARTIAL_RESULTS
Optional boolean to indicate whether partial results should be returned by the recognizer as the user speaks (default is false). The server may ignore a request for partial results in some or all cases.
Constant Value: "android.speech.extra.PARTIAL_RESULTS"
String EXTRA_PREFER_OFFLINE
Optional boolean, to be used with ACTION_RECOGNIZE_SPEECH
,
ACTION_VOICE_SEARCH_HANDS_FREE
, ACTION_WEB_SEARCH
to indicate whether to
only use an offline speech recognition engine. The default is false, meaning that either
network or offline recognition engines may be used.
Constant Value: "android.speech.extra.PREFER_OFFLINE"
String EXTRA_PROMPT
Optional text prompt to show to the user when asking them to speak.
Constant Value: "android.speech.extra.PROMPT"
String EXTRA_RESULTS
An ArrayList<String> of the recognition results when performing
ACTION_RECOGNIZE_SPEECH
. Generally this list should be ordered in
descending order of speech recognizer confidence. (See EXTRA_CONFIDENCE_SCORES
).
Returned in the results; not to be specified in the recognition request. Only present
when RESULT_OK
is returned in an activity result. In a PendingIntent,
the lack of this extra indicates failure.
Constant Value: "android.speech.extra.RESULTS"
String EXTRA_RESULTS_PENDINGINTENT
When the intent is ACTION_RECOGNIZE_SPEECH
, the speech input activity will
return results to you via the activity results mechanism. Alternatively, if you use this
extra to supply a PendingIntent, the results will be added to its bundle and the
PendingIntent will be sent to its target.
Constant Value: "android.speech.extra.RESULTS_PENDINGINTENT"
String EXTRA_RESULTS_PENDINGINTENT_BUNDLE
If you use EXTRA_RESULTS_PENDINGINTENT
to supply a forwarding intent, you can
also use this extra to supply additional extras for the final intent. The search results
will be added to this bundle, and the combined bundle will be sent to the target.
Constant Value: "android.speech.extra.RESULTS_PENDINGINTENT_BUNDLE"
String EXTRA_SECURE
Optional boolean to indicate that a "hands free" voice search was performed while the device was in a secure mode. An example of secure mode is when the device's screen lock is active, and it requires some form of authentication to be unlocked. When the device is securely locked, the voice search activity should either restrict the set of voice actions that are permitted, or require some form of secure authentication before proceeding.
Constant Value: "android.speech.extras.EXTRA_SECURE"
String EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS
The amount of time that it should take after we stop hearing speech to consider the input complete. Note that it is extremely rare you'd want to specify this value in an intent. If you don't have a very good reason to change these, you should leave them as they are. Note also that certain values may cause undesired or unexpected results - use judiciously! Additionally, depending on the recognizer implementation, these values may have no effect.
Constant Value: "android.speech.extras.SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS"
String EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS
The minimum length of an utterance. We will not stop recording before this amount of time. Note that it is extremely rare you'd want to specify this value in an intent. If you don't have a very good reason to change these, you should leave them as they are. Note also that certain values may cause undesired or unexpected results - use judiciously! Additionally, depending on the recognizer implementation, these values may have no effect.
Constant Value: "android.speech.extras.SPEECH_INPUT_MINIMUM_LENGTH_MILLIS"
String EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS
The amount of time that it should take after we stop hearing speech to consider the input possibly complete. This is used to prevent the endpointer cutting off during very short mid-speech pauses. Note that it is extremely rare you'd want to specify this value in an intent. If you don't have a very good reason to change these, you should leave them as they are. Note also that certain values may cause undesired or unexpected results - use judiciously! Additionally, depending on the recognizer implementation, these values may have no effect.
Constant Value: "android.speech.extras.SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS"
String EXTRA_SUPPORTED_LANGUAGES
The key to the extra in the Bundle
returned by ACTION_GET_LANGUAGE_DETAILS
which is an ArrayList
of String
s that represents the languages supported by
this implementation of voice recognition - a list of strings like "en-US", "cmn-Hans-CN",
etc.
Constant Value: "android.speech.extra.SUPPORTED_LANGUAGES"
String EXTRA_WEB_SEARCH_ONLY
Optional boolean, to be used with ACTION_WEB_SEARCH
, to indicate whether to
only fire web searches in response to a user's speech. The default is false, meaning
that other types of actions can be taken based on the user's speech.
Constant Value: "android.speech.extra.WEB_SEARCH_ONLY"
String LANGUAGE_MODEL_FREE_FORM
Use a language model based on free-form speech recognition. This is a value to use for
EXTRA_LANGUAGE_MODEL
.
See also:
Constant Value: "free_form"
String LANGUAGE_MODEL_WEB_SEARCH
Use a language model based on web search terms. This is a value to use for
EXTRA_LANGUAGE_MODEL
.
See also:
Constant Value: "web_search"
int RESULT_AUDIO_ERROR
Result code returned when an audio error was encountered
Constant Value: 5 (0x00000005)
int RESULT_CLIENT_ERROR
Result code returned when there is a generic client error
Constant Value: 2 (0x00000002)
int RESULT_NETWORK_ERROR
Result code returned when a network error was encountered
Constant Value: 4 (0x00000004)
int RESULT_NO_MATCH
Result code returned when no matches are found for the given speech
Constant Value: 1 (0x00000001)
int RESULT_SERVER_ERROR
Result code returned when the recognition server returns an error
Constant Value: 3 (0x00000003)
Intent getVoiceDetailsIntent (Context context)
Returns the broadcast intent to fire with
sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler, int, String, Bundle)
to receive details from the package that implements voice search.
This is based on the value specified by the voice search Activity
in
DETAILS_META_DATA
, and if this is not specified, will return null. Also if there
is no chosen default to resolve for ACTION_WEB_SEARCH
, this will return null.
If an intent is returned and is fired, a Bundle
of extras will be returned to the
provided result receiver, and should ideally contain values for
EXTRA_LANGUAGE_PREFERENCE
and EXTRA_SUPPORTED_LANGUAGES
.
(Whether these are actually provided is up to the particular implementation. It is
recommended that Activity
s implementing ACTION_WEB_SEARCH
provide this
information, but it is not required.)
Parameters | |
---|---|
context |
Context :
a context object |
Returns | |
---|---|
Intent |
the broadcast intent to fire or null if not available |