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

Commit 79896bd1 authored by Valentin Kravtsov's avatar Valentin Kravtsov
Browse files

Adding Recognition Service and Listener wrappers

Change-Id: Ib5068fb6d42b6752d09b0828964b6cbe92d015d3
parent c30ffda0
Loading
Loading
Loading
Loading
+347 −0
Original line number Diff line number Diff line
@@ -134157,6 +134157,320 @@
</package>
<package name="android.speech"
>
<interface name="RecognitionListener"
 abstract="true"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<method name="onBeginningOfSpeech"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="onBufferReceived"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="buffer" type="byte[]">
</parameter>
</method>
<method name="onEndOfSpeech"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="onError"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="error" type="int">
</parameter>
</method>
<method name="onInit"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="onPartialResults"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="partialResults" type="android.os.Bundle">
</parameter>
</method>
<method name="onReadyForSpeech"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="params" type="android.os.Bundle">
</parameter>
</method>
<method name="onResults"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="results" type="android.os.Bundle">
</parameter>
</method>
<method name="onRmsChanged"
 return="void"
 abstract="true"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="rmsdB" type="float">
</parameter>
</method>
</interface>
<class name="RecognitionManager"
 extends="java.lang.Object"
 abstract="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<method name="cancel"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="createRecognitionManager"
 return="android.speech.RecognitionManager"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="context" type="android.content.Context">
</parameter>
<parameter name="listener" type="android.speech.RecognitionListener">
</parameter>
<parameter name="recognizerIntent" type="android.content.Intent">
</parameter>
</method>
<method name="destroy"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="isRecognitionAvailable"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="context" type="android.content.Context">
</parameter>
</method>
<method name="startListening"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="recognizerIntent" type="android.content.Intent">
</parameter>
</method>
<method name="stopListening"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<field name="AUDIO_ERROR"
 type="int"
 transient="false"
 volatile="false"
 value="3"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="CLIENT_ERROR"
 type="int"
 transient="false"
 volatile="false"
 value="5"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="MANAGER_NOT_INITIALIZED_ERROR"
 type="int"
 transient="false"
 volatile="false"
 value="9"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="NETWORK_ERROR"
 type="int"
 transient="false"
 volatile="false"
 value="2"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="NETWORK_TIMEOUT_ERROR"
 type="int"
 transient="false"
 volatile="false"
 value="1"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="NO_MATCH_ERROR"
 type="int"
 transient="false"
 volatile="false"
 value="7"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="RECOGNITION_RESULTS_STRING_ARRAY"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;recognition_results_string_array&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="SERVER_BUSY_ERROR"
 type="int"
 transient="false"
 volatile="false"
 value="8"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="SERVER_ERROR"
 type="int"
 transient="false"
 volatile="false"
 value="4"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="SPEECH_TIMEOUT_ERROR"
 type="int"
 transient="false"
 volatile="false"
 value="6"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</class>
<class name="RecognizerIntent"
 extends="java.lang.Object"
 abstract="false"
@@ -134275,6 +134589,39 @@
 visibility="public"
>
</field>
<field name="EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;android.speech.extras.SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;android.speech.extras.SPEECH_INPUT_MINIMUM_LENGTH_MILLIS&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;android.speech.extras.SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="LANGUAGE_MODEL_FREE_FORM"
 type="java.lang.String"
 transient="false"
+34 −15
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package android.speech;

import android.os.Bundle;
import android.speech.RecognitionResult;

/**
 * Listener for speech recognition events, used with RecognitionService.
@@ -26,35 +25,55 @@ import android.speech.RecognitionResult;
 *  {@hide}
 */
interface IRecognitionListener {
    /** Called when the endpointer is ready for the user to start speaking. */
    void onReadyForSpeech(in Bundle noiseParams);
    /**
     * Called when the endpointer is ready for the user to start speaking.
     *
     * @param params parameters set by the recognition service. Reserved for future use.
     */
    void onReadyForSpeech(in Bundle params);

    /** The user has started to speak. */
    /**
     * The user has started to speak.
     */
    void onBeginningOfSpeech();

    /** The sound level in the audio stream has changed. */
    /**
     * The sound level in the audio stream has changed.
     *
     * @param rmsdB the new RMS dB value
     */
    void onRmsChanged(in float rmsdB);

    /**
     * More sound has been received. Buffer is a byte buffer containing
     * a sequence of 16-bit shorts. 
     * More sound has been received.
     *
     * @param buffer the byte buffer containing a sequence of 16-bit shorts.
     */
    void onBufferReceived(in byte[] buffer);

    /** Called after the user stops speaking. */
    /**
     * Called after the user stops speaking.
     */
    void onEndOfSpeech();

    /**
     * A network or recognition error occurred. The code is defined in
     * {@link android.speech.RecognitionResult}
     * A network or recognition error occurred.
     *
     * @param error code is defined in {@link RecognitionManager}
     */
    void onError(in int error);

    /**
     * Called when recognition results are ready.
     * @param results: an ordered list of the most likely results (N-best list).
     * @param key: a key associated with the results. The same results can
     * be retrieved asynchronously later using the key, if available. 
     *
     * @param results a Bundle containing the most likely results (N-best list).
     */
    void onResults(in Bundle results);

     /**
     * Called when recognition partial results are ready.
     *
     * @param results a Bundle containing the current most likely result.
     */
    void onResults(in List<RecognitionResult> results, long key);
    void onPartialResults(in Bundle results);
}
+31 −12
Original line number Diff line number Diff line
@@ -16,22 +16,41 @@

package android.speech;

import android.os.Bundle;
import android.content.Intent;
import android.speech.IRecognitionListener;
import android.speech.RecognitionResult;

// A Service interface to speech recognition. Call startListening when
// you want to begin capturing audio; RecognitionService will automatically
// determine when the user has finished speaking, stream the audio to the
// recognition servers, and notify you when results are ready.
/** {@hide} */
/**
* A Service interface to speech recognition. Call startListening when
* you want to begin capturing audio; RecognitionService will automatically
* determine when the user has finished speaking, stream the audio to the
* recognition servers, and notify you when results are ready. In most of the cases, 
* this class should not be used directly, instead use {@link RecognitionManager} for
* accessing recognition service. 
* {@hide}
*/
interface IRecognitionService {
    // Start listening for speech. Can only call this from one thread at once.
    // see RecognizerIntent.java for constants used to specify the intent.
    void startListening(in Intent recognizerIntent,
        in IRecognitionListener listener);
    /**
     * Starts listening for speech. Please note that the recognition service supports
     * one listener only, therefore, if this function is called from two different threads,
     * only the latest one will get the notifications
     *
     * @param recognizerIntent the intent from which the invocation occurred. Additionally,
     *        this intent can contain extra parameters to manipulate the behavior of the recognition
     *        client. For more information see {@link RecognizerIntent}.
     * @param listener to receive callbacks
     */
    void startListening(in Intent recognizerIntent, in IRecognitionListener listener);

    List<RecognitionResult> getRecognitionResults(in long key);
    /**
     * Stops listening for speech. Speech captured so far will be recognized as
     * if the user had stopped speaking at this point. The function has no effect unless it
     * is called during the speech capturing.
     */
    void stopListening();

    /**
     * Cancels the speech recognition.
     */
    void cancel();
}
+96 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 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.content.Intent;
import android.os.Bundle;

/**
 * Used for receiving notifications from the RecognitionManager when the
 * recognition related events occur. All the callbacks are executed on the
 * Application main thread.
 */
public interface RecognitionListener {

    /**
     * Called when RecognitionManager is successfully initialized
     */
    void onInit();

    /**
     * Called when the endpointer is ready for the user to start speaking.
     * 
     * @param params parameters set by the recognition service. Reserved for future use.
     */
    void onReadyForSpeech(Bundle params);

    /**
     * The user has started to speak.
     */
    void onBeginningOfSpeech();

    /**
     * The sound level in the audio stream has changed. There is no guarantee that this method will
     * be called.
     * 
     * @param rmsdB the new RMS dB value
     */
    void onRmsChanged(float rmsdB);

    /**
     * More sound has been received. The purpose of this function is to allow giving feedback to the
     * user regarding the captured audio. There is no guarantee that this method will be called.
     * 
     * @param buffer a buffer containing a sequence of big-endian 16-bit integers representing a
     *        single channel audio stream. The sample rate is implementation dependent.
     */
    void onBufferReceived(byte[] buffer);

    /**
     * Called after the user stops speaking.
     */
    void onEndOfSpeech();

    /**
     * A network or recognition error occurred.
     * 
     * @param error code is defined in {@link RecognitionManager}
     */
    void onError(int error);

    /**
     * Called when recognition results are ready.
     * 
     * @param results the recognition results. To retrieve the results in {@code
     *        ArrayList&lt;String&gt;} format use {@link Bundle#getStringArrayList(String)} with
     *        {@link RecognitionManager#RECOGNITION_RESULTS_STRING_ARRAY} as a parameter
     */
    void onResults(Bundle results);

    /**
     * Called when partial recognition results are available. The callback might be called at any
     * time between {@link #onBeginningOfSpeech()} and {@link #onResults(Bundle)} when partial
     * results are ready. This method may be called zero, one or multiple times for each call to
     * {@link RecognitionManager#startListening(Intent)}, depending on the speech recognition
     * service implementation.
     * 
     * @param partialResults the returned results. To retrieve the results in
     *        ArrayList&lt;String&gt; format use {@link Bundle#getStringArrayList(String)} with
     *        {@link RecognitionManager#RECOGNITION_RESULTS_STRING_ARRAY} as a parameter
     */
    void onPartialResults(Bundle partialResults);

}
+321 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading