当我调用SpeechRecognizer对象的startListening方法时,语音识别器开始侦听语音。我想创建一个等待特定关键字的语音的服务:当用户说出该关键字并且语音识别器检测到该关键字时,该服务将准备好接收用户的语音命令。
为此,在实例化一个新的SpeechRecognizer之后,我应该调用它的startListening方法:我可以让语音识别器无限期地侦听吗?
发布于 2012-04-17 07:26:04
Android Speech recognizer可以通过意向额外数据进行定制。参见the android documentation。
公共静态最终字符串EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS
在我们停止收听语音后,认为输入完成所需的时间。..。
公共静态最终字符串API final:EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS Level 8
话语的最小长度。在此时间之前,我们不会停止录制。..。
公共静态最终字符串EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS
在我们停止听到语音后,认为输入可能完成所需的时间。..。
将EXTRA_LANGUAGE_MODEL设置为websearch,以便仅捕获相关的单词。
发布于 2018-06-07 01:49:44
您可以这样实现RecognitionListener接口的onError。它会在你的活动中持续倾听。
@Override
public void onError(int error) {
String errorMessage = getErrorText(error);
Log.i(Constants.TAG, "FAILED " + errorMessage);
speech.destroy();
speech = null;
StartListening();
}
private void StartListening() {
speech = SpeechRecognizer.createSpeechRecognizer(this);
speech.setRecognitionListener(this);
recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName());
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
//if setting.SpeechEnable
speech.startListening(recognizerIntent);
}https://stackoverflow.com/questions/10182893
复制相似问题