小编典典
如果您不想使用RecognizerIntent进行语音识别,则仍然可以使用SpeechRecognizer该类来进行语音识别。但是,使用该类比使用意图要难一些。最后一点,我强烈建议让用户知道他何时被记录,否则,当他最终发现时,他可能会非常适应。
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,
"com.domain.app");
SpeechRecognizer recognizer = SpeechRecognizer
.createSpeechRecognizer(this.getApplicationContext());
RecognitionListener listener = new RecognitionListener() {
@Override
public void onResults(Bundle results) {
ArrayList voiceResults = results
.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if (voiceResults == null) {
System.out.println("No voice results");
} else {
System.out.println("Printing match

本文介绍了如何在Android应用中使用SpeechRecognizer类进行语音识别,而非使用RecognizerIntent。强调了在使用SpeechRecognizer时应注意用户体验,及时告知用户录音状态,并提供了语音识别的错误处理方法。请确保在UI线程运行相关代码并获取必要的权限。
最低0.47元/天 解锁文章
3381

被折叠的 条评论
为什么被折叠?



