RecognitionListener.java revision 79896bd123aa3bc69c6455d4e2ddf2b2b555e6e5
1/* 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/** 22 * Used for receiving notifications from the RecognitionManager when the 23 * recognition related events occur. All the callbacks are executed on the 24 * Application main thread. 25 */ 26public interface RecognitionListener { 27 28 /** 29 * Called when RecognitionManager is successfully initialized 30 */ 31 void onInit(); 32 33 /** 34 * Called when the endpointer is ready for the user to start speaking. 35 * 36 * @param params parameters set by the recognition service. Reserved for future use. 37 */ 38 void onReadyForSpeech(Bundle params); 39 40 /** 41 * The user has started to speak. 42 */ 43 void onBeginningOfSpeech(); 44 45 /** 46 * The sound level in the audio stream has changed. There is no guarantee that this method will 47 * be called. 48 * 49 * @param rmsdB the new RMS dB value 50 */ 51 void onRmsChanged(float rmsdB); 52 53 /** 54 * More sound has been received. The purpose of this function is to allow giving feedback to the 55 * user regarding the captured audio. There is no guarantee that this method will be called. 56 * 57 * @param buffer a buffer containing a sequence of big-endian 16-bit integers representing a 58 * single channel audio stream. The sample rate is implementation dependent. 59 */ 60 void onBufferReceived(byte[] buffer); 61 62 /** 63 * Called after the user stops speaking. 64 */ 65 void onEndOfSpeech(); 66 67 /** 68 * A network or recognition error occurred. 69 * 70 * @param error code is defined in {@link RecognitionManager} 71 */ 72 void onError(int error); 73 74 /** 75 * Called when recognition results are ready. 76 * 77 * @param results the recognition results. To retrieve the results in {@code 78 * ArrayList<String>} format use {@link Bundle#getStringArrayList(String)} with 79 * {@link RecognitionManager#RECOGNITION_RESULTS_STRING_ARRAY} as a parameter 80 */ 81 void onResults(Bundle results); 82 83 /** 84 * Called when partial recognition results are available. The callback might be called at any 85 * time between {@link #onBeginningOfSpeech()} and {@link #onResults(Bundle)} when partial 86 * results are ready. This method may be called zero, one or multiple times for each call to 87 * {@link RecognitionManager#startListening(Intent)}, depending on the speech recognition 88 * service implementation. 89 * 90 * @param partialResults the returned results. To retrieve the results in 91 * ArrayList<String> format use {@link Bundle#getStringArrayList(String)} with 92 * {@link RecognitionManager#RECOGNITION_RESULTS_STRING_ARRAY} as a parameter 93 */ 94 void onPartialResults(Bundle partialResults); 95 96} 97