RecognizerIntent.java revision b798689749c64baba81f02e10cf2157c747d6b46
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 * 26 * @hide {pending API council review} 27 */ 28public class RecognizerIntent { 29 private RecognizerIntent() { 30 // Not for instantiating. 31 } 32 33 /** 34 * Starts an activity that will prompt the user for speech and sends it through a 35 * speech recognizer. 36 * 37 * <p>Required extras: 38 * <ul> 39 * <li>{@link #EXTRA_LANGUAGE_MODEL} 40 * </ul> 41 * 42 * <p>Optional extras: 43 * <ul> 44 * <li>{@link Intent#EXTRA_PROMPT} 45 * <li>{@link #EXTRA_LANGUAGE} 46 * <li>{@link #EXTRA_MAX_RESULTS} 47 * </ul> 48 * 49 * <p> Result extras: 50 * <ul> 51 * <li>{@link #EXTRA_RESULTS} 52 * </ul> 53 * 54 * <p>NOTE: There may not be any applications installed to handle this action, so you should 55 * make sure to catch {@link ActivityNotFoundException}. 56 */ 57 public static final String ACTION_RECOGNIZE_SPEECH = "android.speech.action.RECOGNIZE_SPEECH"; 58 59 /** 60 * Informs the recognizer which speech model to prefer when performing 61 * {@link #ACTION_RECOGNIZE_SPEECH}. The recognizer uses this 62 * information to fine tune the results. This extra is required. Activities implementing 63 * {@link #ACTION_RECOGNIZE_SPEECH} may interpret the values as they see fit. 64 * 65 * @see #LANGUAGE_MODEL_FREE_FORM 66 * @see #LANGUAGE_MODEL_WEB_SEARCH 67 */ 68 public static final String EXTRA_LANGUAGE_MODEL = "language_model"; 69 70 /** Free form speech recognition */ 71 public static final String LANGUAGE_MODEL_FREE_FORM = "free_form"; 72 /** Use a language model based on web search terms */ 73 public static final String LANGUAGE_MODEL_WEB_SEARCH = "web_search"; 74 75 /** Optional text prompt to show to the user when asking them to speak. */ 76 public static final String EXTRA_PROMPT = "prompt"; 77 78 /** 79 * Optional language override to inform the recognizer that it should expect speech in 80 * a language different than the one set in the {@link java.util.Locale#getDefault()}. 81 */ 82 public static final String EXTRA_LANGUAGE = "lang"; 83 84 /** 85 * Optional limit on the maximum number of results to return. If omitted the recognizer 86 * will choose how many results to return. Must be an integer. 87 */ 88 public static final String EXTRA_MAX_RESULTS = "max_results"; 89 90 /** Result code returned when no matches are found for the given speech */ 91 public static final int RESULT_NO_MATCH = Activity.RESULT_FIRST_USER; 92 /** Result code returned when there is a generic client error */ 93 public static final int RESULT_CLIENT_ERROR = Activity.RESULT_FIRST_USER + 1; 94 /** Result code returned when the recognition server returns an error */ 95 public static final int RESULT_SERVER_ERROR = Activity.RESULT_FIRST_USER + 2; 96 /** Result code returned when a network error was encountered */ 97 public static final int RESULT_NETWORK_ERROR = Activity.RESULT_FIRST_USER + 3; 98 /** Result code returned when an audio error was encountered */ 99 public static final int RESULT_AUDIO_ERROR = Activity.RESULT_FIRST_USER + 4; 100 101 /** 102 * An ArrayList<String> of the potential results when performing 103 * {@link #ACTION_RECOGNIZE_SPEECH}. Only present when {@link Activity#RESULT_OK} is returned. 104 */ 105 public static final String EXTRA_RESULTS = "results"; 106} 107