gpt4 book ai didi

android - 如何在 Android 中暂停和恢复 SpeechRecognizer?

转载 作者:行者123 更新时间:2023-11-29 22:03:49 24 4
gpt4 key购买 nike

我正在使用 SpeechRecognizer 类。

这是我的代码:

SpeechRecognizer     speechRecognizer;
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(getBaseContext());
MyRecognitionListener speechListner=new MyRecognitionListener();
speechRecognizer.setRecognitionListener(speechListner);
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, getApplication().getPackageName());
speechRecognizer.startListening(intent);

问题是我无法暂停和恢复它。我已经尝试过:

speechRecognizer.cancel();
speechRecognizer.stopListening();

但它仍然在听。

最佳答案

您不能对已取消的 SpeechRecognizer 调用 stopListening()。在 cancel() 之前调用它。

speechRecognizer.stopListening();
speechRecognizer.cancel();

关于android - 如何在 Android 中暂停和恢复 SpeechRecognizer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11304334/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com