【发布时间】:2013-10-14 09:41:02
【问题描述】:
我正在为我的应用程序进行语音识别,我尝试了这段代码并 我在我的 logcat 中收到错误,因为 intent must not null exception 在 android 中
public class SpeechRecognizerActivity extends Activity {
/** Called when the activity is first created. */
String a;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView txt=(TextView)findViewById(R.id.textView1);
class MyRecognitionListener implements RecognitionListener {
@Override
public void onBeginningOfSpeech() {
Log.d("Speech", "onBeginningOfSpeech");
}
@Override
public void onBufferReceived(byte[] buffer) {
Log.d("Speech", "onBufferReceived");
}
@Override
public void onEndOfSpeech() {
Log.d("Speech", "onEndOfSpeech");
}
@Override
public void onError(int error) {
Log.d("Speech", "onError");
}
@Override
public void onEvent(int eventType, Bundle params) {
Log.d("Speech", "onEvent");
}
@Override
public void onPartialResults(Bundle partialResults) {
Log.d("Speech", "onPartialResults");
}
@Override
public void onReadyForSpeech(Bundle params) {
Log.d("Speech", "onReadyForSpeech");
}
@Override
public void onResults(Bundle results) {
Log.d("Speech", "onResults");
ArrayList<String> strlist = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
for (int i = 0; i < strlist.size();i++ ) {
Log.d("Speech", "result=" + strlist.get(i));
}
}
@Override
public void onRmsChanged(float rmsdB) {
Log.d("Speech", "onRmsChanged");
}
}
SpeechRecognizer sr = SpeechRecognizer.createSpeechRecognizer(getApplicationContext());
MyRecognitionListener listener = new MyRecognitionListener();
sr.setRecognitionListener(listener);
sr.startListening(RecognizerIntent.getVoiceDetailsIntent(getApplicationContext()));
}
}
请建议我,我犯了什么错误或必须在之前设置一些设置 运行程序之前的模拟器。
【问题讨论】:
-
你在你的代码中做了什么?你是如何试图识别我无法理解的声音?!!!在实施之前,您是否喜欢任何教程?
-
@GrIsHu 我认为 user2582340 不想打开语音输入活动,因此尝试使用 SpeechRecognizer,这里回答的问题是:stackoverflow.com/questions/6316937/…
-
到目前为止有什么结果吗?其中一个答案对你有用吗?
标签: android speech-recognition