我正在尝试创建允许连续运行 Android 语音识别引擎的服务。我在Android Speech Recognition as a service on Android 4.1 & 4.2 上看到了一个示例,并接受了它,但不知何故,无论说什么,我总是在侦听器 onError() 方法中收到 SpeechRecognizer.ERROR_NO_MATCH 错误。当然,永远不会调用 onResults()。该服务的代码与上面链接的答案完全相同,我的启动代码是:
Intent startServiceIntent = null;
Log.d(TAG, "Creating new intent for the recognition service");
startServiceIntent = new Intent(getApplicationContext(), SpeechRecognitionService.class);
Log.d(TAG, "Starting the speech recognition service ...");
getApplicationContext().startService(startServiceIntent);
int duration = Toast.LENGTH_LONG;
CharSequence text = "Starting speech recognition ...";
Toast toast = Toast.makeText(getApplicationContext(), text, duration);
toast.show();
但是当我通过发送 Intent 直接调用语音识别引擎时,它工作得很好:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Start talking");
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 10);
startActivityForResult(intent, 1234);
我所有的测试都是在 Note2 上运行的,上面有 Android 4.1.2。有没有人遇到过这个问题并且可能知道如何解决这个问题?谢谢