Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c3cd43e authored by Qi Cao's avatar Qi Cao
Browse files

Added public extras for audio injection, biasing, formatting, masking

offensive words. Reworded existing extras for segmented session feature.

Reference doc: go/recognizer-intent-public-doc
Bug: 218705986

Test: Only adding strings and doc. No test needed.
Change-Id: I929ddfd59ea17c9ed4cdc22a9ddb90dcc409c40b
parent b1b3e3fb
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -39446,12 +39446,21 @@ package android.speech {
    field public static final String ACTION_VOICE_SEARCH_HANDS_FREE = "android.speech.action.VOICE_SEARCH_HANDS_FREE";
    field public static final String ACTION_WEB_SEARCH = "android.speech.action.WEB_SEARCH";
    field public static final String DETAILS_META_DATA = "android.speech.DETAILS";
    field public static final String EXTRA_AUDIO_INJECT_SOURCE = "android.speech.extra.AUDIO_INJECT_SOURCE";
    field @Deprecated public static final String EXTRA_AUDIO_INJECT_SOURCE = "android.speech.extra.AUDIO_INJECT_SOURCE";
    field public static final String EXTRA_AUDIO_SOURCE = "android.speech.extra.AUDIO_SOURCE";
    field public static final String EXTRA_AUDIO_SOURCE_CHANNEL_COUNT = "android.speech.extra.AUDIO_SOURCE_CHANNEL_COUNT";
    field public static final String EXTRA_AUDIO_SOURCE_ENCODING = "android.speech.extra.AUDIO_SOURCE_ENCODING";
    field public static final String EXTRA_AUDIO_SOURCE_SAMPLING_RATE = "android.speech.extra.AUDIO_SOURCE_SAMPLING_RATE";
    field public static final String EXTRA_BIASING_STRINGS = "android.speech.extra.BIASING_STRINGS";
    field public static final String EXTRA_CALLING_PACKAGE = "calling_package";
    field public static final String EXTRA_CONFIDENCE_SCORES = "android.speech.extra.CONFIDENCE_SCORES";
    field public static final String EXTRA_ENABLE_BIASING_DEVICE_CONTEXT = "android.speech.extra.ENABLE_BIASING_DEVICE_CONTEXT";
    field public static final String EXTRA_ENABLE_FORMATTING = "android.speech.extra.ENABLE_FORMATTING";
    field public static final String EXTRA_HIDE_PARTIAL_TRAILING_PUNCTUATION = "android.speech.extra.HIDE_PARTIAL_TRAILING_PUNCTUATION";
    field public static final String EXTRA_LANGUAGE = "android.speech.extra.LANGUAGE";
    field public static final String EXTRA_LANGUAGE_MODEL = "android.speech.extra.LANGUAGE_MODEL";
    field public static final String EXTRA_LANGUAGE_PREFERENCE = "android.speech.extra.LANGUAGE_PREFERENCE";
    field public static final String EXTRA_MASK_OFFENSIVE_WORDS = "android.speech.extra.MASK_OFFENSIVE_WORDS";
    field public static final String EXTRA_MAX_RESULTS = "android.speech.extra.MAX_RESULTS";
    field public static final String EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE = "android.speech.extra.ONLY_RETURN_LANGUAGE_PREFERENCE";
    field public static final String EXTRA_ORIGIN = "android.speech.extra.ORIGIN";
@@ -39462,12 +39471,14 @@ package android.speech {
    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";
    field public static final String EXTRA_SECURE = "android.speech.extras.EXTRA_SECURE";
    field public static final String EXTRA_SEGMENT_SESSION = "android.speech.extra.SEGMENT_SESSION";
    field public static final String EXTRA_SEGMENTED_SESSION = "android.speech.extra.SEGMENTED_SESSION";
    field public static final String EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS = "android.speech.extras.SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS";
    field public static final String EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS = "android.speech.extras.SPEECH_INPUT_MINIMUM_LENGTH_MILLIS";
    field public static final String EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS = "android.speech.extras.SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS";
    field public static final String EXTRA_SUPPORTED_LANGUAGES = "android.speech.extra.SUPPORTED_LANGUAGES";
    field public static final String EXTRA_WEB_SEARCH_ONLY = "android.speech.extra.WEB_SEARCH_ONLY";
    field public static final String FORMATTING_OPTIMIZE_LATENCY = "latency";
    field public static final String FORMATTING_OPTIMIZE_QUALITY = "quality";
    field public static final String LANGUAGE_MODEL_FREE_FORM = "free_form";
    field public static final String LANGUAGE_MODEL_WEB_SEARCH = "web_search";
    field public static final int RESULT_AUDIO_ERROR = 5; // 0x5
+191 −71
Original line number Diff line number Diff line
@@ -32,21 +32,6 @@ import java.util.ArrayList;
 * Constants for supporting speech recognition through starting an {@link Intent}
 */
public class RecognizerIntent {
    /**
     * The extra key used in an intent to the speech recognizer for voice search. Not
     * generally to be used by developers. The system search dialog uses this, for example,
     * to set a calling package for identification by a voice search API. If this extra
     * is set by anyone but the system process, it should be overridden by the voice search
     * implementation.
     */
    public static final String EXTRA_CALLING_PACKAGE = "calling_package";

    /**
     * The extra key used in an intent which is providing an already opened audio source for the
     * RecognitionService to use. Data should be a URI to an audio resource.
     */
    public static final String EXTRA_AUDIO_INJECT_SOURCE =
            "android.speech.extra.AUDIO_INJECT_SOURCE";

    private RecognizerIntent() {
        // Not for instantiating.
@@ -156,6 +141,129 @@ public class RecognizerIntent {
    public static final String ACTION_VOICE_SEARCH_HANDS_FREE =
            "android.speech.action.VOICE_SEARCH_HANDS_FREE";

    /**
     * Optional {@link android.os.ParcelFileDescriptor} pointing to an already opened audio
     * source for the recognizer to use. The caller of the recognizer is responsible for closing
     * the audio. If this extra is not set or the recognizer does not support this feature, the
     * recognizer will open the mic for audio and close it when the recognition is finished.
     *
     * <p>Along with this extra, please send {@link #EXTRA_AUDIO_SOURCE_CHANNEL_COUNT},
     * {@link #EXTRA_AUDIO_SOURCE_ENCODING}, and {@link #EXTRA_AUDIO_SOURCE_SAMPLING_RATE}
     * extras, otherwise the default values of these extras will be used.
     *
     * <p>Additionally, {@link #EXTRA_ENABLE_BIASING_DEVICE_CONTEXT} may have no effect when this
     * extra is set.
     *
     * <p>This can also be used as the string value for {@link #EXTRA_SEGMENTED_SESSION} to
     * enable segmented session mode. The audio must be passed in using this extra. The
     * recognition session will end when and only when the audio is closed.
     *
     * @see #EXTRA_SEGMENTED_SESSION
     */
    public static final String EXTRA_AUDIO_SOURCE = "android.speech.extra.AUDIO_SOURCE";

    /**
     * Optional integer, to be used with {@link #EXTRA_AUDIO_SOURCE}, to indicate the number of
     * channels in the audio. The default value is 1.
     */
    public static final String EXTRA_AUDIO_SOURCE_CHANNEL_COUNT =
            "android.speech.extra.AUDIO_SOURCE_CHANNEL_COUNT";

    /**
     * Optional integer (from {@link android.media.AudioFormat}), to be used with
     * {@link #EXTRA_AUDIO_SOURCE}, to indicate the audio encoding. The default value is
     * {@link android.media.AudioFormat#ENCODING_PCM_16BIT}.
     */
    public static final String EXTRA_AUDIO_SOURCE_ENCODING =
            "android.speech.extra.AUDIO_SOURCE_ENCODING";

    /**
     * Optional integer, to be used with {@link #EXTRA_AUDIO_SOURCE}, to indicate the sampling
     * rate of the audio. The default value is 16000.
     */
    public static final String EXTRA_AUDIO_SOURCE_SAMPLING_RATE =
            "android.speech.extra.AUDIO_SOURCE_SAMPLING_RATE";

    /**
     * Optional boolean to enable biasing towards device context. The recognizer will use the
     * device context to tune the recognition results.
     *
     * <p>Depending on the recognizer implementation, this value may have no effect.
     */
    public static final String EXTRA_ENABLE_BIASING_DEVICE_CONTEXT =
            "android.speech.extra.ENABLE_BIASING_DEVICE_CONTEXT";

    /**
     * Optional list of strings, towards which the recognizer should bias the recognition results.
     * These are separate from the device context.
     */
    public static final String EXTRA_BIASING_STRINGS = "android.speech.extra.BIASING_STRINGS";

    /**
     * Optional string to enable text formatting (e.g. unspoken punctuation (examples: question
     * mark, comma, period, etc.), capitalization, etc.) and specify the optimization strategy.
     * If set, the partial and final result texts will be formatted. Each result list will
     * contain two hypotheses in the order of 1) formatted text 2) raw text.
     *
     * <p>Depending on the recognizer implementation, this value may have no effect.
     *
     * @see #FORMATTING_OPTIMIZE_QUALITY
     * @see #FORMATTING_OPTIMIZE_LATENCY
     */
    public static final String EXTRA_ENABLE_FORMATTING = "android.speech.extra.ENABLE_FORMATTING";

    /**
     * Optimizes formatting quality. This will increase latency but provide the highest
     * punctuation quality. This is a value to use for {@link #EXTRA_ENABLE_FORMATTING}.
     *
     * @see #EXTRA_ENABLE_FORMATTING
     */
    public static final String FORMATTING_OPTIMIZE_QUALITY = "quality";
    /**
     * Optimizes formatting latency. This will result in a slightly lower quality of punctuation
     * but can improve the experience for real-time use cases. This is a value to use for
     * {@link #EXTRA_ENABLE_FORMATTING}.
     *
     * @see #EXTRA_ENABLE_FORMATTING
     */
    public static final String FORMATTING_OPTIMIZE_LATENCY = "latency";

    /**
     * Optional boolean, to be used with {@link #EXTRA_ENABLE_FORMATTING}, to prevent the
     * recognizer adding punctuation after the last word of the partial results. The default is
     * false.
     */
    public static final String EXTRA_HIDE_PARTIAL_TRAILING_PUNCTUATION =
            "android.speech.extra.HIDE_PARTIAL_TRAILING_PUNCTUATION";

    /**
     * Optional boolean indicating whether the recognizer should mask the offensive words in
     * recognition results. The Default is true.
     */
    public static final String EXTRA_MASK_OFFENSIVE_WORDS =
            "android.speech.extra.MASK_OFFENSIVE_WORDS";

    /**
     * The extra key used in an intent to the speech recognizer for voice search. Not
     * generally to be used by developers. The system search dialog uses this, for example,
     * to set a calling package for identification by a voice search API. If this extra
     * is set by anyone but the system process, it should be overridden by the voice search
     * implementation.
     */
    public static final String EXTRA_CALLING_PACKAGE = "calling_package";

    /**
     * The extra key used in an intent which is providing an already opened audio source for the
     * RecognitionService to use. Data should be a URI to an audio resource.
     *
     * <p>Depending on the recognizer implementation, this value may have no effect.
     *
     * @deprecated Replaced with {@link #EXTRA_AUDIO_SOURCE}
     */
    @Deprecated
    public static final String EXTRA_AUDIO_INJECT_SOURCE =
            "android.speech.extra.AUDIO_INJECT_SOURCE";

    /**
     * Optional boolean to indicate that a "hands free" voice search was performed while the device
     * was in a secure mode. An example of secure mode is when the device's screen lock is active,
@@ -168,24 +276,29 @@ public class RecognizerIntent {
    public static final String EXTRA_SECURE = "android.speech.extras.EXTRA_SECURE";

    /**
     * The minimum length of an utterance. We will not stop recording before this amount of time.
     * Optional integer to indicate the minimum length of the recognition session. The recognizer
     * will not stop recognizing speech before this amount of time.
     *
     * Note that it is extremely rare you'd want to specify this value in an intent. If you don't
     * have a very good reason to change these, you should leave them as they are. Note also that
     * certain values may cause undesired or unexpected results - use judiciously! Additionally,
     * depending on the recognizer implementation, these values may have no effect.
     * <p>Note that it is extremely rare you'd want to specify this value in an intent.
     * Generally, it should be specified only when it is also used as the value for
     * {@link #EXTRA_SEGMENTED_SESSION} to enable segmented session mode. Note also that certain
     * values may cause undesired or unexpected results - use judiciously!
     *
     * <p>Depending on the recognizer implementation, these values may have no effect.
     */
    public static final String EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS =
            "android.speech.extras.SPEECH_INPUT_MINIMUM_LENGTH_MILLIS";

    /**
     * The amount of time that it should take after we stop hearing speech to consider the input
     * complete. 
     * The amount of time that it should take after the recognizer stops hearing speech to
     * consider the input complete hence end the recognition session.
     *
     * Note that it is extremely rare you'd want to specify this value in an intent. If
     * you don't have a very good reason to change these, you should leave them as they are. Note
     * also that certain values may cause undesired or unexpected results - use judiciously!
     * Additionally, depending on the recognizer implementation, these values may have no effect.
     * <p>Note that it is extremely rare you'd want to specify this value in an intent.
     * Generally, it should be specified only when it is also used as the value for
     * {@link #EXTRA_SEGMENTED_SESSION} to enable segmented session mode. Note also that certain
     * values may cause undesired or unexpected results - use judiciously!
     *
     * <p>Depending on the recognizer implementation, these values may have no effect.
     */
    public static final String EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS =
            "android.speech.extras.SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS";
@@ -428,14 +541,21 @@ public class RecognizerIntent {
    public static final String EXTRA_PREFER_OFFLINE = "android.speech.extra.PREFER_OFFLINE";

    /**
     * Optional boolean, when true and supported by the recognizer implementation it will split
     * the recognition results in segments, returned via
     * {@link RecognitionListener#onSegmentResults(Bundle)} and terminate the session with
     * {@link RecognitionListener#onEndOfSegmentedSession()}. There will be no call to
     * {@link RecognitionListener#onResults(Bundle)}. Callers can use
     * {@link #EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS} and
     * {@link #EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS} to tune how long the segments
     * will be. Defaults to false.
     * Optional string to enable segmented session mode of the specified type, which can be
     * {@link #EXTRA_AUDIO_SOURCE}, {@link #EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS} or
     * {@link #EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS}. When segmented session mode is
     * supported by the recognizer implementation and this extra is set, it will return the
     * recognition results in segments via {@link RecognitionListener#onSegmentResults(Bundle)}
     * and terminate the session with {@link RecognitionListener#onEndOfSegmentedSession()}.
     *
     * <p>When setting this extra, make sure the extra used as the string value here is also set
     * in the same intent with proper value.
     *
     * <p>Depending on the recognizer implementation, this value may have no effect.
     *
     * @see #EXTRA_AUDIO_SOURCE
     * @see #EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS
     * @see #EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS
     */
    public static final String EXTRA_SEGMENT_SESSION = "android.speech.extra.SEGMENT_SESSION";
    public static final String EXTRA_SEGMENTED_SESSION = "android.speech.extra.SEGMENTED_SESSION";
}