• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.app.Activity;
20 import android.content.ActivityNotFoundException;
21 import android.content.Intent;
22 
23 /**
24  * Constants for supporting speech recognition through starting an {@link Intent}
25  */
26 public class RecognizerIntent {
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, or forwarded
34      * via a PendingIntent if one is provided.
35      *
36      * <p>Required extras:
37      * <ul>
38      *   <li>{@link #EXTRA_LANGUAGE_MODEL}
39      * </ul>
40      *
41      * <p>Optional extras:
42      * <ul>
43      *   <li>{@link #EXTRA_PROMPT}
44      *   <li>{@link #EXTRA_LANGUAGE}
45      *   <li>{@link #EXTRA_MAX_RESULTS}
46      *   <li>{@link #EXTRA_RESULTS_PENDINGINTENT}
47      *   <li>{@link #EXTRA_RESULTS_PENDINGINTENT_BUNDLE}
48      * </ul>
49      *
50      * <p> Result extras:
51      * <ul>
52      *   <li>{@link #EXTRA_RESULTS}
53      * </ul>
54      *
55      * <p>NOTE: There may not be any applications installed to handle this action, so you should
56      * make sure to catch {@link ActivityNotFoundException}.
57      */
58     public static final String ACTION_RECOGNIZE_SPEECH = "android.speech.action.RECOGNIZE_SPEECH";
59 
60     /**
61      * Starts an activity that will prompt the user for speech, sends it through a
62      * speech recognizer, and invokes and displays a web search result.
63      *
64      * <p>Required extras:
65      * <ul>
66      *   <li>{@link #EXTRA_LANGUAGE_MODEL}
67      * </ul>
68      *
69      * <p>Optional extras:
70      * <ul>
71      *   <li>{@link #EXTRA_PROMPT}
72      *   <li>{@link #EXTRA_LANGUAGE}
73      *   <li>{@link #EXTRA_MAX_RESULTS}
74      * </ul>
75      *
76      * <p> Result extras:
77      * <ul>
78      *   <li>{@link #EXTRA_RESULTS}
79      * </ul>
80      *
81      * <p>NOTE: There may not be any applications installed to handle this action, so you should
82      * make sure to catch {@link ActivityNotFoundException}.
83      */
84     public static final String ACTION_WEB_SEARCH = "android.speech.action.WEB_SEARCH";
85 
86     /**
87      * Informs the recognizer which speech model to prefer when performing
88      * {@link #ACTION_RECOGNIZE_SPEECH}. The recognizer uses this
89      * information to fine tune the results. This extra is required. Activities implementing
90      * {@link #ACTION_RECOGNIZE_SPEECH} may interpret the values as they see fit.
91      *
92      *  @see #LANGUAGE_MODEL_FREE_FORM
93      *  @see #LANGUAGE_MODEL_WEB_SEARCH
94      */
95     public static final String EXTRA_LANGUAGE_MODEL = "android.speech.extra.LANGUAGE_MODEL";
96 
97     /**
98      * Use a language model based on free-form speech recognition.  This is a value to use for
99      * {@link #EXTRA_LANGUAGE_MODEL}.
100      * @see #EXTRA_LANGUAGE_MODEL
101      */
102     public static final String LANGUAGE_MODEL_FREE_FORM = "free_form";
103     /**
104      * Use a language model based on web search terms.  This is a value to use for
105      * {@link #EXTRA_LANGUAGE_MODEL}.
106      * @see #EXTRA_LANGUAGE_MODEL
107      */
108     public static final String LANGUAGE_MODEL_WEB_SEARCH = "web_search";
109 
110     /** Optional text prompt to show to the user when asking them to speak. */
111     public static final String EXTRA_PROMPT = "android.speech.extra.PROMPT";
112 
113     /**
114      * Optional language override to inform the recognizer that it should expect speech in
115      * a language different than the one set in the {@link java.util.Locale#getDefault()}.
116      */
117     public static final String EXTRA_LANGUAGE = "android.speech.extra.LANGUAGE";
118 
119     /**
120      * Optional limit on the maximum number of results to return. If omitted the recognizer
121      * will choose how many results to return. Must be an integer.
122      */
123     public static final String EXTRA_MAX_RESULTS = "android.speech.extra.MAX_RESULTS";
124 
125     /**
126      * When the intent is {@link #ACTION_RECOGNIZE_SPEECH}, the speech input activity will
127      * return results to you via the activity results mechanism.  Alternatively, if you use this
128      * extra to supply a PendingIntent, the results will be added to its bundle and the
129      * PendingIntent will be sent to its target.
130      */
131     public static final String EXTRA_RESULTS_PENDINGINTENT =
132             "android.speech.extra.RESULTS_PENDINGINTENT";
133     /**
134      * If you use {@link #EXTRA_RESULTS_PENDINGINTENT} to supply a forwarding intent, you can
135      * also use this extra to supply additional extras for the final intent.  The search results
136      * will be added to this bundle, and the combined bundle will be sent to the target.
137      */
138     public static final String EXTRA_RESULTS_PENDINGINTENT_BUNDLE =
139             "android.speech.extra.RESULTS_PENDINGINTENT_BUNDLE";
140 
141     /** Result code returned when no matches are found for the given speech */
142     public static final int RESULT_NO_MATCH = Activity.RESULT_FIRST_USER;
143     /** Result code returned when there is a generic client error */
144     public static final int RESULT_CLIENT_ERROR = Activity.RESULT_FIRST_USER + 1;
145     /** Result code returned when the recognition server returns an error */
146     public static final int RESULT_SERVER_ERROR = Activity.RESULT_FIRST_USER + 2;
147     /** Result code returned when a network error was encountered */
148     public static final int RESULT_NETWORK_ERROR = Activity.RESULT_FIRST_USER + 3;
149     /** Result code returned when an audio error was encountered */
150     public static final int RESULT_AUDIO_ERROR = Activity.RESULT_FIRST_USER + 4;
151 
152     /**
153      * An ArrayList<String> of the potential results when performing
154      * {@link #ACTION_RECOGNIZE_SPEECH}. Only present when {@link Activity#RESULT_OK} is returned.
155      */
156     public static final String EXTRA_RESULTS = "android.speech.extra.RESULTS";
157 }
158