2020import java .util .concurrent .Executors ;
2121import java .util .concurrent .locks .ReentrantLock ;
2222
23- import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .MIN_VOICE_RECOGNITION_TIME_LISTENING ;
2423import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .OnRecognizerError ;
2524import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .OnRecognizerMostConfidentResult ;
2625import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .OnRecognizerPartialResults ;
2726import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .OnRecognizerReady ;
2827import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .OnRecognizerResults ;
29- import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .RECOGNIZER_AFTER_PARTIALS_ERROR ;
30- import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .RECOGNIZER_EMPTY_RESULTS_ERROR ;
31- import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .RECOGNIZER_LOW_SOUND_ERROR ;
32- import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .RECOGNIZER_NO_SOUND_ERROR ;
33- import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .RECOGNIZER_RETRY_ERROR ;
34- import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .RECOGNIZER_STOPPED_TOO_EARLY_ERROR ;
35- import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .RECOGNIZER_UNAVAILABLE_ERROR ;
36- import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .RECOGNIZER_UNKNOWN_ERROR ;
37- import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .RecognizerListenerContract ;
28+ import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .RecognizerListener ;
3829import static com .chattylabs .sdk .android .voice .ConversationalFlowComponent .selectMostConfidentResult ;
3930
4031public final class AndroidSpeechRecognizer implements ConversationalFlowComponent .SpeechRecognizer {
@@ -49,12 +40,12 @@ public final class AndroidSpeechRecognizer implements ConversationalFlowComponen
4940
5041 // Resources
5142 private final Application application ;
52- private final VoiceConfig config ;
43+ private final ComponentConfig config ;
5344 private final AndroidHandler mainHandler ;
5445 private final AndroidAudioHandler audioHandler ;
5546 private final BluetoothSco bluetoothSco ;
5647 private final Intent speechRecognizerIntent ;
57- private final SpeechRecognizerCreator recognizerCreator ;
48+ private final SpeechRecognizerCreator < android . speech . SpeechRecognizer > recognizerCreator ;
5849 private final ExecutorService executorService ;
5950 private SpeechRecognizer speechRecognizer ;
6051
@@ -98,7 +89,7 @@ public void run() {
9889 });
9990 }
10091 };
101- timeout .schedule (task , MIN_VOICE_RECOGNITION_TIME_LISTENING * 3 );
92+ timeout .schedule (task , RecognizerListener . MIN_VOICE_RECOGNITION_TIME_LISTENING * 3 );
10293 }
10394
10495 private void cleanup () {
@@ -134,7 +125,8 @@ public void onReadyForSpeech(Bundle params) {
134125 public void onError (int error ) {
135126 logger .e (TAG , "ANDROID VOICE - error: " + getErrorType (error ));
136127 // We consider 2 sec as timeout for non speech
137- boolean stoppedTooEarly = (System .currentTimeMillis () - elapsedTime ) < ConversationalFlowComponent .MIN_VOICE_RECOGNITION_TIME_LISTENING ;
128+ boolean stoppedTooEarly = (System .currentTimeMillis () - elapsedTime ) <
129+ ConversationalFlowComponent .RecognizerListener .MIN_VOICE_RECOGNITION_TIME_LISTENING ;
138130 // Start checking for the error
139131 OnRecognizerError errorListener = getOnError ();
140132 int soundLevel = getSoundLevel ();
@@ -143,27 +135,27 @@ public void onError(int error) {
143135 cancel ();
144136 if (errorListener != null ) {
145137 if (needRetry (error )) {
146- errorListener .execute (RECOGNIZER_UNAVAILABLE_ERROR , error );
138+ errorListener .execute (RecognizerListener . RECOGNIZER_UNAVAILABLE_ERROR , error );
147139 }
148140 else if (stoppedTooEarly ) {
149- errorListener .execute (RECOGNIZER_STOPPED_TOO_EARLY_ERROR , error );
141+ errorListener .execute (RecognizerListener . RECOGNIZER_STOPPED_TOO_EARLY_ERROR , error );
150142 }
151143 else if (soundLevel == NO_SOUND ) {
152- errorListener .execute (RECOGNIZER_NO_SOUND_ERROR , error );
144+ errorListener .execute (RecognizerListener . RECOGNIZER_NO_SOUND_ERROR , error );
153145 }
154146 else if (soundLevel == LOW_SOUND ) {
155- errorListener .execute (RECOGNIZER_LOW_SOUND_ERROR , error );
147+ errorListener .execute (RecognizerListener . RECOGNIZER_LOW_SOUND_ERROR , error );
156148 }
157149 else if (intents > 0 ) {
158- errorListener .execute (RECOGNIZER_AFTER_PARTIALS_ERROR , error );
150+ errorListener .execute (RecognizerListener . RECOGNIZER_AFTER_PARTIALS_ERROR , error );
159151 }
160152 else if (isTryAgain ()) {
161153 errorListener .execute (error == SpeechRecognizer .ERROR_NO_MATCH ?
162- RECOGNIZER_UNKNOWN_ERROR :
163- RECOGNIZER_RETRY_ERROR , error );
154+ RecognizerListener . RECOGNIZER_UNKNOWN_ERROR :
155+ RecognizerListener . RECOGNIZER_RETRY_ERROR , error );
164156 }
165157 else { // Restore ANDROID VOICE
166- errorListener .execute (RECOGNIZER_UNKNOWN_ERROR , error );
158+ errorListener .execute (RecognizerListener . RECOGNIZER_UNKNOWN_ERROR , error );
167159 }
168160 }
169161 }
@@ -192,7 +184,7 @@ public void onResults(Bundle results) {
192184 logger .e (TAG , "ANDROID VOICE - NO results" );
193185 OnRecognizerError listener = getOnError ();
194186 reset ();
195- if (listener != null ) listener .execute (RECOGNIZER_EMPTY_RESULTS_ERROR , -1 );
187+ if (listener != null ) listener .execute (RecognizerListener . RECOGNIZER_EMPTY_RESULTS_ERROR , -1 );
196188 }
197189 }
198190
@@ -226,7 +218,7 @@ private boolean needRetry(int error) {
226218 // Log stuff
227219 private ILogger logger ;
228220
229- AndroidSpeechRecognizer (Application application , VoiceConfig configuration ,
221+ AndroidSpeechRecognizer (Application application , ComponentConfig configuration ,
230222 AndroidAudioHandler audioHandler , BluetoothSco bluetoothSco ,
231223 SpeechRecognizerCreator recognizerCreator , ILogger logger ) {
232224 this .application = application ;
@@ -322,7 +314,7 @@ public void shutdown() {
322314 }
323315
324316 @ Override
325- public void listen (RecognizerListenerContract ... listeners ) {
317+ public void listen (RecognizerListener ... listeners ) {
326318 logger .i (TAG , "ANDROID VOICE - start listening" );
327319 handleListeners (listeners );
328320 // Check whether Sco is connected or required
@@ -382,10 +374,10 @@ private void startListening() {
382374 });
383375 }
384376
385- private void handleListeners (RecognizerListenerContract ... listeners ) {
377+ private void handleListeners (RecognizerListener ... listeners ) {
386378 recognitionListener .reset ();
387379 if (listeners != null && listeners .length > 0 ) {
388- for (RecognizerListenerContract item : listeners ) {
380+ for (RecognizerListener item : listeners ) {
389381 if (item instanceof OnRecognizerReady ) {
390382 recognitionListener .setOnReady ((OnRecognizerReady ) item );
391383 }
0 commit comments