Android语音超时-语音识别

时间:2019-01-15 10:12:16

标签: android speech-recognition speech-to-text

我正在构建一个通过语音识别收集用户数据的应用程序。我的问题是,仅在大约5秒钟之前调用语音超时错误,这会使语音识别器无法识别任何其他语音。我的问题是:如何增加超时错误的时间或如何停止错误。

我的代码:

SpeechRecogniser sr = createSpeechRecogniser(this)
recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,"en");

recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);

sr.startListening(recogniserIntent);
sr.setOnRecognitionListener(new OnRecognitionListener(){
    //implenent all its methods
    onError(int code){
        switch(code){
            case ERROR_SPEECH_TIMEOUT:
            //this is where the error is called and stops the speech recogniser
            //i want the time for this error to be increased
            break;

            }
        }
});

1 个答案:

答案 0 :(得分:0)

这些可选参数有助于延长时间,如果您需要增加时间(服务通过该参数遵守的时间有限制),则您将必须像stackoverflow.com/a/49810988/806328中那样覆盖重写器识别侦听器

recognizerIntent.PutExtra(RecognizerIntent.ActionRecognizeSpeech, RecognizerIntent.ExtraPreferOffline);
            recognizerIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1000); 
            recognizerIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1000);
            recognizerIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 1500);