当持续通话时,RecogniseListener工作正常,但每当有5-10秒的静音时,会调用监听器的onReadyForSpeech()方法,但永远不会调用onBegginingOfSpeech()。
这是我的听众:
sr = SpeechRecognizer.createSpeechRecognizer(this);
sr.setRecognitionListener(new RecognitionListener() {
@Override
public void onReadyForSpeech(Bundle params) {
}
@Override
public void onBeginningOfSpeech() {
}
@Override
public void onRmsChanged(float rmsdB) {
}
@Override
public void onBufferReceived(byte[] buffer) {
}
@Override
public void onEndOfSpeech() {
startRecognising();
}
@Override
public void onError(int error) {
}
@Override
public void onResults(Bundle results) {
adapter.add(new MessageData(MessageData.TYPE_VOICE, recognisedText.getText().toString()), 0);
recyclerView.scrollToPosition(0);
recognisedText.setText("");
}
@Override
public void onPartialResults(Bundle partialResults) {
ArrayList data = partialResults.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
String word = (String) data.get(data.size() - 1);
recognisedText.setText(word);
}
@Override
public void onEvent(int eventType, Bundle params) {
}
});
startRecognising()方法:
private void startRecognising(){
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 20000000);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,1);
sr.startListening(intent);
}
顺便说一下,有没有可以实时识别语音的免费替代方案?