179896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov/*
279896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov * Copyright (C) 2010 The Android Open Source Project
379896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov *
479896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov * Licensed under the Apache License, Version 2.0 (the "License");
579896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov * you may not use this file except in compliance with the License.
679896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov * You may obtain a copy of the License at
779896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov *
879896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov *      http://www.apache.org/licenses/LICENSE-2.0
979896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov *
1079896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov * Unless required by applicable law or agreed to in writing, software
1179896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov * distributed under the License is distributed on an "AS IS" BASIS,
1279896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1379896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov * See the License for the specific language governing permissions and
1479896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov * limitations under the License.
1579896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov */
1679896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsovpackage android.speech;
1779896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov
1879896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsovimport android.content.Intent;
1979896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsovimport android.os.Bundle;
2079896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov
2179896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov/**
222a5d9f9b577376768372837723f0f42098aba13bJean-Michel Trivi * Used for receiving notifications from the SpeechRecognizer when the
2379896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov * recognition related events occur. All the callbacks are executed on the
2479896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov * Application main thread.
2579896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov */
2679896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsovpublic interface RecognitionListener {
2779896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    /**
2879896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * Called when the endpointer is ready for the user to start speaking.
2979896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     *
3079896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * @param params parameters set by the recognition service. Reserved for future use.
3179896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     */
3279896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    void onReadyForSpeech(Bundle params);
3379896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov
3479896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    /**
3579896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * The user has started to speak.
3679896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     */
3779896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    void onBeginningOfSpeech();
3879896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov
3979896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    /**
4079896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * The sound level in the audio stream has changed. There is no guarantee that this method will
4179896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * be called.
4279896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     *
4379896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * @param rmsdB the new RMS dB value
4479896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     */
4579896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    void onRmsChanged(float rmsdB);
4679896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov
4779896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    /**
4879896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * More sound has been received. The purpose of this function is to allow giving feedback to the
4979896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * user regarding the captured audio. There is no guarantee that this method will be called.
5079896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     *
5179896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * @param buffer a buffer containing a sequence of big-endian 16-bit integers representing a
5279896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     *        single channel audio stream. The sample rate is implementation dependent.
5379896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     */
5479896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    void onBufferReceived(byte[] buffer);
5579896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov
5679896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    /**
5779896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * Called after the user stops speaking.
5879896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     */
5979896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    void onEndOfSpeech();
6079896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov
6179896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    /**
6279896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * A network or recognition error occurred.
6379896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     *
642a5d9f9b577376768372837723f0f42098aba13bJean-Michel Trivi     * @param error code is defined in {@link SpeechRecognizer}
6579896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     */
6679896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    void onError(int error);
6779896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov
6879896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    /**
6979896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * Called when recognition results are ready.
7079896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     *
7179896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * @param results the recognition results. To retrieve the results in {@code
7279896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     *        ArrayList<String>} format use {@link Bundle#getStringArrayList(String)} with
73bb7cf916b23c78dc640f8bdfb7ad5cd6b09c3636Mike LeBeau     *        {@link SpeechRecognizer#RESULTS_RECOGNITION} as a parameter. A float array of
74bb7cf916b23c78dc640f8bdfb7ad5cd6b09c3636Mike LeBeau     *        confidence values might also be given in {@link SpeechRecognizer#CONFIDENCE_SCORES}.
7579896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     */
7679896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    void onResults(Bundle results);
7779896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov
7879896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    /**
7979896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * Called when partial recognition results are available. The callback might be called at any
8079896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * time between {@link #onBeginningOfSpeech()} and {@link #onResults(Bundle)} when partial
8179896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * results are ready. This method may be called zero, one or multiple times for each call to
822a5d9f9b577376768372837723f0f42098aba13bJean-Michel Trivi     * {@link SpeechRecognizer#startListening(Intent)}, depending on the speech recognition
83cc47fae688e55edefd0abd15811d674ba47889e0Alex Gruenstein     * service implementation.  To request partial results, use
84cc47fae688e55edefd0abd15811d674ba47889e0Alex Gruenstein     * {@link RecognizerIntent#EXTRA_PARTIAL_RESULTS}
8579896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     *
8679896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     * @param partialResults the returned results. To retrieve the results in
8779896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     *        ArrayList<String> format use {@link Bundle#getStringArrayList(String)} with
882a5d9f9b577376768372837723f0f42098aba13bJean-Michel Trivi     *        {@link SpeechRecognizer#RESULTS_RECOGNITION} as a parameter
8979896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov     */
9079896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov    void onPartialResults(Bundle partialResults);
9179896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov
923da3cad97269d694a6153771fb4a0c3775ca6ab5Valentin Kravtsov    /**
933da3cad97269d694a6153771fb4a0c3775ca6ab5Valentin Kravtsov     * Reserved for adding future events.
943da3cad97269d694a6153771fb4a0c3775ca6ab5Valentin Kravtsov     *
953da3cad97269d694a6153771fb4a0c3775ca6ab5Valentin Kravtsov     * @param eventType the type of the occurred event
963da3cad97269d694a6153771fb4a0c3775ca6ab5Valentin Kravtsov     * @param params a Bundle containing the passed parameters
973da3cad97269d694a6153771fb4a0c3775ca6ab5Valentin Kravtsov     */
983da3cad97269d694a6153771fb4a0c3775ca6ab5Valentin Kravtsov    void onEvent(int eventType, Bundle params);
9979896bd123aa3bc69c6455d4e2ddf2b2b555e6e5Valentin Kravtsov}
100