问题
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