我正在开发一个Android应用程序,它总是监听用户的声音。当我在 Sony X10i 上运行时它可以工作,但在 Samsung Galaxy SII 上则不起作用。
这是我的代码:
SpeechRecognizer speechRecognizer;
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(getBaseContext());
MyRecognitionListener speechListner=new MyRecognitionListener();
speechRecognizer.setRecognitionListener(speechListner);
speechRecognizer.startListening(RecognizerIntent.getVoiceDetailsIntent(getApplicationContext()));
这是我的监听器类:
class MyRecognitionListener implements RecognitionListener {
public void onBeginningOfSpeech() {
Log.d("leapkh", "onBeginningOfSpeech");
}
public void onBufferReceived(byte[] buffer) {
Log.d("leapkh", "onBufferReceived");
}
public void onEndOfSpeech() {
Log.d("leapkh", "onEndOfSpeech");
}
public void onError(int error) {
Log.d("leapkh", "onError");
}
public void onEvent(int eventType, Bundle params) {
Log.d("leapkh", "onEvent");
}
public void onPartialResults(Bundle partialResults) {
Log.d("leapkh", "onPartialResults");
}
public void onReadyForSpeech(Bundle params) {
Log.d("leapkh", "onReadyForSpeech");
}
public void onResults(Bundle results) {
Log.d("leapkh", "onResults");
}
public void onRmsChanged(float rmsdB) {
Log.d("leapkh", "onRmsChanged");
}
}
在这种情况下,如何解决这个问题呢?
我找到了解决方案。
改变参数speechRecognizer.startListening()
方法intent
如下:
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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)