0
我正尝试在提供的代码here的服务中运行语音识别API,并且遇到问题。无法在服务中启动语音识别
我的活动有以下线路:
protected void onCreate(Bundle savedInstanceState) {
......
Intent startConstantSR = new Intent("MyService.class");
getApplicationContext().startService(startConstantSR);
....
}
和服务的onCreate看起来像这样
public void onCreate()
{super.onCreate();
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
mSpeechRecognizer.setRecognitionListener(new SpeechRecognitionListener());
mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
this.getPackageName());
mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
}
我在onReadyForSpeech和onBeginningOfSpeech成立了吐司展现出来,所以我知道我在正确的道路上 - 但没有烤面包。
我在做什么错?我找不到,因为我几乎不了解服务。
道具编写整个代码! –