Skip to content

Commit

Permalink
Fixed problem with recognition error. Applied for all recognizer vers…
Browse files Browse the repository at this point in the history
…ions.
  • Loading branch information
Gusarov Roman committed Sep 10, 2015
1 parent 4a31da8 commit 5b044a2
Showing 1 changed file with 2 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public class GoogleRecognitionServiceImpl extends AIService {
private final Handler handler;

private volatile boolean wasReadyForSpeech;
private String googleRecognizerVersion;


private final Map<Integer, String> errorMessages = new HashMap<Integer, String>();
Expand All @@ -93,13 +92,11 @@ public GoogleRecognitionServiceImpl(final Context context, final AIConfiguration
}

handler = new Handler(context.getMainLooper());

googleRecognizerVersion = RecognizerChecker.getGoogleRecognizerVersion(context);
}

protected void initializeRecognizer() {

if (speechRecognizer != null && affectedWithGoogleSearchProblem()) {
if (speechRecognizer != null) {
return;
}

Expand Down Expand Up @@ -282,19 +279,6 @@ private void runInUiThread(final Runnable runnable) {
handler.post(runnable);
}

/**
* Workaround for http://stackoverflow.com/questions/31071650/speechrecognizer-throws-onerror-on-the-first-listening
* @return
*/
private boolean affectedWithGoogleSearchProblem() {
if (googleRecognizerVersion != null) {
if (googleRecognizerVersion.contains("4.7.13.19")) {
return true;
}
}
return false;
}

private class InternalRecognitionListener implements RecognitionListener {

@Override
Expand Down Expand Up @@ -331,11 +315,7 @@ public void onEndOfSpeech() {

@Override
public void onError(final int error) {

// workaround for http://stackoverflow.com/questions/31071650/speechrecognizer-throws-onerror-on-the-first-listening
if (error == SpeechRecognizer.ERROR_NO_MATCH
&& affectedWithGoogleSearchProblem()
&& !wasReadyForSpeech) {
if (error == SpeechRecognizer.ERROR_NO_MATCH && !wasReadyForSpeech) {
return;
}

Expand Down

0 comments on commit 5b044a2

Please sign in to comment.