From bb7cf916b23c78dc640f8bdfb7ad5cd6b09c3636 Mon Sep 17 00:00:00 2001 From: Mike LeBeau Date: Tue, 5 Apr 2011 09:37:30 -0400 Subject: Support speech recognizer confidence values. Pass speech recognizer confidence values in the SpeechRecognizer and RecognizerIntent APIs through to the caller. This change defines new API constants for keys to these values. The corresponding change is being made to Google Voice Search, and should be made to any other implementations. Bug: 3267513 Bug: 4163206 Change-Id: I294553f2eb9eb3be21298b8434117c8c5309558d --- api/current.xml | 22 ++++++++++++++++ core/java/android/speech/RecognitionListener.java | 3 ++- core/java/android/speech/RecognizerIntent.java | 31 ++++++++++++++++++----- core/java/android/speech/SpeechRecognizer.java | 16 +++++++++++- 4 files changed, 64 insertions(+), 8 deletions(-) diff --git a/api/current.xml b/api/current.xml index 0a57d3e77893..f9a338993542 100644 --- a/api/current.xml +++ b/api/current.xml @@ -180231,6 +180231,17 @@ visibility="public" > + + + + If you want to avoid triggering any type of action besides web search, you can use @@ -105,6 +105,7 @@ public class RecognizerIntent { *

Result extras (returned in the result, not to be specified in the request): *

    *
  • {@link #EXTRA_RESULTS} + *
  • {@link #EXTRA_CONFIDENCE_SCORES} (optional) *
* *

NOTE: There may not be any applications installed to handle this action, so you should @@ -232,12 +233,30 @@ public class RecognizerIntent { /** * An ArrayList<String> of the recognition results when performing - * {@link #ACTION_RECOGNIZE_SPEECH}. Returned in the results; not to be specified in the - * recognition request. Only present when {@link Activity#RESULT_OK} is returned in - * an activity result. In a PendingIntent, the lack of this extra indicates failure. + * {@link #ACTION_RECOGNIZE_SPEECH}. Generally this list should be ordered in + * descending order of speech recognizer confidence. (See {@link #EXTRA_CONFIDENCE_SCORES}). + * Returned in the results; not to be specified in the recognition request. Only present + * when {@link Activity#RESULT_OK} is returned in an activity result. In a PendingIntent, + * the lack of this extra indicates failure. */ public static final String EXTRA_RESULTS = "android.speech.extra.RESULTS"; + /** + * A float array of confidence scores of the recognition results when performing + * {@link #ACTION_RECOGNIZE_SPEECH}. The array should be the same size as the ArrayList + * returned in {@link #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 {@link Activity#RESULT_OK} is + * returned in an activity result. + */ + public static final String EXTRA_CONFIDENCE_SCORES = "android.speech.extra.CONFIDENCE_SCORES"; + /** * Returns the broadcast intent to fire with * {@link Context#sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler, int, String, Bundle)} diff --git a/core/java/android/speech/SpeechRecognizer.java b/core/java/android/speech/SpeechRecognizer.java index cd73ba850631..8fee41d1bcb7 100644 --- a/core/java/android/speech/SpeechRecognizer.java +++ b/core/java/android/speech/SpeechRecognizer.java @@ -50,12 +50,26 @@ public class SpeechRecognizer { private static final String TAG = "SpeechRecognizer"; /** - * Used to retrieve an {@code ArrayList} from the {@link Bundle} passed to the + * Key used to retrieve an {@code ArrayList} from the {@link Bundle} passed to the * {@link RecognitionListener#onResults(Bundle)} and * {@link RecognitionListener#onPartialResults(Bundle)} methods. These strings are the possible * recognition results, where the first element is the most likely candidate. */ public static final String RESULTS_RECOGNITION = "results_recognition"; + + /** + * Key used to retrieve a float array from the {@link Bundle} passed to the + * {@link RecognitionListener#onResults(Bundle)} and + * {@link RecognitionListener#onPartialResults(Bundle)} methods. The array should be + * the same size as the ArrayList provided in {@link #RESULTS_RECOGNITION}, 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. + *

+ * This value is optional and might not be provided. + */ + public static final String CONFIDENCE_SCORES = "confidence_scores"; /** Network operation timed out. */ public static final int ERROR_NETWORK_TIMEOUT = 1; -- cgit v1.2.3-59-g8ed1b