该应用程序用新的文本覆盖旧文本,但这不是目的。我希望新文本除了保留新文本之外还保留旧文本,例如将新旧文本转换为字符串,然后将它们组合在一起?
final SpeechRecognizer mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
final Intent mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
mSpeechRecognizer.setRecognitionListener(new RecognitionListener() {
@Override
public void onResults(Bundle bundle) {
//getting all the matches
ArrayList<String> matches = bundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
//displaying the first match
if (matches != null)
resultText.setText(matches.get(0));
}
});
答案 0 :(得分:7)
因此您想将结果附加到TextView吗?
这很简单:
resultText.append(matches.get(0));
有空格:
resultText.append(" " + matches.get(0));
另一种方式:
resultText.setText(resultText.getText() + " " + matches.get(0));