33import android .os .Bundle ;
44import android .speech .RecognitionListener ;
55import android .support .annotation .CallSuper ;
6- import android .util .Log ;
76
8- import com .chattylabs .sdk .android .common . Tag ;
7+ import static com .chattylabs .sdk .android .voice . ConversationalFlowComponent .* ;
98
109
11- abstract class AndroidSpeechRecognitionAdapter implements RecognitionListener {
12- private static final String TAG = Tag .make ("AndroidSpeechRecognitionAdapter" );
13-
10+ abstract class AndroidSpeechRecognitionAdapter
11+ implements RecognitionListener , RecognizerUtteranceListener {
1412 // Settings
1513 private static final int MINIMUM_REACHED_LEVEL_INTENTS = 3 ;
1614 private static final float DEFAULT_THRESHOLD_LOW_SOUND = 5f ;
@@ -22,11 +20,11 @@ abstract class AndroidSpeechRecognitionAdapter implements RecognitionListener {
2220 static final int LOW_SOUND = 2 ;
2321 static final int NORMAL_SOUND = 3 ;
2422
25- private ConversationalFlowComponent . OnRecognizerReady onReady ;
26- private ConversationalFlowComponent . OnRecognizerResults onResults ;
27- private ConversationalFlowComponent . OnRecognizerPartialResults onPartialResults ;
28- private ConversationalFlowComponent . OnRecognizerMostConfidentResult onMostConfidentResult ;
29- private ConversationalFlowComponent . OnRecognizerError onError ;
23+ private OnRecognizerReady onReady ;
24+ private OnRecognizerResults onResults ;
25+ private OnRecognizerPartialResults onPartialResults ;
26+ private OnRecognizerMostConfidentResult onMostConfidentResult ;
27+ private OnRecognizerError onError ;
3028
3129 private boolean tryAgain ;
3230 private int soundLevel = UNKNOWN ;
@@ -36,44 +34,53 @@ abstract class AndroidSpeechRecognitionAdapter implements RecognitionListener {
3634 private int lowSoundIntents ;
3735 private int normalSoundIntents ;
3836
39- public void setOnReady (ConversationalFlowComponent .OnRecognizerReady onReady ) {
37+ @ Override
38+ public void _setOnReady (OnRecognizerReady onReady ) {
4039 this .onReady = onReady ;
4140 }
4241
43- public ConversationalFlowComponent .OnRecognizerResults getOnResults () {
42+ @ Override
43+ public OnRecognizerResults _getOnResults () {
4444 return onResults ;
4545 }
4646
47- public AndroidSpeechRecognitionAdapter setOnResults (ConversationalFlowComponent .OnRecognizerResults onResults ) {
47+ @ Override
48+ public AndroidSpeechRecognitionAdapter _setOnResults (OnRecognizerResults onResults ) {
4849 this .onResults = onResults ;
4950 return this ;
5051 }
5152
52- public ConversationalFlowComponent .OnRecognizerPartialResults getOnPartialResults () {
53+ @ Override
54+ public OnRecognizerPartialResults _getOnPartialResults () {
5355 return onPartialResults ;
5456 }
5557
56- public AndroidSpeechRecognitionAdapter setOnPartialResults (
57- ConversationalFlowComponent .OnRecognizerPartialResults onPartialResults ) {
58+ @ Override
59+ public AndroidSpeechRecognitionAdapter _setOnPartialResults (
60+ OnRecognizerPartialResults onPartialResults ) {
5861 this .onPartialResults = onPartialResults ;
5962 return this ;
6063 }
6164
62- public ConversationalFlowComponent .OnRecognizerMostConfidentResult getOnMostConfidentResult () {
65+ @ Override
66+ public OnRecognizerMostConfidentResult _getOnMostConfidentResult () {
6367 return onMostConfidentResult ;
6468 }
6569
66- public AndroidSpeechRecognitionAdapter setOnMostConfidentResult (
67- ConversationalFlowComponent .OnRecognizerMostConfidentResult onMostConfidentResult ) {
70+ @ Override
71+ public AndroidSpeechRecognitionAdapter _setOnMostConfidentResult (
72+ OnRecognizerMostConfidentResult onMostConfidentResult ) {
6873 this .onMostConfidentResult = onMostConfidentResult ;
6974 return this ;
7075 }
7176
72- public ConversationalFlowComponent .OnRecognizerError getOnError () {
77+ @ Override
78+ public OnRecognizerError _getOnError () {
7379 return onError ;
7480 }
7581
76- public AndroidSpeechRecognitionAdapter setOnError (ConversationalFlowComponent .OnRecognizerError onError ) {
82+ @ Override
83+ public AndroidSpeechRecognitionAdapter _setOnError (OnRecognizerError onError ) {
7784 this .onError = onError ;
7885 return this ;
7986 }
@@ -109,10 +116,6 @@ public void setSoundLevel(int soundLevel) {
109116 this .soundLevel = soundLevel ;
110117 }
111118
112- public abstract void startTimeout ();
113-
114- public abstract void reset ();
115-
116119 String getSoundLevelAsString (int level ) {
117120 switch (level ) {
118121 case NO_SOUND :
@@ -128,7 +131,6 @@ String getSoundLevelAsString(int level) {
128131
129132 @ Override @ CallSuper
130133 public void onReadyForSpeech (Bundle params ) {
131- //if (BuildConfig.DEBUG) System.out.println("onReadyForSpeech: " + params);
132134 if (onReady != null ) onReady .execute (params );
133135 }
134136
@@ -137,19 +139,19 @@ public void onBeginningOfSpeech() {
137139 }
138140
139141 @ Override
140- public void onRmsChanged (float rmsdB ) {
141- if (rmsdB % 1 == 0 ) return ;
142- if (rmsDebug ) Log . v ( TAG , "RECOGNITION - Rms db: " + rmsdB );
142+ public void onRmsChanged (float rmsDb ) {
143+ if (rmsDb % 1 == 0 ) return ;
144+ if (rmsDebug ) System . out . printf ( " Rms db: %s" , rmsDb );
143145
144- if (rmsdB <= noSoundThreshold && soundLevel <= NO_SOUND ) {
146+ if (rmsDb <= noSoundThreshold && soundLevel <= NO_SOUND ) {
145147 soundLevel = NO_SOUND ;
146148 // quiet
147- } else if (rmsdB > noSoundThreshold && rmsdB < lowSoundThreshold && soundLevel <= LOW_SOUND ) {
149+ } else if (rmsDb > noSoundThreshold && rmsDb < lowSoundThreshold && soundLevel <= LOW_SOUND ) {
148150 lowSoundIntents ++;
149151 if (lowSoundIntents > MINIMUM_REACHED_LEVEL_INTENTS )
150152 soundLevel = LOW_SOUND ;
151153 // medium
152- } else if (rmsdB >= lowSoundThreshold && soundLevel <= NORMAL_SOUND ) {
154+ } else if (rmsDb >= lowSoundThreshold && soundLevel <= NORMAL_SOUND ) {
153155 lowSoundIntents ++;
154156 if (lowSoundIntents > MINIMUM_REACHED_LEVEL_INTENTS && soundLevel <= LOW_SOUND )
155157 soundLevel = LOW_SOUND ;
@@ -182,6 +184,5 @@ public void onPartialResults(Bundle partialResults) {
182184
183185 @ Override
184186 public void onEvent (int eventType , Bundle params ) {
185- //if (BuildConfig.DEBUG) System.out.println("onEvent: " + eventType + " - " + params);
186187 }
187188}
0 commit comments