diff options
| -rw-r--r-- | core/api/current.txt | 28 | ||||
| -rw-r--r-- | core/java/android/speech/RecognitionPart.aidl | 19 | ||||
| -rw-r--r-- | core/java/android/speech/RecognitionPart.java | 488 | ||||
| -rw-r--r-- | core/java/android/speech/RecognizerIntent.java | 14 | ||||
| -rw-r--r-- | core/java/android/speech/SpeechRecognizer.java | 11 |
5 files changed, 560 insertions, 0 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 8748a7625ee8..79f5e69cf516 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -41298,6 +41298,31 @@ package android.speech { method public default void onSegmentResults(@NonNull android.os.Bundle); } + public final class RecognitionPart implements android.os.Parcelable { + method public int describeContents(); + method public int getConfidenceLevel(); + method @Nullable public String getFormattedText(); + method @NonNull public String getRawText(); + method public long getTimestampMillis(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field public static final int CONFIDENCE_LEVEL_HIGH = 5; // 0x5 + field public static final int CONFIDENCE_LEVEL_LOW = 1; // 0x1 + field public static final int CONFIDENCE_LEVEL_LOW_MEDIUM = 2; // 0x2 + field public static final int CONFIDENCE_LEVEL_MEDIUM = 3; // 0x3 + field public static final int CONFIDENCE_LEVEL_MEDIUM_HIGH = 4; // 0x4 + field public static final int CONFIDENCE_LEVEL_UNKNOWN = 0; // 0x0 + field @NonNull public static final android.os.Parcelable.Creator<android.speech.RecognitionPart> CREATOR; + } + + public static final class RecognitionPart.Builder { + ctor public RecognitionPart.Builder(@NonNull String); + method @NonNull public android.speech.RecognitionPart build(); + method @NonNull public android.speech.RecognitionPart.Builder setConfidenceLevel(int); + method @NonNull public android.speech.RecognitionPart.Builder setFormattedText(@NonNull String); + method @NonNull public android.speech.RecognitionPart.Builder setRawText(@NonNull String); + method @NonNull public android.speech.RecognitionPart.Builder setTimestampMillis(long); + } + public abstract class RecognitionService extends android.app.Service { ctor public RecognitionService(); method public int getMaxConcurrentSessionsCount(); @@ -41387,6 +41412,8 @@ package android.speech { field public static final String EXTRA_PARTIAL_RESULTS = "android.speech.extra.PARTIAL_RESULTS"; field public static final String EXTRA_PREFER_OFFLINE = "android.speech.extra.PREFER_OFFLINE"; field public static final String EXTRA_PROMPT = "android.speech.extra.PROMPT"; + field public static final String EXTRA_REQUEST_WORD_CONFIDENCE = "android.speech.extra.REQUEST_WORD_CONFIDENCE"; + field public static final String EXTRA_REQUEST_WORD_TIMING = "android.speech.extra.REQUEST_WORD_TIMING"; field public static final String EXTRA_RESULTS = "android.speech.extra.RESULTS"; field public static final String EXTRA_RESULTS_PENDINGINTENT = "android.speech.extra.RESULTS_PENDINGINTENT"; field public static final String EXTRA_RESULTS_PENDINGINTENT_BUNDLE = "android.speech.extra.RESULTS_PENDINGINTENT_BUNDLE"; @@ -41446,6 +41473,7 @@ package android.speech { field public static final int ERROR_SERVER_DISCONNECTED = 11; // 0xb field public static final int ERROR_SPEECH_TIMEOUT = 6; // 0x6 field public static final int ERROR_TOO_MANY_REQUESTS = 10; // 0xa + field public static final String RECOGNITION_PARTS = "recognition_parts"; field public static final String RESULTS_ALTERNATIVES = "results_alternatives"; field public static final String RESULTS_RECOGNITION = "results_recognition"; } diff --git a/core/java/android/speech/RecognitionPart.aidl b/core/java/android/speech/RecognitionPart.aidl new file mode 100644 index 000000000000..f7754a28e823 --- /dev/null +++ b/core/java/android/speech/RecognitionPart.aidl @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.speech; + +parcelable RecognitionPart; diff --git a/core/java/android/speech/RecognitionPart.java b/core/java/android/speech/RecognitionPart.java new file mode 100644 index 000000000000..e551cdc9f21f --- /dev/null +++ b/core/java/android/speech/RecognitionPart.java @@ -0,0 +1,488 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.speech; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.os.Parcelable; + +import com.android.internal.util.DataClass; +import com.android.internal.util.Preconditions; + +/** + * Info about a single recognition part. + * + * <p> A recognition part represents a recognized word or character, as well as any potential + * adjacent punctuation, that is returned by the {@link SpeechRecognizer}. + * + * <p> Each recognition part is described with a {@link String} denoting the raw text. + * Additionally, if formatting is enabled with {@link RecognizerIntent#EXTRA_ENABLE_FORMATTING}, + * another {@link String} representation exists denoting the formatted text. + * + * <p> If the timestamps are requested with {@link RecognizerIntent#EXTRA_REQUEST_WORD_TIMING}, each + * recognition part will contain a value representing the offset of the beginning of this part from + * the start of the recognition session in milliseconds. + * + * <p> If the confidence levels are requested with + * {@link RecognizerIntent#EXTRA_REQUEST_WORD_CONFIDENCE}, each recognition part will contain + * a value describing the level of recognition confidence. + */ +@DataClass( + genBuilder = true, + genEqualsHashCode = true, + genHiddenConstDefs = true, + genToString = true) +public final class RecognitionPart implements Parcelable { + + /** Confidence level not requested. */ + public static final int CONFIDENCE_LEVEL_UNKNOWN = 0; + + /** Lowest level of confidence out of five levels. */ + public static final int CONFIDENCE_LEVEL_LOW = 1; + + /** Second-lowest level of confidence out of five levels. */ + public static final int CONFIDENCE_LEVEL_LOW_MEDIUM = 2; + + /** Medium level of confidence out of five levels. */ + public static final int CONFIDENCE_LEVEL_MEDIUM = 3; + + /** Second-highest level of confidence out of five levels. */ + public static final int CONFIDENCE_LEVEL_MEDIUM_HIGH = 4; + + /** Highest level of confidence out of five levels. */ + public static final int CONFIDENCE_LEVEL_HIGH = 5; + + /** The {@code non-null} raw text version of the recognized part of the result. */ + @NonNull + private final String mRawText; + + /** + * The formatted text version of the recognized part of the result. If formatting is enabled + * with {@link RecognizerIntent#EXTRA_ENABLE_FORMATTING}, it has a {@code non-null} value. + * + * <p> Otherwise, it should be {@code null} by default. + */ + @Nullable + private final String mFormattedText; + private static String defaultFormattedText() { + return null; + } + + /** + * Non-negative offset of the beginning of this part from + * the start of the recognition session in milliseconds + * if requested with {@link RecognizerIntent#EXTRA_REQUEST_WORD_TIMING}. + * + * <p> Otherwise, this should equal 0. + */ + private final long mTimestampMillis; + private static long defaultTimestampMillis() { + return 0; + } + + /** + * The level of confidence for this part if requested + * with {@link RecognizerIntent#EXTRA_REQUEST_WORD_CONFIDENCE}. + * + * <p> Otherwise, this should equal {@link #CONFIDENCE_LEVEL_UNKNOWN}. + */ + @ConfidenceLevel + private final int mConfidenceLevel; + @ConfidenceLevel + private static int defaultConfidenceLevel() { + return CONFIDENCE_LEVEL_UNKNOWN; + } + + private void onConstructed() { + Preconditions.checkArgumentNonnegative(mTimestampMillis, + "The timestamp must be non-negative."); + } + + @DataClass.Suppress("setFormattedText") + abstract static class BaseBuilder { + /** + * The formatted text version of the recognized part of the result. If formatting is enabled + * with {@link RecognizerIntent#EXTRA_ENABLE_FORMATTING}, it has a {@code non-null} value. + * + * <p> Otherwise, it should be {@code null} by default. + */ + @NonNull + public Builder setFormattedText(@NonNull String value) { + // Method explicitly defined, so that the argument can be checked for non-null. + com.android.internal.util.AnnotationValidations.validate(NonNull.class, null, value); + + final Builder builder = (Builder) this; + builder.checkNotUsed(); + builder.mBuilderFieldsSet |= 0x2; + builder.mFormattedText = value; + return builder; + } + } + + + + // Code below generated by codegen v1.0.23. + // + // DO NOT MODIFY! + // CHECKSTYLE:OFF Generated code + // + // To regenerate run: + // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/speech/RecognitionPart.java + // + // To exclude the generated code from IntelliJ auto-formatting enable (one-time): + // Settings > Editor > Code Style > Formatter Control + //@formatter:off + + + /** @hide */ + @android.annotation.IntDef(prefix = "CONFIDENCE_LEVEL_", value = { + CONFIDENCE_LEVEL_UNKNOWN, + CONFIDENCE_LEVEL_LOW, + CONFIDENCE_LEVEL_LOW_MEDIUM, + CONFIDENCE_LEVEL_MEDIUM, + CONFIDENCE_LEVEL_MEDIUM_HIGH, + CONFIDENCE_LEVEL_HIGH + }) + @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) + @DataClass.Generated.Member + public @interface ConfidenceLevel {} + + /** @hide */ + @DataClass.Generated.Member + public static String confidenceLevelToString(@ConfidenceLevel int value) { + switch (value) { + case CONFIDENCE_LEVEL_UNKNOWN: + return "CONFIDENCE_LEVEL_UNKNOWN"; + case CONFIDENCE_LEVEL_LOW: + return "CONFIDENCE_LEVEL_LOW"; + case CONFIDENCE_LEVEL_LOW_MEDIUM: + return "CONFIDENCE_LEVEL_LOW_MEDIUM"; + case CONFIDENCE_LEVEL_MEDIUM: + return "CONFIDENCE_LEVEL_MEDIUM"; + case CONFIDENCE_LEVEL_MEDIUM_HIGH: + return "CONFIDENCE_LEVEL_MEDIUM_HIGH"; + case CONFIDENCE_LEVEL_HIGH: + return "CONFIDENCE_LEVEL_HIGH"; + default: return Integer.toHexString(value); + } + } + + @DataClass.Generated.Member + /* package-private */ RecognitionPart( + @NonNull String rawText, + @Nullable String formattedText, + long timestampMillis, + @ConfidenceLevel int confidenceLevel) { + this.mRawText = rawText; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mRawText); + this.mFormattedText = formattedText; + this.mTimestampMillis = timestampMillis; + this.mConfidenceLevel = confidenceLevel; + + if (!(mConfidenceLevel == CONFIDENCE_LEVEL_UNKNOWN) + && !(mConfidenceLevel == CONFIDENCE_LEVEL_LOW) + && !(mConfidenceLevel == CONFIDENCE_LEVEL_LOW_MEDIUM) + && !(mConfidenceLevel == CONFIDENCE_LEVEL_MEDIUM) + && !(mConfidenceLevel == CONFIDENCE_LEVEL_MEDIUM_HIGH) + && !(mConfidenceLevel == CONFIDENCE_LEVEL_HIGH)) { + throw new java.lang.IllegalArgumentException( + "confidenceLevel was " + mConfidenceLevel + " but must be one of: " + + "CONFIDENCE_LEVEL_UNKNOWN(" + CONFIDENCE_LEVEL_UNKNOWN + "), " + + "CONFIDENCE_LEVEL_LOW(" + CONFIDENCE_LEVEL_LOW + "), " + + "CONFIDENCE_LEVEL_LOW_MEDIUM(" + CONFIDENCE_LEVEL_LOW_MEDIUM + "), " + + "CONFIDENCE_LEVEL_MEDIUM(" + CONFIDENCE_LEVEL_MEDIUM + "), " + + "CONFIDENCE_LEVEL_MEDIUM_HIGH(" + CONFIDENCE_LEVEL_MEDIUM_HIGH + "), " + + "CONFIDENCE_LEVEL_HIGH(" + CONFIDENCE_LEVEL_HIGH + ")"); + } + + + onConstructed(); + } + + /** + * The {@code non-null} raw text version of the recognized part of the result. + */ + @DataClass.Generated.Member + public @NonNull String getRawText() { + return mRawText; + } + + /** + * The formatted text version of the recognized part of the result. If formatting is enabled + * with {@link RecognizerIntent#EXTRA_ENABLE_FORMATTING}, it has a {@code non-null} value. + * + * <p> Otherwise, it should be {@code null} by default. + */ + @DataClass.Generated.Member + public @Nullable String getFormattedText() { + return mFormattedText; + } + + /** + * Non-negative offset of the beginning of this part from + * the start of the recognition session in milliseconds + * if requested with {@link RecognizerIntent#EXTRA_REQUEST_WORD_TIMING}. + * + * <p> Otherwise, this should equal 0. + */ + @DataClass.Generated.Member + public long getTimestampMillis() { + return mTimestampMillis; + } + + /** + * The level of confidence for this part if requested + * with {@link RecognizerIntent#EXTRA_REQUEST_WORD_CONFIDENCE}. + * + * <p> Otherwise, this should equal {@link #CONFIDENCE_LEVEL_UNKNOWN}. + */ + @DataClass.Generated.Member + public @ConfidenceLevel int getConfidenceLevel() { + return mConfidenceLevel; + } + + @Override + @DataClass.Generated.Member + public String toString() { + // You can override field toString logic by defining methods like: + // String fieldNameToString() { ... } + + return "RecognitionPart { " + + "rawText = " + mRawText + ", " + + "formattedText = " + mFormattedText + ", " + + "timestampMillis = " + mTimestampMillis + ", " + + "confidenceLevel = " + confidenceLevelToString(mConfidenceLevel) + + " }"; + } + + @Override + @DataClass.Generated.Member + public boolean equals(@Nullable Object o) { + // You can override field equality logic by defining either of the methods like: + // boolean fieldNameEquals(RecognitionPart other) { ... } + // boolean fieldNameEquals(FieldType otherValue) { ... } + + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + @SuppressWarnings("unchecked") + RecognitionPart that = (RecognitionPart) o; + //noinspection PointlessBooleanExpression + return true + && java.util.Objects.equals(mRawText, that.mRawText) + && java.util.Objects.equals(mFormattedText, that.mFormattedText) + && mTimestampMillis == that.mTimestampMillis + && mConfidenceLevel == that.mConfidenceLevel; + } + + @Override + @DataClass.Generated.Member + public int hashCode() { + // You can override field hashCode logic by defining methods like: + // int fieldNameHashCode() { ... } + + int _hash = 1; + _hash = 31 * _hash + java.util.Objects.hashCode(mRawText); + _hash = 31 * _hash + java.util.Objects.hashCode(mFormattedText); + _hash = 31 * _hash + Long.hashCode(mTimestampMillis); + _hash = 31 * _hash + mConfidenceLevel; + return _hash; + } + + @Override + @DataClass.Generated.Member + public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { + // You can override field parcelling by defining methods like: + // void parcelFieldName(Parcel dest, int flags) { ... } + + byte flg = 0; + if (mFormattedText != null) flg |= 0x2; + dest.writeByte(flg); + dest.writeString(mRawText); + if (mFormattedText != null) dest.writeString(mFormattedText); + dest.writeLong(mTimestampMillis); + dest.writeInt(mConfidenceLevel); + } + + @Override + @DataClass.Generated.Member + public int describeContents() { return 0; } + + /** @hide */ + @SuppressWarnings({"unchecked", "RedundantCast"}) + @DataClass.Generated.Member + /* package-private */ RecognitionPart(@NonNull android.os.Parcel in) { + // You can override field unparcelling by defining methods like: + // static FieldType unparcelFieldName(Parcel in) { ... } + + byte flg = in.readByte(); + String rawText = in.readString(); + String formattedText = (flg & 0x2) == 0 ? null : in.readString(); + long timestampMillis = in.readLong(); + int confidenceLevel = in.readInt(); + + this.mRawText = rawText; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mRawText); + this.mFormattedText = formattedText; + this.mTimestampMillis = timestampMillis; + this.mConfidenceLevel = confidenceLevel; + + if (!(mConfidenceLevel == CONFIDENCE_LEVEL_UNKNOWN) + && !(mConfidenceLevel == CONFIDENCE_LEVEL_LOW) + && !(mConfidenceLevel == CONFIDENCE_LEVEL_LOW_MEDIUM) + && !(mConfidenceLevel == CONFIDENCE_LEVEL_MEDIUM) + && !(mConfidenceLevel == CONFIDENCE_LEVEL_MEDIUM_HIGH) + && !(mConfidenceLevel == CONFIDENCE_LEVEL_HIGH)) { + throw new java.lang.IllegalArgumentException( + "confidenceLevel was " + mConfidenceLevel + " but must be one of: " + + "CONFIDENCE_LEVEL_UNKNOWN(" + CONFIDENCE_LEVEL_UNKNOWN + "), " + + "CONFIDENCE_LEVEL_LOW(" + CONFIDENCE_LEVEL_LOW + "), " + + "CONFIDENCE_LEVEL_LOW_MEDIUM(" + CONFIDENCE_LEVEL_LOW_MEDIUM + "), " + + "CONFIDENCE_LEVEL_MEDIUM(" + CONFIDENCE_LEVEL_MEDIUM + "), " + + "CONFIDENCE_LEVEL_MEDIUM_HIGH(" + CONFIDENCE_LEVEL_MEDIUM_HIGH + "), " + + "CONFIDENCE_LEVEL_HIGH(" + CONFIDENCE_LEVEL_HIGH + ")"); + } + + + onConstructed(); + } + + @DataClass.Generated.Member + public static final @NonNull Parcelable.Creator<RecognitionPart> CREATOR + = new Parcelable.Creator<RecognitionPart>() { + @Override + public RecognitionPart[] newArray(int size) { + return new RecognitionPart[size]; + } + + @Override + public RecognitionPart createFromParcel(@NonNull android.os.Parcel in) { + return new RecognitionPart(in); + } + }; + + /** + * A builder for {@link RecognitionPart} + */ + @SuppressWarnings("WeakerAccess") + @DataClass.Generated.Member + public static final class Builder extends BaseBuilder { + + private @NonNull String mRawText; + private @Nullable String mFormattedText; + private long mTimestampMillis; + private @ConfidenceLevel int mConfidenceLevel; + + private long mBuilderFieldsSet = 0L; + + /** + * Creates a new Builder. + * + * @param rawText + * The {@code non-null} raw text version of the recognized part of the result. + */ + public Builder( + @NonNull String rawText) { + mRawText = rawText; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mRawText); + } + + /** + * The {@code non-null} raw text version of the recognized part of the result. + */ + @DataClass.Generated.Member + public @NonNull Builder setRawText(@NonNull String value) { + checkNotUsed(); + mBuilderFieldsSet |= 0x1; + mRawText = value; + return this; + } + + /** + * Non-negative offset of the beginning of this part from + * the start of the recognition session in milliseconds + * if requested with {@link RecognizerIntent#EXTRA_REQUEST_WORD_TIMING}. + * + * <p> Otherwise, this should equal 0. + */ + @DataClass.Generated.Member + public @NonNull Builder setTimestampMillis(long value) { + checkNotUsed(); + mBuilderFieldsSet |= 0x4; + mTimestampMillis = value; + return this; + } + + /** + * The level of confidence for this part if requested + * with {@link RecognizerIntent#EXTRA_REQUEST_WORD_CONFIDENCE}. + * + * <p> Otherwise, this should equal {@link #CONFIDENCE_LEVEL_UNKNOWN}. + */ + @DataClass.Generated.Member + public @NonNull Builder setConfidenceLevel(@ConfidenceLevel int value) { + checkNotUsed(); + mBuilderFieldsSet |= 0x8; + mConfidenceLevel = value; + return this; + } + + /** Builds the instance. This builder should not be touched after calling this! */ + public @NonNull RecognitionPart build() { + checkNotUsed(); + mBuilderFieldsSet |= 0x10; // Mark builder used + + if ((mBuilderFieldsSet & 0x2) == 0) { + mFormattedText = defaultFormattedText(); + } + if ((mBuilderFieldsSet & 0x4) == 0) { + mTimestampMillis = defaultTimestampMillis(); + } + if ((mBuilderFieldsSet & 0x8) == 0) { + mConfidenceLevel = defaultConfidenceLevel(); + } + RecognitionPart o = new RecognitionPart( + mRawText, + mFormattedText, + mTimestampMillis, + mConfidenceLevel); + return o; + } + + private void checkNotUsed() { + if ((mBuilderFieldsSet & 0x10) != 0) { + throw new IllegalStateException( + "This Builder should not be reused. Use a new Builder instance instead"); + } + } + } + + @DataClass.Generated( + time = 1676294616910L, + codegenVersion = "1.0.23", + sourceFile = "frameworks/base/core/java/android/speech/RecognitionPart.java", + inputSignatures = "public static final int CONFIDENCE_LEVEL_UNKNOWN\npublic static final int CONFIDENCE_LEVEL_LOW\npublic static final int CONFIDENCE_LEVEL_LOW_MEDIUM\npublic static final int CONFIDENCE_LEVEL_MEDIUM\npublic static final int CONFIDENCE_LEVEL_MEDIUM_HIGH\npublic static final int CONFIDENCE_LEVEL_HIGH\nprivate final @android.annotation.NonNull java.lang.String mRawText\nprivate final @android.annotation.Nullable java.lang.String mFormattedText\nprivate final long mTimestampMillis\nprivate final @android.speech.RecognitionPart.ConfidenceLevel int mConfidenceLevel\nprivate static java.lang.String defaultFormattedText()\nprivate static long defaultTimestampMillis()\nprivate static @android.speech.RecognitionPart.ConfidenceLevel int defaultConfidenceLevel()\nprivate void onConstructed()\nclass RecognitionPart extends java.lang.Object implements [android.os.Parcelable]\npublic @android.annotation.NonNull android.speech.RecognitionPart.Builder setFormattedText(java.lang.String)\nclass BaseBuilder extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genBuilder=true, genEqualsHashCode=true, genHiddenConstDefs=true, genToString=true)\npublic @android.annotation.NonNull android.speech.RecognitionPart.Builder setFormattedText(java.lang.String)\nclass BaseBuilder extends java.lang.Object implements []") + @Deprecated + private void __metadata() {} + + + //@formatter:on + // End of generated code + +} diff --git a/core/java/android/speech/RecognizerIntent.java b/core/java/android/speech/RecognizerIntent.java index cd18c19ddf3f..7127fa1fd657 100644 --- a/core/java/android/speech/RecognizerIntent.java +++ b/core/java/android/speech/RecognizerIntent.java @@ -558,4 +558,18 @@ public class RecognizerIntent { * @see #EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS */ public static final String EXTRA_SEGMENTED_SESSION = "android.speech.extra.SEGMENTED_SESSION"; + + /** + * Optional boolean indicating whether the recognizer should return the timestamp + * of each word in the final recognition results. + */ + public static final String EXTRA_REQUEST_WORD_TIMING = + "android.speech.extra.REQUEST_WORD_TIMING"; + + /** + * Optional boolean indicating whether the recognizer should return the confidence + * level of each word in the final recognition results. + */ + public static final String EXTRA_REQUEST_WORD_CONFIDENCE = + "android.speech.extra.REQUEST_WORD_CONFIDENCE"; } diff --git a/core/java/android/speech/SpeechRecognizer.java b/core/java/android/speech/SpeechRecognizer.java index bcb8005e35cf..33c5b5a27fab 100644 --- a/core/java/android/speech/SpeechRecognizer.java +++ b/core/java/android/speech/SpeechRecognizer.java @@ -113,6 +113,17 @@ public class SpeechRecognizer { public static final String RESULTS_ALTERNATIVES = "results_alternatives"; /** + * Key used to receive an ArrayList<{@link RecognitionPart}> object from the + * {@link Bundle} passed to the {@link RecognitionListener#onResults(Bundle)} and + * {@link RecognitionListener#onSegmentResults(Bundle)} methods. + * + * <p> A single {@link SpeechRecognizer} result is represented as a {@link String}. Each word of + * the resulting String, as well as any potential adjacent punctuation, is represented by a + * {@link RecognitionPart} item from the ArrayList retrieved by this key. + */ + public static final String RECOGNITION_PARTS = "recognition_parts"; + + /** * The reason speech recognition failed. * * @hide |