【发布时间】:2012-11-05 05:49:10
【问题描述】:
我有一个相当奇怪的问题。我有一个 android 应用程序,我正在使用 SpeechRecognizer 类为其添加语音识别。我创建了实现 RecognitionListener 的类,它只为每个事件打印一条日志消息。一切似乎都很好。 onReadyForSpeech 被触发,onBeginningOfSpeech 被触发,onEndOfSpeech 被触发。
一个重要的事件并没有被触发,onResults :p
因此,在夏季,一切似乎都很好,没有抛出异常,并且我收到事件告诉我它已成功启动并停止侦听。我是否缺少一些额外的意图来告诉 SpeechRecognizer 它需要将结果发送到 onResults 或类似的东西?
我将意图设置如下
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, getClass().getPackage().getName());
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
SpeechRecognizer 是这样完成的
SpeechRecognizer speech = SpeechRecognizer.createSpeechRecognizer(this);
speech.setRecognitionListener(this);
我开始听
speech.startListening(intent);
【问题讨论】:
-
查看您从
onError收到的错误代码。 -
onError 没有被调用,这是奇怪的部分。我将其隔离为网络问题,因为如果我关闭无线并使用 3G,它就可以工作。如果我也关闭 3G(根本没有网络)onError 会触发。尝试了另一个无线,它也可以在那里工作,但是在我的无线工作中,它不起作用并且不会调用 onError。
标签: java android artificial-intelligence speech-recognition