15

この関数は音声認識を開始しますが、タイムアウトが早すぎます。音声認識が IME キーボード (Google キーボードなど) から開始された場合と同様に、すぐにはタイムアウトしません。Google キーボードで使用されているのと同じインテントを開始する方法が必要です。

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;
    }
}
4

3 に答える 3