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 17 package android.speech; 18 19 import static android.speech.flags.Flags.FLAG_MULTILANG_EXTRA_LAUNCH; 20 21 import android.annotation.FlaggedApi; 22 import android.app.Activity; 23 import android.content.ActivityNotFoundException; 24 import android.content.BroadcastReceiver; 25 import android.content.ComponentName; 26 import android.content.Context; 27 import android.content.Intent; 28 import android.content.pm.PackageManager; 29 import android.content.pm.ResolveInfo; 30 import android.os.Bundle; 31 32 import java.util.ArrayList; 33 34 /** 35 * Constants for supporting speech recognition through starting an {@link Intent} 36 */ 37 public class RecognizerIntent { 38 RecognizerIntent()39 private RecognizerIntent() { 40 // Not for instantiating. 41 } 42 43 /** 44 * Starts an activity that will prompt the user for speech and send it through a 45 * speech recognizer. The results will be returned via activity results (in 46 * {@link Activity#onActivityResult}, if you start the intent using 47 * {@link Activity#startActivityForResult(Intent, int)}), or forwarded via a PendingIntent 48 * if one is provided. 49 * 50 * <p>Starting this intent with just {@link Activity#startActivity(Intent)} is not supported. 51 * You must either use {@link Activity#startActivityForResult(Intent, int)}, or provide a 52 * PendingIntent, to receive recognition results. 53 * 54 * <p>The implementation of this API is likely to stream audio to remote servers to perform 55 * speech recognition which can use a substantial amount of bandwidth. 56 * 57 * <p>Required extras: 58 * <ul> 59 * <li>{@link #EXTRA_LANGUAGE_MODEL} 60 * </ul> 61 * 62 * <p>Optional extras: 63 * <ul> 64 * <li>{@link #EXTRA_PROMPT} 65 * <li>{@link #EXTRA_LANGUAGE} 66 * <li>{@link #EXTRA_MAX_RESULTS} 67 * <li>{@link #EXTRA_RESULTS_PENDINGINTENT} 68 * <li>{@link #EXTRA_RESULTS_PENDINGINTENT_BUNDLE} 69 * </ul> 70 * 71 * <p> Result extras (returned in the result, not to be specified in the request): 72 * <ul> 73 * <li>{@link #EXTRA_RESULTS} 74 * </ul> 75 * 76 * <p>NOTE: There may not be any applications installed to handle this action, so you should 77 * make sure to catch {@link ActivityNotFoundException}. 78 */ 79 public static final String ACTION_RECOGNIZE_SPEECH = "android.speech.action.RECOGNIZE_SPEECH"; 80 81 /** 82 * Starts an activity that will prompt the user for speech, send it through a 83 * speech recognizer, and either display a web search result or trigger 84 * another type of action based on the user's speech. 85 * 86 * <p>If you want to avoid triggering any type of action besides web search, you can use 87 * the {@link #EXTRA_WEB_SEARCH_ONLY} extra. 88 * 89 * <p>Required extras: 90 * <ul> 91 * <li>{@link #EXTRA_LANGUAGE_MODEL} 92 * </ul> 93 * 94 * <p>Optional extras: 95 * <ul> 96 * <li>{@link #EXTRA_PROMPT} 97 * <li>{@link #EXTRA_LANGUAGE} 98 * <li>{@link #EXTRA_MAX_RESULTS} 99 * <li>{@link #EXTRA_PARTIAL_RESULTS} 100 * <li>{@link #EXTRA_WEB_SEARCH_ONLY} 101 * <li>{@link #EXTRA_ORIGIN} 102 * </ul> 103 * 104 * <p> Result extras (returned in the result, not to be specified in the request): 105 * <ul> 106 * <li>{@link #EXTRA_RESULTS} 107 * <li>{@link #EXTRA_CONFIDENCE_SCORES} (optional) 108 * </ul> 109 * 110 * <p>NOTE: There may not be any applications installed to handle this action, so you should 111 * make sure to catch {@link ActivityNotFoundException}. 112 */ 113 public static final String ACTION_WEB_SEARCH = "android.speech.action.WEB_SEARCH"; 114 115 /** 116 * Starts an activity that will prompt the user for speech without requiring the user's 117 * visual attention or touch input. It will send it through a speech recognizer, 118 * and either synthesize speech for a web search result or trigger 119 * another type of action based on the user's speech. 120 * 121 * This activity may be launched while device is locked in a secure mode. 122 * Special care must be taken to ensure that the voice actions that are performed while 123 * hands free cannot compromise the device's security. 124 * The activity should check the value of the {@link #EXTRA_SECURE} extra to determine 125 * whether the device has been securely locked. If so, the activity should either restrict 126 * the set of voice actions that are permitted or require some form of secure 127 * authentication before proceeding. 128 * 129 * To ensure that the activity's user interface is visible while the lock screen is showing, 130 * the activity should set the 131 * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} window flag. 132 * Otherwise the activity's user interface may be hidden by the lock screen. The activity 133 * should take care not to leak private information when the device is securely locked. 134 * 135 * <p>Optional extras: 136 * <ul> 137 * <li>{@link #EXTRA_SECURE} 138 * </ul> 139 * 140 * <p class="note"> 141 * In some cases, a matching Activity may not exist, so ensure you 142 * safeguard against this. 143 */ 144 public static final String ACTION_VOICE_SEARCH_HANDS_FREE = 145 "android.speech.action.VOICE_SEARCH_HANDS_FREE"; 146 147 /** 148 * Optional {@link android.os.ParcelFileDescriptor} pointing to an already opened audio 149 * source for the recognizer to use. The caller of the recognizer is responsible for closing 150 * the audio. If this extra is not set or the recognizer does not support this feature, the 151 * recognizer will open the mic for audio and close it when the recognition is finished. 152 * 153 * <p>Along with this extra, please send {@link #EXTRA_AUDIO_SOURCE_CHANNEL_COUNT}, 154 * {@link #EXTRA_AUDIO_SOURCE_ENCODING}, and {@link #EXTRA_AUDIO_SOURCE_SAMPLING_RATE} 155 * extras, otherwise the default values of these extras will be used. 156 * 157 * <p>Additionally, {@link #EXTRA_ENABLE_BIASING_DEVICE_CONTEXT} may have no effect when this 158 * extra is set. 159 * 160 * <p>This can also be used as the string value for {@link #EXTRA_SEGMENTED_SESSION} to 161 * enable segmented session mode. The audio must be passed in using this extra. The 162 * recognition session will end when and only when the audio is closed. 163 * 164 * @see #EXTRA_SEGMENTED_SESSION 165 */ 166 public static final String EXTRA_AUDIO_SOURCE = "android.speech.extra.AUDIO_SOURCE"; 167 168 /** 169 * Optional integer, to be used with {@link #EXTRA_AUDIO_SOURCE}, to indicate the number of 170 * channels in the audio. The default value is 1. 171 */ 172 public static final String EXTRA_AUDIO_SOURCE_CHANNEL_COUNT = 173 "android.speech.extra.AUDIO_SOURCE_CHANNEL_COUNT"; 174 175 /** 176 * Optional integer (from {@link android.media.AudioFormat}), to be used with 177 * {@link #EXTRA_AUDIO_SOURCE}, to indicate the audio encoding. The default value is 178 * {@link android.media.AudioFormat#ENCODING_PCM_16BIT}. 179 */ 180 public static final String EXTRA_AUDIO_SOURCE_ENCODING = 181 "android.speech.extra.AUDIO_SOURCE_ENCODING"; 182 183 /** 184 * Optional integer, to be used with {@link #EXTRA_AUDIO_SOURCE}, to indicate the sampling 185 * rate of the audio. The default value is 16000. 186 */ 187 public static final String EXTRA_AUDIO_SOURCE_SAMPLING_RATE = 188 "android.speech.extra.AUDIO_SOURCE_SAMPLING_RATE"; 189 190 /** 191 * Optional boolean to enable biasing towards device context. The recognizer will use the 192 * device context to tune the recognition results. 193 * 194 * <p>Depending on the recognizer implementation, this value may have no effect. 195 */ 196 public static final String EXTRA_ENABLE_BIASING_DEVICE_CONTEXT = 197 "android.speech.extra.ENABLE_BIASING_DEVICE_CONTEXT"; 198 199 /** 200 * Optional list of strings, towards which the recognizer should bias the recognition results. 201 * These are separate from the device context. 202 */ 203 public static final String EXTRA_BIASING_STRINGS = "android.speech.extra.BIASING_STRINGS"; 204 205 /** 206 * Optional string to enable text formatting (e.g. unspoken punctuation (examples: question 207 * mark, comma, period, etc.), capitalization, etc.) and specify the optimization strategy. 208 * If set, the partial and final result texts will be formatted. Each result list will 209 * contain two hypotheses in the order of 1) formatted text 2) raw text. 210 * 211 * <p>Depending on the recognizer implementation, this value may have no effect. 212 * 213 * @see #FORMATTING_OPTIMIZE_QUALITY 214 * @see #FORMATTING_OPTIMIZE_LATENCY 215 */ 216 public static final String EXTRA_ENABLE_FORMATTING = "android.speech.extra.ENABLE_FORMATTING"; 217 218 /** 219 * Optimizes formatting quality. This will increase latency but provide the highest 220 * punctuation quality. This is a value to use for {@link #EXTRA_ENABLE_FORMATTING}. 221 * 222 * @see #EXTRA_ENABLE_FORMATTING 223 */ 224 public static final String FORMATTING_OPTIMIZE_QUALITY = "quality"; 225 /** 226 * Optimizes formatting latency. This will result in a slightly lower quality of punctuation 227 * but can improve the experience for real-time use cases. This is a value to use for 228 * {@link #EXTRA_ENABLE_FORMATTING}. 229 * 230 * @see #EXTRA_ENABLE_FORMATTING 231 */ 232 public static final String FORMATTING_OPTIMIZE_LATENCY = "latency"; 233 234 /** 235 * Optional boolean, to be used with {@link #EXTRA_ENABLE_FORMATTING}, to prevent the 236 * recognizer adding punctuation after the last word of the partial results. The default is 237 * false. 238 */ 239 public static final String EXTRA_HIDE_PARTIAL_TRAILING_PUNCTUATION = 240 "android.speech.extra.HIDE_PARTIAL_TRAILING_PUNCTUATION"; 241 242 /** 243 * Optional boolean indicating whether the recognizer should mask the offensive words in 244 * recognition results. The Default is true. 245 */ 246 public static final String EXTRA_MASK_OFFENSIVE_WORDS = 247 "android.speech.extra.MASK_OFFENSIVE_WORDS"; 248 249 /** 250 * The extra key used in an intent to the speech recognizer for voice search. Not 251 * generally to be used by developers. The system search dialog uses this, for example, 252 * to set a calling package for identification by a voice search API. If this extra 253 * is set by anyone but the system process, it should be overridden by the voice search 254 * implementation. 255 */ 256 public static final String EXTRA_CALLING_PACKAGE = "calling_package"; 257 258 /** 259 * The extra key used in an intent which is providing an already opened audio source for the 260 * RecognitionService to use. Data should be a URI to an audio resource. 261 * 262 * <p>Depending on the recognizer implementation, this value may have no effect. 263 * 264 * @deprecated Replaced with {@link #EXTRA_AUDIO_SOURCE} 265 */ 266 @Deprecated 267 public static final String EXTRA_AUDIO_INJECT_SOURCE = 268 "android.speech.extra.AUDIO_INJECT_SOURCE"; 269 270 /** 271 * Optional boolean to indicate that a "hands free" voice search was performed while the device 272 * was in a secure mode. An example of secure mode is when the device's screen lock is active, 273 * and it requires some form of authentication to be unlocked. 274 * 275 * When the device is securely locked, the voice search activity should either restrict 276 * the set of voice actions that are permitted, or require some form of secure authentication 277 * before proceeding. 278 */ 279 public static final String EXTRA_SECURE = "android.speech.extras.EXTRA_SECURE"; 280 281 /** 282 * Optional integer to indicate the minimum length of the recognition session. The recognizer 283 * will not stop recognizing speech before this amount of time. 284 * 285 * <p>Note that it is extremely rare you'd want to specify this value in an intent. 286 * Generally, it should be specified only when it is also used as the value for 287 * {@link #EXTRA_SEGMENTED_SESSION} to enable segmented session mode. Note also that certain 288 * values may cause undesired or unexpected results - use judiciously! 289 * 290 * <p>Depending on the recognizer implementation, these values may have no effect. 291 */ 292 public static final String EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS = 293 "android.speech.extras.SPEECH_INPUT_MINIMUM_LENGTH_MILLIS"; 294 295 /** 296 * The amount of time that it should take after the recognizer stops hearing speech to 297 * consider the input complete hence end the recognition session. 298 * 299 * <p>Note that it is extremely rare you'd want to specify this value in an intent. 300 * Generally, it should be specified only when it is also used as the value for 301 * {@link #EXTRA_SEGMENTED_SESSION} to enable segmented session mode. Note also that certain 302 * values may cause undesired or unexpected results - use judiciously! 303 * 304 * <p>Depending on the recognizer implementation, these values may have no effect. 305 */ 306 public static final String EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS = 307 "android.speech.extras.SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS"; 308 309 /** 310 * The amount of time that it should take after we stop hearing speech to consider the input 311 * possibly complete. This is used to prevent the endpointer cutting off during very short 312 * mid-speech pauses. 313 * 314 * Note that it is extremely rare you'd want to specify this value in an intent. If 315 * you don't have a very good reason to change these, you should leave them as they are. Note 316 * also that certain values may cause undesired or unexpected results - use judiciously! 317 * Additionally, depending on the recognizer implementation, these values may have no effect. 318 */ 319 public static final String EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS = 320 "android.speech.extras.SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS"; 321 322 /** 323 * Informs the recognizer which speech model to prefer when performing 324 * {@link #ACTION_RECOGNIZE_SPEECH}. The recognizer uses this 325 * information to fine tune the results. This extra is required. Activities implementing 326 * {@link #ACTION_RECOGNIZE_SPEECH} may interpret the values as they see fit. 327 * 328 * @see #LANGUAGE_MODEL_FREE_FORM 329 * @see #LANGUAGE_MODEL_WEB_SEARCH 330 */ 331 public static final String EXTRA_LANGUAGE_MODEL = "android.speech.extra.LANGUAGE_MODEL"; 332 333 /** 334 * Use a language model based on free-form speech recognition. This is a value to use for 335 * {@link #EXTRA_LANGUAGE_MODEL}. 336 * @see #EXTRA_LANGUAGE_MODEL 337 */ 338 public static final String LANGUAGE_MODEL_FREE_FORM = "free_form"; 339 /** 340 * Use a language model based on web search terms. This is a value to use for 341 * {@link #EXTRA_LANGUAGE_MODEL}. 342 * @see #EXTRA_LANGUAGE_MODEL 343 */ 344 public static final String LANGUAGE_MODEL_WEB_SEARCH = "web_search"; 345 346 /** Optional text prompt to show to the user when asking them to speak. */ 347 public static final String EXTRA_PROMPT = "android.speech.extra.PROMPT"; 348 349 /** 350 * Optional IETF language tag (as defined by BCP 47), for example "en-US". This tag informs the 351 * recognizer to perform speech recognition in a language different than the one set in the 352 * {@link java.util.Locale#getDefault()}. 353 */ 354 public static final String EXTRA_LANGUAGE = "android.speech.extra.LANGUAGE"; 355 356 /** 357 * Optional value which can be used to indicate the referer url of a page in which 358 * speech was requested. For example, a web browser may choose to provide this for 359 * uses of speech on a given page. 360 */ 361 public static final String EXTRA_ORIGIN = "android.speech.extra.ORIGIN"; 362 363 /** 364 * Optional limit on the maximum number of results to return. If omitted the recognizer 365 * will choose how many results to return. Must be an integer. 366 */ 367 public static final String EXTRA_MAX_RESULTS = "android.speech.extra.MAX_RESULTS"; 368 369 /** 370 * Optional boolean, to be used with {@link #ACTION_WEB_SEARCH}, to indicate whether to 371 * only fire web searches in response to a user's speech. The default is false, meaning 372 * that other types of actions can be taken based on the user's speech. 373 */ 374 public static final String EXTRA_WEB_SEARCH_ONLY = "android.speech.extra.WEB_SEARCH_ONLY"; 375 376 /** 377 * Optional boolean to indicate whether partial results should be returned by the recognizer 378 * as the user speaks (default is false). The server may ignore a request for partial 379 * results in some or all cases. 380 */ 381 public static final String EXTRA_PARTIAL_RESULTS = "android.speech.extra.PARTIAL_RESULTS"; 382 383 /** 384 * When the intent is {@link #ACTION_RECOGNIZE_SPEECH}, the speech input activity will 385 * return results to you via the activity results mechanism. Alternatively, if you use this 386 * extra to supply a PendingIntent, the results will be added to its bundle and the 387 * PendingIntent will be sent to its target. 388 */ 389 public static final String EXTRA_RESULTS_PENDINGINTENT = 390 "android.speech.extra.RESULTS_PENDINGINTENT"; 391 392 /** 393 * If you use {@link #EXTRA_RESULTS_PENDINGINTENT} to supply a forwarding intent, you can 394 * also use this extra to supply additional extras for the final intent. The search results 395 * will be added to this bundle, and the combined bundle will be sent to the target. 396 */ 397 public static final String EXTRA_RESULTS_PENDINGINTENT_BUNDLE = 398 "android.speech.extra.RESULTS_PENDINGINTENT_BUNDLE"; 399 400 /** Result code returned when no matches are found for the given speech */ 401 public static final int RESULT_NO_MATCH = Activity.RESULT_FIRST_USER; 402 /** Result code returned when there is a generic client error */ 403 public static final int RESULT_CLIENT_ERROR = Activity.RESULT_FIRST_USER + 1; 404 /** Result code returned when the recognition server returns an error */ 405 public static final int RESULT_SERVER_ERROR = Activity.RESULT_FIRST_USER + 2; 406 /** Result code returned when a network error was encountered */ 407 public static final int RESULT_NETWORK_ERROR = Activity.RESULT_FIRST_USER + 3; 408 /** Result code returned when an audio error was encountered */ 409 public static final int RESULT_AUDIO_ERROR = Activity.RESULT_FIRST_USER + 4; 410 411 /** 412 * An ArrayList<String> of the recognition results when performing 413 * {@link #ACTION_RECOGNIZE_SPEECH}. Generally this list should be ordered in 414 * descending order of speech recognizer confidence. (See {@link #EXTRA_CONFIDENCE_SCORES}). 415 * Returned in the results; not to be specified in the recognition request. Only present 416 * when {@link Activity#RESULT_OK} is returned in an activity result. In a PendingIntent, 417 * the lack of this extra indicates failure. 418 */ 419 public static final String EXTRA_RESULTS = "android.speech.extra.RESULTS"; 420 421 /** 422 * A float array of confidence scores of the recognition results when performing 423 * {@link #ACTION_RECOGNIZE_SPEECH}. The array should be the same size as the ArrayList 424 * returned in {@link #EXTRA_RESULTS}, and should contain values ranging from 0.0 to 1.0, 425 * or -1 to represent an unavailable confidence score. 426 * <p> 427 * Confidence values close to 1.0 indicate high confidence (the speech recognizer is 428 * confident that the recognition result is correct), while values close to 0.0 indicate 429 * low confidence. 430 * <p> 431 * Returned in the results; not to be specified in the recognition request. This extra is 432 * optional and might not be provided. Only present when {@link Activity#RESULT_OK} is 433 * returned in an activity result. 434 */ 435 public static final String EXTRA_CONFIDENCE_SCORES = "android.speech.extra.CONFIDENCE_SCORES"; 436 437 /** 438 * Returns the broadcast intent to fire with 439 * {@link Context#sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler, int, String, Bundle)} 440 * to receive details from the package that implements voice search. 441 * <p> 442 * This is based on the value specified by the voice search {@link Activity} in 443 * {@link #DETAILS_META_DATA}, and if this is not specified, will return null. Also if there 444 * is no chosen default to resolve for {@link #ACTION_WEB_SEARCH}, this will return null. 445 * <p> 446 * If an intent is returned and is fired, a {@link Bundle} of extras will be returned to the 447 * provided result receiver, and should ideally contain values for 448 * {@link #EXTRA_LANGUAGE_PREFERENCE} and {@link #EXTRA_SUPPORTED_LANGUAGES}. 449 * <p> 450 * (Whether these are actually provided is up to the particular implementation. It is 451 * recommended that {@link Activity}s implementing {@link #ACTION_WEB_SEARCH} provide this 452 * information, but it is not required.) 453 * 454 * @param context a context object 455 * @return the broadcast intent to fire or null if not available 456 */ getVoiceDetailsIntent(Context context)457 public static final Intent getVoiceDetailsIntent(Context context) { 458 Intent voiceSearchIntent = new Intent(ACTION_WEB_SEARCH); 459 ResolveInfo ri = context.getPackageManager().resolveActivity( 460 voiceSearchIntent, PackageManager.GET_META_DATA); 461 if (ri == null || ri.activityInfo == null || ri.activityInfo.metaData == null) return null; 462 463 String className = ri.activityInfo.metaData.getString(DETAILS_META_DATA); 464 if (className == null) return null; 465 466 Intent detailsIntent = new Intent(ACTION_GET_LANGUAGE_DETAILS); 467 detailsIntent.setComponent(new ComponentName(ri.activityInfo.packageName, className)); 468 return detailsIntent; 469 } 470 471 /** 472 * Meta-data name under which an {@link Activity} implementing {@link #ACTION_WEB_SEARCH} can 473 * use to expose the class name of a {@link BroadcastReceiver} which can respond to request for 474 * more information, from any of the broadcast intents specified in this class. 475 * <p> 476 * Broadcast intents can be directed to the class name specified in the meta-data by creating 477 * an {@link Intent}, setting the component with 478 * {@link Intent#setComponent(android.content.ComponentName)}, and using 479 * {@link Context#sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler, int, String, android.os.Bundle)} 480 * with another {@link BroadcastReceiver} which can receive the results. 481 * <p> 482 * The {@link #getVoiceDetailsIntent(Context)} method is provided as a convenience to create 483 * a broadcast intent based on the value of this meta-data, if available. 484 * <p> 485 * This is optional and not all {@link Activity}s which implement {@link #ACTION_WEB_SEARCH} 486 * are required to implement this. Thus retrieving this meta-data may be null. 487 */ 488 public static final String DETAILS_META_DATA = "android.speech.DETAILS"; 489 490 /** 491 * A broadcast intent which can be fired to the {@link BroadcastReceiver} component specified 492 * in the meta-data defined in the {@link #DETAILS_META_DATA} meta-data of an 493 * {@link Activity} satisfying {@link #ACTION_WEB_SEARCH}. 494 * <p> 495 * When fired with 496 * {@link Context#sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler, int, String, android.os.Bundle)}, 497 * a {@link Bundle} of extras will be returned to the provided result receiver, and should 498 * ideally contain values for {@link #EXTRA_LANGUAGE_PREFERENCE} and 499 * {@link #EXTRA_SUPPORTED_LANGUAGES}. 500 * <p> 501 * (Whether these are actually provided is up to the particular implementation. It is 502 * recommended that {@link Activity}s implementing {@link #ACTION_WEB_SEARCH} provide this 503 * information, but it is not required.) 504 */ 505 public static final String ACTION_GET_LANGUAGE_DETAILS = 506 "android.speech.action.GET_LANGUAGE_DETAILS"; 507 508 /** 509 * Specify this boolean extra in a broadcast of {@link #ACTION_GET_LANGUAGE_DETAILS} to 510 * indicate that only the current language preference is needed in the response. This 511 * avoids any additional computation if all you need is {@link #EXTRA_LANGUAGE_PREFERENCE} 512 * in the response. 513 */ 514 public static final String EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE = 515 "android.speech.extra.ONLY_RETURN_LANGUAGE_PREFERENCE"; 516 517 /** 518 * The key to the extra in the {@link Bundle} returned by {@link #ACTION_GET_LANGUAGE_DETAILS} 519 * which is a {@link String} that represents the current language preference this user has 520 * specified - a locale string like "en-US". 521 */ 522 public static final String EXTRA_LANGUAGE_PREFERENCE = 523 "android.speech.extra.LANGUAGE_PREFERENCE"; 524 525 /** 526 * The key to the extra in the {@link Bundle} returned by {@link #ACTION_GET_LANGUAGE_DETAILS} 527 * which is an {@link ArrayList} of {@link String}s that represents the languages supported by 528 * this implementation of voice recognition - a list of strings like "en-US", "cmn-Hans-CN", 529 * etc. 530 */ 531 public static final String EXTRA_SUPPORTED_LANGUAGES = 532 "android.speech.extra.SUPPORTED_LANGUAGES"; 533 534 /** 535 * Optional boolean, to be used with {@link #ACTION_RECOGNIZE_SPEECH}, 536 * {@link #ACTION_VOICE_SEARCH_HANDS_FREE}, {@link #ACTION_WEB_SEARCH} to indicate whether to 537 * only use an offline speech recognition engine. The default is false, meaning that either 538 * network or offline recognition engines may be used. 539 * 540 * <p>Depending on the recognizer implementation, these values may have 541 * no effect.</p> 542 * 543 */ 544 public static final String EXTRA_PREFER_OFFLINE = "android.speech.extra.PREFER_OFFLINE"; 545 546 /** 547 * Optional string to enable segmented session mode of the specified type, which can be 548 * {@link #EXTRA_AUDIO_SOURCE}, {@link #EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS} or 549 * {@link #EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS}. When segmented session mode is 550 * supported by the recognizer implementation and this extra is set, it will return the 551 * recognition results in segments via {@link RecognitionListener#onSegmentResults(Bundle)} 552 * and terminate the session with {@link RecognitionListener#onEndOfSegmentedSession()}. 553 * 554 * <p>When setting this extra, make sure the extra used as the string value here is also set 555 * in the same intent with proper value. 556 * 557 * <p>Depending on the recognizer implementation, this value may have no effect. 558 * 559 * @see #EXTRA_AUDIO_SOURCE 560 * @see #EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS 561 * @see #EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS 562 */ 563 public static final String EXTRA_SEGMENTED_SESSION = "android.speech.extra.SEGMENTED_SESSION"; 564 565 /** 566 * Optional boolean indicating whether the recognizer should return the timestamp 567 * of each word in the final recognition results. 568 */ 569 public static final String EXTRA_REQUEST_WORD_TIMING = 570 "android.speech.extra.REQUEST_WORD_TIMING"; 571 572 /** 573 * Optional boolean indicating whether the recognizer should return the confidence 574 * level of each word in the final recognition results. 575 */ 576 public static final String EXTRA_REQUEST_WORD_CONFIDENCE = 577 "android.speech.extra.REQUEST_WORD_CONFIDENCE"; 578 579 /** 580 * Optional boolean indicating whether to enable language detection. When enabled, the 581 * recognizer will consistently identify the language of the current spoken utterance and 582 * provide that info via {@link RecognitionListener#onLanguageDetection(Bundle)}. 583 * 584 * <p> Depending on the recognizer implementation, this flag may have no effect. 585 */ 586 public static final String EXTRA_ENABLE_LANGUAGE_DETECTION = 587 "android.speech.extra.ENABLE_LANGUAGE_DETECTION"; 588 589 /** 590 * Optional list of IETF language tags (as defined by BCP 47, e.g. "en-US", "de-DE"). 591 * This extra is to be used with {@link #EXTRA_ENABLE_LANGUAGE_DETECTION}. 592 * If set, the recognizer will constrain the language detection output 593 * to this list of languages, potentially improving detection accuracy. 594 */ 595 public static final String EXTRA_LANGUAGE_DETECTION_ALLOWED_LANGUAGES = 596 "android.speech.extra.LANGUAGE_DETECTION_ALLOWED_LANGUAGES"; 597 598 /** 599 * Optional string to enable automatic switching to the language being spoken with 600 * the desired sensitivity level, instead of being restricted to a single language. 601 * The corresponding language models must be downloaded to support the switch. 602 * Otherwise, the recognizer will report an error on a switch failure. The recognizer 603 * provides the switch results via {@link RecognitionListener#onLanguageDetection(Bundle)}. 604 * 605 * <p> Since detection is a necessary requirement for the language switching, 606 * setting this value implicitly enables {@link #EXTRA_ENABLE_LANGUAGE_DETECTION}. 607 * 608 * <p> Depending on the recognizer implementation, this value may have no effect. 609 * 610 * @see #LANGUAGE_SWITCH_HIGH_PRECISION 611 * @see #LANGUAGE_SWITCH_BALANCED 612 * @see #LANGUAGE_SWITCH_QUICK_RESPONSE 613 */ 614 public static final String EXTRA_ENABLE_LANGUAGE_SWITCH = 615 "android.speech.extra.ENABLE_LANGUAGE_SWITCH"; 616 617 /** 618 * A value to use for {@link #EXTRA_ENABLE_LANGUAGE_SWITCH}. 619 * 620 * <p> Enables language switch only when a new language is detected as 621 * {@link SpeechRecognizer#LANGUAGE_DETECTION_CONFIDENCE_LEVEL_HIGHLY_CONFIDENT}, 622 * which means the service may wait for longer before switching. 623 * 624 * @see #EXTRA_ENABLE_LANGUAGE_SWITCH 625 */ 626 public static final String LANGUAGE_SWITCH_HIGH_PRECISION = "high_precision"; 627 628 /** 629 * A value to use for {@link #EXTRA_ENABLE_LANGUAGE_SWITCH}. 630 * 631 * <p> Enables language switch only when a new language is detected as at least 632 * {@link SpeechRecognizer#LANGUAGE_DETECTION_CONFIDENCE_LEVEL_CONFIDENT}, which means 633 * the service is balancing between detecting a new language confidently and switching early. 634 * 635 * @see #EXTRA_ENABLE_LANGUAGE_SWITCH 636 */ 637 public static final String LANGUAGE_SWITCH_BALANCED = "balanced"; 638 639 /** 640 * A value to use for {@link #EXTRA_ENABLE_LANGUAGE_SWITCH}. 641 * 642 * <p> Enables language switch only when a new language is detected as at least 643 * {@link SpeechRecognizer#LANGUAGE_DETECTION_CONFIDENCE_LEVEL_NOT_CONFIDENT}, 644 * which means the service should switch at the earliest moment possible. 645 * 646 * @see #EXTRA_ENABLE_LANGUAGE_SWITCH 647 */ 648 public static final String LANGUAGE_SWITCH_QUICK_RESPONSE = "quick_response"; 649 650 /** 651 * Optional list of IETF language tags (as defined by BCP 47, e.g. "en-US", "de-DE"). This extra 652 * is to be used with {@link #EXTRA_ENABLE_LANGUAGE_SWITCH}. If set, the recognizer will apply 653 * the auto switch only to these languages, even if the speech models of other languages also 654 * exist. The corresponding language models must be downloaded to support the switch. 655 * Otherwise, the recognizer will report an error on a switch failure. 656 */ 657 public static final String EXTRA_LANGUAGE_SWITCH_ALLOWED_LANGUAGES = 658 "android.speech.extra.LANGUAGE_SWITCH_ALLOWED_LANGUAGES"; 659 660 /** 661 * Optional integer to use for {@link #EXTRA_ENABLE_LANGUAGE_SWITCH}. If set, the language 662 * switch will be deactivated when LANGUAGE_SWITCH_MAX_SWITCHES reached. 663 * 664 * <p> Depending on the recognizer implementation, this flag may have no effect. 665 * 666 * @see #EXTRA_ENABLE_LANGUAGE_SWITCH 667 */ 668 @FlaggedApi(FLAG_MULTILANG_EXTRA_LAUNCH) 669 public static final String EXTRA_LANGUAGE_SWITCH_MAX_SWITCHES = 670 "android.speech.extra.LANGUAGE_SWITCH_MAX_SWITCHES"; 671 672 /** 673 * Optional integer to use for {@link #EXTRA_ENABLE_LANGUAGE_SWITCH}. If set, the language 674 * switch will only be activated for this value of ms of audio since the START_OF_SPEECH. This 675 * could provide a more stable recognition result when the language switch is only required in 676 * the beginning of the session. 677 * 678 * <p> Depending on the recognizer implementation, this flag may have no effect. 679 * 680 * @see #EXTRA_ENABLE_LANGUAGE_SWITCH 681 */ 682 @FlaggedApi(FLAG_MULTILANG_EXTRA_LAUNCH) 683 public static final String EXTRA_LANGUAGE_SWITCH_INITIAL_ACTIVE_DURATION_TIME_MILLIS = 684 "android.speech.extra.LANGUAGE_SWITCH_INITIAL_ACTIVE_DURATION_TIME_MILLIS"; 685 } 686