Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

speech recognition times out too soon in android

Tags:

java

android

This function starts speech recognition, but it times out too soon, where as if Speech recognition is started from the IME keyboard (eg Google keyboard) it does not timeout so quickly. I need a way to start the same intent as is used by the google keyboard.

public void StartSpeechRecognitionActivity(){
    try{
        Intent intent = new   Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
        intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 3000);
        intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 3000);
        main.startActivityForResult(intent, SPEECHRECOGNITION_RESULTCODE);
    } catch (ActivityNotFoundException error) {
        ShowAndSpeakMessage("Speech recognition is not supported by your device");
    } catch( RuntimeException error ) {
        Log.e( TAG, ERROR_PREFIX + Errors.toString(error) );
    } catch( Error error ) {
        Log.e( TAG, ERROR_PREFIX + Errors.toString(error) );
        throw error;
    }
}
like image 506
Farhan Munir Avatar asked Jul 15 '13 11:07

Farhan Munir


1 Answers

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
                            "Voice recognition!");
startActivityForResult(intent, REQUEST_CODE);

This just works fine for me!

like image 200
intrepidkarthi Avatar answered Oct 05 '22 07:10

intrepidkarthi