问题
How do you record and transcribe continuous speech on Android?
Want to record and transcribe speech in Android for a mobile (cordova) app. How is it possible to force the Android API for speech recognition NOT to stop recording when it thinks speech is done? Have tried setting all of the parameters. The parameters that would seem to guarantee continuous recognition (see below) do not seem to work, even when tried in a whole bunch of values/combinations. No matter what values we have tried to pass, the speech recognition algorithm seems to stop and return after about 1-2 seconds of silence. Some of the parameters currently being used are set below. With these parameters, speech recognition stops after 1-2s of silence. Uncommenting the other parameter doesn't solve this. Similarly, trying to DICTATION_MODE on/off doesn't work, and using partial results on/off doesn't solve the problem either (as recognition still ends). Changing the lengths of the MILLIS parameters also hasn't yielded a positive result so far.
So far, several different available cordova speech recognition plugins, and edits to them to change the underlying parameters, have led to the same problem (as described above).
Here is the current cordova code, taken from one of the several cordova speech plugins.
private void startRecognition() {
final Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,lang);
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, "12000");
// intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, "12000");
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, "12000");
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, "12000");
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, false);
intent.putExtra("android.speech.extra.DICTATION_MODE", true);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5);
Handler loopHandler = new Handler(Looper.getMainLooper());
loopHandler.post(new Runnable() {
@Override
public void run() {
recognizer.startListening(intent);
}
});
PluginResult res = new PluginResult(PluginResult.Status.NO_RESULT);
res.setKeepCallback(true);
this.speechRecognizerCallbackContext.sendPluginResult(res);
}
来源:https://stackoverflow.com/questions/54157013/android-continuous-speechrecognition-preventing-end