Example usage for android.speech SpeechRecognizer ERROR_SPEECH_TIMEOUT

List of usage examples for android.speech SpeechRecognizer ERROR_SPEECH_TIMEOUT

Introduction

In this page you can find the example usage for android.speech SpeechRecognizer ERROR_SPEECH_TIMEOUT.

Prototype

int ERROR_SPEECH_TIMEOUT

To view the source code for android.speech SpeechRecognizer ERROR_SPEECH_TIMEOUT.

Click Source Link

Document

No speech input

Usage

From source file:com.chexiaoya.gaodemapdemo.SpeechSearchActivity.java

@Override
public void onError(int error) {
    status = STATUS_None;/*from  w w  w.j a  v  a 2s  .co m*/
    StringBuilder sb = new StringBuilder();
    switch (error) {
    case SpeechRecognizer.ERROR_AUDIO:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_CLIENT:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS:
        sb.append("???");
        break;
    case SpeechRecognizer.ERROR_NETWORK:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_NO_MATCH:
        sb.append("?");
        break;
    case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_SERVER:
        sb.append("?");
        break;
    case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:
        sb.append("");
        break;
    }
    sb.append(":" + error);
    showToast(sb.toString());
}

From source file:com.baidu.android.voicedemo.ActivityTouch.java

@Override
public void onError(int error) {
    StringBuilder sb = new StringBuilder();
    switch (error) {
    case SpeechRecognizer.ERROR_AUDIO:
        sb.append("");
        break;/*from   w  ww  .j a  v a  2  s .c  om*/
    case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_CLIENT:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS:
        sb.append("???");
        break;
    case SpeechRecognizer.ERROR_NETWORK:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_NO_MATCH:
        sb.append("?");
        break;
    case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_SERVER:
        sb.append("?");
        break;
    case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:
        sb.append("");
        break;
    }
    sb.append(":" + error);
    print("" + sb.toString());
}

From source file:conversandroid.MainActivity.java

/**
 * Provides feedback to the user when the ASR encounters an error
 *//*from  w  ww . j a  v  a 2s . com*/
@Override
public void processAsrError(int errorCode) {
    changeButtonAppearanceToDefault();

    //Possible bug in Android SpeechRecognizer: NO_MATCH errors even before the the ASR
    // has even tried to recognized. We have adopted the solution proposed in:
    // http://stackoverflow.com/questions/31071650/speechrecognizer-throws-onerror-on-the-first-listening
    long duration = System.currentTimeMillis() - startListeningTime;
    if (duration < 500 && errorCode == SpeechRecognizer.ERROR_NO_MATCH) {
        Log.e(LOGTAG, "Doesn't seem like the system tried to listen at all. duration = " + duration
                + "ms. Going to ignore the error");
        stopListening();
    } else {
        String errorMsg = "";
        switch (errorCode) {
        case SpeechRecognizer.ERROR_AUDIO:
            errorMsg = "Audio recording error";
        case SpeechRecognizer.ERROR_CLIENT:
            errorMsg = "Unknown client side error";
        case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS:
            errorMsg = "Insufficient permissions";
        case SpeechRecognizer.ERROR_NETWORK:
            errorMsg = "Network related error";
        case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:
            errorMsg = "Network operation timed out";
        case SpeechRecognizer.ERROR_NO_MATCH:
            errorMsg = "No recognition result matched";
        case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:
            errorMsg = "RecognitionService busy";
        case SpeechRecognizer.ERROR_SERVER:
            errorMsg = "Server sends error status";
        case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
            errorMsg = "No speech input";
        default:
            errorMsg = ""; //Another frequent error that is not really due to the ASR, we will ignore it
        }
        if (errorMsg != "") {
            Log.e(LOGTAG, "Error when attempting to listen: " + errorMsg);

            try {
                speak(errorMsg, "EN", ID_PROMPT_INFO);
            } catch (Exception e) {
                Log.e(LOGTAG, "English not available for TTS, default language used instead");
            }
        }
    }

}

From source file:com.ct.speech.HintReceiver.java

/**
 * Fire an intent to start the speech recognition activity.
 * /*from   w w  w .  ja  v  a  2  s  .  c  om*/
 * @param args
 *            Argument array with the following string args: [req
 *            code][number of matches][prompt string] Google speech
 *            recognizer
 */

private void startSpeechRecognitionActivity(JSONArray args) {
    // int reqCode = 42; // Hitchhiker? // global now
    int maxMatches = 2;
    String prompt = "";
    String language = "";
    try {
        if (args.length() > 0) {
            // Request code - passed back to the caller on a successful
            // operation
            String temp = args.getString(0);
            reqCode = Integer.parseInt(temp);
        }
        if (args.length() > 1) {
            // Maximum number of matches, 0 means the recognizer decides
            String temp = args.getString(1);
            maxMatches = Integer.parseInt(temp);
        }
        if (args.length() > 2) {
            // Optional text prompt
            prompt = args.getString(2);
        }
        if (args.length() > 3) {
            // Optional language specified
            language = args.getString(3);
        }
    } catch (Exception e) {
        Log.e(TAG, String.format("startSpeechRecognitionActivity exception: %s", e.toString()));
    }
    final Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra("calling_package", "com.ct.BasicAppFrame");
    // If specific language
    if (!language.equals("")) {
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
    }
    if (maxMatches > 0)
        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxMatches);
    if (!(prompt.length() == 0))
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);
    // ctx.startActivityForResult(this, intent, reqCode); //removed to try
    // using recognizer directly
    try {
        this.ctx.runOnUiThread(new Runnable() {
            public void run() {
                final SpeechRecognizer recognizer = SpeechRecognizer.createSpeechRecognizer((Context) ctx);
                RecognitionListener listener = new RecognitionListener() {
                    @Override
                    public void onResults(Bundle results) {
                        //closeRecordedFile();
                        sendBackResults(results);
                        ArrayList<String> voiceResults = results
                                .getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
                        if (voiceResults == null) {
                            Log.e(TAG, "No voice results");
                        } else {
                            // Log.d(TAG, "Printing matches: ");
                            for (@SuppressWarnings("unused")
                            String match : voiceResults) {
                                // Log.d(TAG, match);
                            }
                        }
                        recognizer.destroy();
                    }

                    @Override
                    public void onReadyForSpeech(Bundle params) {
                        // Log.d(TAG, "Ready for speech");
                    }

                    @Override
                    public void onError(int error) {
                        Log.d(TAG, "Error listening for speech: " + error);
                        if (error == SpeechRecognizer.ERROR_NO_MATCH) {
                            sendBackResults(NO_MATCH);
                        } else if (error == SpeechRecognizer.ERROR_SPEECH_TIMEOUT) {
                            sendBackResults(NO_INPUT);
                        } else {
                            speechFailure("unknown error");
                        }
                        recognizer.destroy();
                    }

                    @Override
                    public void onBeginningOfSpeech() {
                        // Log.d(TAG, "Speech starting");
                        setStartOfSpeech();
                    }

                    @Override
                    //doesn't fire in Android after Ice Cream Sandwich
                    public void onBufferReceived(byte[] buffer) {
                    }

                    @Override
                    public void onEndOfSpeech() {
                        setEndOfSpeech();
                    }

                    @Override
                    public void onEvent(int eventType, Bundle params) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onPartialResults(Bundle partialResults) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onRmsChanged(float rmsdB) {
                        // TODO Auto-generated method stub

                    }
                };
                recognizer.setRecognitionListener(listener);
                Log.d(TAG, "starting speech recognition activity");
                recognizer.startListening(intent);
            }
        });
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.baidu.android.voicedemo.ApiActivity.java

@Override
public void onError(int error) {
    status = STATUS_None;/*from   www  .ja v a  2s . co  m*/
    StringBuilder sb = new StringBuilder();
    switch (error) {
    case SpeechRecognizer.ERROR_AUDIO:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_CLIENT:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS:
        sb.append("???");
        break;
    case SpeechRecognizer.ERROR_NETWORK:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_NO_MATCH:
        sb.append("?");
        break;
    case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_SERVER:
        sb.append("?");
        break;
    case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:
        sb.append("");
        break;
    }
    sb.append(":" + error);
    print("" + sb.toString());
    btn.setText("");
}

From source file:cn.laojing.smarthome.VoiceActivity.java

@Override
public void onError(int error) {
    StringBuilder sb = new StringBuilder();
    switch (error) {
    case SpeechRecognizer.ERROR_AUDIO:
        sb.append("");
        break;/*from w  ww .j a va2s.co  m*/
    case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_CLIENT:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS:
        sb.append("???");
        break;
    case SpeechRecognizer.ERROR_NETWORK:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_NO_MATCH:
        sb.append("?");
        break;
    case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_SERVER:
        sb.append("?");
        break;
    case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:
        sb.append("");
        break;
    }
    sb.append(":" + error);
    print("" + sb.toString());
    start();
}

From source file:conversandroid.RichASR.java

@Override
public void onError(final int errorCode) {

    //Possible bug in Android SpeechRecognizer: NO_MATCH errors even before the the ASR
    // has even tried to recognized. We have adopted the solution proposed in:
    // http://stackoverflow.com/questions/31071650/speechrecognizer-throws-onerror-on-the-first-listening
    long duration = System.currentTimeMillis() - startListeningTime;
    if (duration < 500 && errorCode == SpeechRecognizer.ERROR_NO_MATCH) {
        Log.e(LOGTAG, "Doesn't seem like the system tried to listen at all. duration = " + duration
                + "ms. Going to ignore the error");
        stopListening();//from w  w  w .  j  av  a  2  s. co  m
    } else {
        String errorMsg = "";
        switch (errorCode) {
        case SpeechRecognizer.ERROR_AUDIO:
            errorMsg = "Audio recording error";
        case SpeechRecognizer.ERROR_CLIENT:
            errorMsg = "Unknown client side error";
        case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS:
            errorMsg = "Insufficient permissions";
        case SpeechRecognizer.ERROR_NETWORK:
            errorMsg = "Network related error";
        case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:
            errorMsg = "Network operation timed out";
        case SpeechRecognizer.ERROR_NO_MATCH:
            errorMsg = "No recognition result matched";
        case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:
            errorMsg = "RecognitionService busy";
        case SpeechRecognizer.ERROR_SERVER:
            errorMsg = "Server sends error status";
        case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
            errorMsg = "No speech input";
        default:
            errorMsg = "";
        }
        if (errorCode == 5 && errorMsg == "") {
            //Log.e(LOGTAG, "Going to ignore the error");
            //Another frequent error that is not really due to the ASR
        } else {
            ((TextView) findViewById(R.id.feedbackTxt)).setText("Error :( " + errorMsg);
            Log.e(LOGTAG, "Error -> " + errorMsg);
            stopListening();
        }
    }
}

From source file:cn.jasonlv.siri.activity.MainActivity.java

@Override
public void onError(int error) {
    status = STATUS_None;/*ww w.j  a v  a  2  s .  com*/
    StringBuilder sb = new StringBuilder();
    switch (error) {
    case SpeechRecognizer.ERROR_AUDIO:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_CLIENT:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS:
        sb.append("???");
        break;
    case SpeechRecognizer.ERROR_NETWORK:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_NO_MATCH:
        sb.append("?");
        break;
    case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:
        sb.append("");
        break;
    case SpeechRecognizer.ERROR_SERVER:
        sb.append("?");
        break;
    case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:
        sb.append("");
        break;
    }
    sb.append(":" + error);
    print("" + sb.toString());
    //btn.setText("");
}

From source file:com.glabs.homegenie.util.VoiceControl.java

@Override
public void onError(int i) {
    String message;//from   www. ja  va2s. co m
    switch (i) {
    case SpeechRecognizer.ERROR_AUDIO:
        message = "Audio recording error";
        break;
    case SpeechRecognizer.ERROR_CLIENT:
        message = "Client side error";
        //restart = false;
        break;
    case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS:
        message = "Insufficient permissions";
        //restart = false;
        break;
    case SpeechRecognizer.ERROR_NETWORK:
        message = "Network error";
        break;
    case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:
        message = "Network timeout";
        break;
    case SpeechRecognizer.ERROR_NO_MATCH:
        message = "No match";
        break;
    case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:
        message = "RecognitionService busy";
        break;
    case SpeechRecognizer.ERROR_SERVER:
        message = "error from server";
        break;
    case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
        message = "No speech input";
        break;
    default:
        message = "Not recognised";
        break;
    }
    Toast.makeText(_hgcontext.getApplicationContext(), "Recognizer: " + message, 10000).show();
    _recognizer.destroy();
    _recognizer = null;
}

From source file:org.botlibre.sdk.activity.MicConfiguration.java

@Override
public void onError(int error) {
    isRecording = false;/*from www  .  j av  a 2  s .co m*/

    lastReply = System.currentTimeMillis();

    this.speech.destroy();
    this.speech = SpeechRecognizer.createSpeechRecognizer(this);
    this.speech.setRecognitionListener(this);

    setMicIcon(false, false);

    muteMicBeep(false);

    setStreamVolume();

    if (error == SpeechRecognizer.ERROR_AUDIO) {
        Log.d("System.out", "Error: Audio Recording Error");
    } else if (error == SpeechRecognizer.ERROR_CLIENT) {
        Log.d("System.out", "Error: Other client side error");
        restartListening();
    } else if (error == SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS) {
        Log.d("System.out", "Error: INsufficient permissions");
    } else if (error == SpeechRecognizer.ERROR_NETWORK) {
        Log.d("System.out", "Error: Other network Error");
    } else if (error == SpeechRecognizer.ERROR_NETWORK_TIMEOUT) {
        Log.d("System.out", "Error: Network operation timed out");
    } else if (error == SpeechRecognizer.ERROR_NO_MATCH) {
        Log.d("System.out", "Error: No recognition result matched");
        restartListening();
    } else if (error == SpeechRecognizer.ERROR_RECOGNIZER_BUSY) {
        Log.d("System.out", "Error: Recognition service busy");
        restartListening();
    } else if (error == SpeechRecognizer.ERROR_SERVER) {
        Log.d("System.out", "Error: Server Error");
        restartListening();
    } else if (error == SpeechRecognizer.ERROR_SPEECH_TIMEOUT) {
        Log.d("System.out", "Error: NO speech input");
        restartListening();
    }

}