RecognizerIntent.java revision 5a346d631f99c8cb48a0963a233918f96475337e
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.speech; 18 19import android.app.Activity; 20import android.content.ActivityNotFoundException; 21import android.content.Intent; 22 23/** 24 * Constants for supporting speech recognition through starting an {@link Intent} 25 */ 26public class RecognizerIntent { 27 private RecognizerIntent() { 28 // Not for instantiating. 29 } 30 31 /** 32 * Starts an activity that will prompt the user for speech and sends it through a 33 * speech recognizer. The results will be returned via activity results (in 34 * {@link Activity#onActivityResult}, if you start the intent using 35 * {@link Activity#startActivityForResult(Intent, int)}), or forwarded via a PendingIntent 36 * if one is provided. 37 * 38 * <p>Starting this intent with just {@link Activity#startActivity(Intent)} is not supported. 39 * You must either use {@link Activity#startActivityForResult(Intent, int)}, or provide a 40 * PendingIntent, to receive recognition results. 41 * 42 * <p>Required extras: 43 * <ul> 44 * <li>{@link #EXTRA_LANGUAGE_MODEL} 45 * </ul> 46 * 47 * <p>Optional extras: 48 * <ul> 49 * <li>{@link #EXTRA_PROMPT} 50 * <li>{@link #EXTRA_LANGUAGE} 51 * <li>{@link #EXTRA_MAX_RESULTS} 52 * <li>{@link #EXTRA_RESULTS_PENDINGINTENT} 53 * <li>{@link #EXTRA_RESULTS_PENDINGINTENT_BUNDLE} 54 * </ul> 55 * 56 * <p> Result extras (returned in the result, not to be specified in the request): 57 * <ul> 58 * <li>{@link #EXTRA_RESULTS} 59 * </ul> 60 * 61 * <p>NOTE: There may not be any applications installed to handle this action, so you should 62 * make sure to catch {@link ActivityNotFoundException}. 63 */ 64 public static final String ACTION_RECOGNIZE_SPEECH = "android.speech.action.RECOGNIZE_SPEECH"; 65 66 /** 67 * Starts an activity that will prompt the user for speech, sends it through a 68 * speech recognizer, and invokes and displays a web search result. 69 * 70 * <p>Required extras: 71 * <ul> 72 * <li>{@link #EXTRA_LANGUAGE_MODEL} 73 * </ul> 74 * 75 * <p>Optional extras: 76 * <ul> 77 * <li>{@link #EXTRA_PROMPT} 78 * <li>{@link #EXTRA_LANGUAGE} 79 * <li>{@link #EXTRA_MAX_RESULTS} 80 * </ul> 81 * 82 * <p> Result extras (returned in the result, not to be specified in the request): 83 * <ul> 84 * <li>{@link #EXTRA_RESULTS} 85 * </ul> 86 * 87 * <p>NOTE: There may not be any applications installed to handle this action, so you should 88 * make sure to catch {@link ActivityNotFoundException}. 89 */ 90 public static final String ACTION_WEB_SEARCH = "android.speech.action.WEB_SEARCH"; 91 92 /** 93 * The minimum length of an utterance. We will not stop recording before this amount of time. 94 * 95 * Note that it is extremely rare you'd want to specify this value in an intent. If you don't 96 * have a very good reason to change these, you should leave them as they are. Note also that 97 * certain values may cause undesired or unexpected results - use judiciously! Additionally, 98 * depending on the recognizer implementation, these values may have no effect. 99 */ 100 public static final String EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS = 101 "android.speech.extras.SPEECH_INPUT_MINIMUM_LENGTH_MILLIS"; 102 103 /** 104 * The amount of time that it should take after we stop hearing speech to consider the input 105 * complete. 106 * 107 * Note that it is extremely rare you'd want to specify this value in an intent. If 108 * you don't have a very good reason to change these, you should leave them as they are. Note 109 * also that certain values may cause undesired or unexpected results - use judiciously! 110 * Additionally, depending on the recognizer implementation, these values may have no effect. 111 */ 112 public static final String EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS = 113 "android.speech.extras.SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS"; 114 115 /** 116 * The amount of time that it should take after we stop hearing speech to consider the input 117 * possibly complete. This is used to prevent the endpointer cutting off during very short 118 * mid-speech pauses. 119 * 120 * Note that it is extremely rare you'd want to specify this value in an intent. If 121 * you don't have a very good reason to change these, you should leave them as they are. Note 122 * also that certain values may cause undesired or unexpected results - use judiciously! 123 * Additionally, depending on the recognizer implementation, these values may have no effect. 124 */ 125 public static final String EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS = 126 "android.speech.extras.SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS"; 127 128 /** 129 * Informs the recognizer which speech model to prefer when performing 130 * {@link #ACTION_RECOGNIZE_SPEECH}. The recognizer uses this 131 * information to fine tune the results. This extra is required. Activities implementing 132 * {@link #ACTION_RECOGNIZE_SPEECH} may interpret the values as they see fit. 133 * 134 * @see #LANGUAGE_MODEL_FREE_FORM 135 * @see #LANGUAGE_MODEL_WEB_SEARCH 136 */ 137 public static final String EXTRA_LANGUAGE_MODEL = "android.speech.extra.LANGUAGE_MODEL"; 138 139 /** 140 * Use a language model based on free-form speech recognition. This is a value to use for 141 * {@link #EXTRA_LANGUAGE_MODEL}. 142 * @see #EXTRA_LANGUAGE_MODEL 143 */ 144 public static final String LANGUAGE_MODEL_FREE_FORM = "free_form"; 145 /** 146 * Use a language model based on web search terms. This is a value to use for 147 * {@link #EXTRA_LANGUAGE_MODEL}. 148 * @see #EXTRA_LANGUAGE_MODEL 149 */ 150 public static final String LANGUAGE_MODEL_WEB_SEARCH = "web_search"; 151 152 /** Optional text prompt to show to the user when asking them to speak. */ 153 public static final String EXTRA_PROMPT = "android.speech.extra.PROMPT"; 154 155 /** 156 * Optional IETF language tag (as defined by BCP 47), for example "en-US". This tag informs the 157 * recognizer to perform speech recognition in a language different than the one set in the 158 * {@link java.util.Locale#getDefault()}. 159 */ 160 public static final String EXTRA_LANGUAGE = "android.speech.extra.LANGUAGE"; 161 162 /** 163 * Optional limit on the maximum number of results to return. If omitted the recognizer 164 * will choose how many results to return. Must be an integer. 165 */ 166 public static final String EXTRA_MAX_RESULTS = "android.speech.extra.MAX_RESULTS"; 167 168 /** 169 * When the intent is {@link #ACTION_RECOGNIZE_SPEECH}, the speech input activity will 170 * return results to you via the activity results mechanism. Alternatively, if you use this 171 * extra to supply a PendingIntent, the results will be added to its bundle and the 172 * PendingIntent will be sent to its target. 173 */ 174 public static final String EXTRA_RESULTS_PENDINGINTENT = 175 "android.speech.extra.RESULTS_PENDINGINTENT"; 176 177 /** 178 * If you use {@link #EXTRA_RESULTS_PENDINGINTENT} to supply a forwarding intent, you can 179 * also use this extra to supply additional extras for the final intent. The search results 180 * will be added to this bundle, and the combined bundle will be sent to the target. 181 */ 182 public static final String EXTRA_RESULTS_PENDINGINTENT_BUNDLE = 183 "android.speech.extra.RESULTS_PENDINGINTENT_BUNDLE"; 184 185 /** Result code returned when no matches are found for the given speech */ 186 public static final int RESULT_NO_MATCH = Activity.RESULT_FIRST_USER; 187 /** Result code returned when there is a generic client error */ 188 public static final int RESULT_CLIENT_ERROR = Activity.RESULT_FIRST_USER + 1; 189 /** Result code returned when the recognition server returns an error */ 190 public static final int RESULT_SERVER_ERROR = Activity.RESULT_FIRST_USER + 2; 191 /** Result code returned when a network error was encountered */ 192 public static final int RESULT_NETWORK_ERROR = Activity.RESULT_FIRST_USER + 3; 193 /** Result code returned when an audio error was encountered */ 194 public static final int RESULT_AUDIO_ERROR = Activity.RESULT_FIRST_USER + 4; 195 196 /** 197 * An ArrayList<String> of the recognition results when performing 198 * {@link #ACTION_RECOGNIZE_SPEECH}. Returned in the results; not to be specified in the 199 * recognition request. Only present when {@link Activity#RESULT_OK} is returned in 200 * an activity result. In a PendingIntent, the lack of this extra indicates failure. 201 */ 202 public static final String EXTRA_RESULTS = "android.speech.extra.RESULTS"; 203 204 /** 205 * Triggers the voice search settings activity. 206 */ 207 public static final String ACTION_VOICE_SEARCH_SETTINGS = 208 "android.speech.action.VOICE_SEARCH_SETTINGS"; 209} 210