Configuring the length of utterance and pauses in Android's speech recognizer

左心房为你撑大大i 提交于 2019-12-10 11:47:14

问题


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

    }
}

回答1:


The API has 3 EXTRAs for that

  • EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS
  • EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS
  • EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS

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.)




回答2:


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.



来源:https://stackoverflow.com/questions/19308184/configuring-the-length-of-utterance-and-pauses-in-androids-speech-recognizer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!