blob: 5eb71d7eb939657ba0f88502d49ed4f8a4671717 [file] [log] [blame]
Valentin Kravtsov79896bd2010-01-15 11:56:03 +00001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package android.speech;
17
18import android.content.Intent;
19import android.os.Bundle;
20
21/**
Jean-Michel Trivi2a5d9f92010-03-29 18:31:19 -070022 * Used for receiving notifications from the SpeechRecognizer when the
Valentin Kravtsov79896bd2010-01-15 11:56:03 +000023 * recognition related events occur. All the callbacks are executed on the
24 * Application main thread.
25 */
26public interface RecognitionListener {
Valentin Kravtsov79896bd2010-01-15 11:56:03 +000027 /**
28 * Called when the endpointer is ready for the user to start speaking.
29 *
30 * @param params parameters set by the recognition service. Reserved for future use.
31 */
32 void onReadyForSpeech(Bundle params);
33
34 /**
35 * The user has started to speak.
36 */
37 void onBeginningOfSpeech();
38
39 /**
40 * The sound level in the audio stream has changed. There is no guarantee that this method will
41 * be called.
42 *
43 * @param rmsdB the new RMS dB value
44 */
45 void onRmsChanged(float rmsdB);
46
47 /**
48 * More sound has been received. The purpose of this function is to allow giving feedback to the
49 * user regarding the captured audio. There is no guarantee that this method will be called.
50 *
51 * @param buffer a buffer containing a sequence of big-endian 16-bit integers representing a
52 * single channel audio stream. The sample rate is implementation dependent.
53 */
54 void onBufferReceived(byte[] buffer);
55
56 /**
57 * Called after the user stops speaking.
58 */
59 void onEndOfSpeech();
60
61 /**
62 * A network or recognition error occurred.
63 *
Jean-Michel Trivi2a5d9f92010-03-29 18:31:19 -070064 * @param error code is defined in {@link SpeechRecognizer}
Valentin Kravtsov79896bd2010-01-15 11:56:03 +000065 */
66 void onError(int error);
67
68 /**
69 * Called when recognition results are ready.
70 *
71 * @param results the recognition results. To retrieve the results in {@code
72 * ArrayList<String>} format use {@link Bundle#getStringArrayList(String)} with
Jean-Michel Trivi2a5d9f92010-03-29 18:31:19 -070073 * {@link SpeechRecognizer#RESULTS_RECOGNITION} as a parameter
Valentin Kravtsov79896bd2010-01-15 11:56:03 +000074 */
75 void onResults(Bundle results);
76
77 /**
78 * Called when partial recognition results are available. The callback might be called at any
79 * time between {@link #onBeginningOfSpeech()} and {@link #onResults(Bundle)} when partial
80 * results are ready. This method may be called zero, one or multiple times for each call to
Jean-Michel Trivi2a5d9f92010-03-29 18:31:19 -070081 * {@link SpeechRecognizer#startListening(Intent)}, depending on the speech recognition
Alex Gruensteincc47fae2010-02-09 14:36:42 -080082 * service implementation. To request partial results, use
83 * {@link RecognizerIntent#EXTRA_PARTIAL_RESULTS}
Valentin Kravtsov79896bd2010-01-15 11:56:03 +000084 *
85 * @param partialResults the returned results. To retrieve the results in
86 * ArrayList<String> format use {@link Bundle#getStringArrayList(String)} with
Jean-Michel Trivi2a5d9f92010-03-29 18:31:19 -070087 * {@link SpeechRecognizer#RESULTS_RECOGNITION} as a parameter
Valentin Kravtsov79896bd2010-01-15 11:56:03 +000088 */
89 void onPartialResults(Bundle partialResults);
90
Valentin Kravtsov3da3cad2010-01-28 14:53:41 +000091 /**
92 * Reserved for adding future events.
93 *
94 * @param eventType the type of the occurred event
95 * @param params a Bundle containing the passed parameters
96 */
97 void onEvent(int eventType, Bundle params);
Valentin Kravtsov79896bd2010-01-15 11:56:03 +000098}