2

I have android's Speech To Text API to speak something to the phone and convert it into text. By default, if one stops speaking to the microphone, the API assumes that the user is done talking and returns the text from the input speech.

For my application, the user might have long pauses between her consecutive sentences. How can I configure Android's speech to text API to consider the end of the speech only when I ask it to and not do that as soon as the speaker takes a small pause between sentences? Thanks!

Here is my current implementation which simply converts speech to text as soon as the user takes a small pause between sentences:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    case RESULT_SPEECH: {
        if (resultCode == RESULT_OK && null != data) {

            ArrayList<String> text = data
                    .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

            txtText.setText(text.get(0));
        }
        break;
    }

    }
}
Kaarel
  • 10,554
  • 4
  • 56
  • 78
Darth.Vader
  • 5,079
  • 7
  • 50
  • 90
  • possible duplicate of [Voice Recognition stops listening after a few seconds](http://stackoverflow.com/questions/13670378/voice-recognition-stops-listening-after-a-few-seconds) – Nikolay Shmyrev Oct 11 '13 at 06:04
  • Please do not close this question. It's clearly different from http://stackoverflow.com/questions/13670378/voice-recognition-stops-listening-after-a-few-seconds and much better written. – Kaarel Oct 11 '13 at 13:28

2 Answers2

1

The API has 3 EXTRAs for that

But note that the API also says that "depending on the recognizer implementation, these values may have no effect", so you just have to test with the implementation that you are using if they have any effect or not. (I haven't done this test myself, so it would be great if you added a comment to this answer reporting your test results.)

Kaarel
  • 10,554
  • 4
  • 56
  • 78
1

Prior to Android 4.1 (or users of the Google Search/Now app) this will work for you:

int someValue = 5;
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, Long.valueOf(someValue * 1000L));

Unfortunately later versions no longer react to this parameter, a great shame as it makes lengthy note taking or email composing impossible....

I have brought the issue to their attention.

brandall
  • 6,094
  • 4
  • 49
  • 103