源程序如下:
infoShow = (EditText)findViewById(R.id.EdText);
errorInfoShow = (EditText)findViewById(R.id.errorEdText);butStartTest = (Button)findViewById(R.id.butStarttest);
edStart = (EditText)findViewById(R.id.EdStartText);
butStartTest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v.getId() == R.id.butStarttest) {
mSpeechRecognizer.startListening(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH));
}
}
});
mSpeechRecognizer= SpeechRecognizer.createSpeechRecognizer(this,new ComponentName(this,VoiceRecognitionService.class));
RecognitionListener listener = new RecognitionListener() {@Override
public void onReadyForSpeech(Bundle params) {
Log.d("准备开始语音识别",params.toString());
edStart.setText("准备开始语音识别");
}
@Override
public void onBeginningOfSpeech() {
edStart.setText("开始语音识别");
}
@Override
public void onRmsChanged(float rmsdB) {
}
@Override
public void onBufferReceived(byte[] buffer) {
}
@Override
public void onEndOfSpeech() {
infoShow.setText("语音识别结束");
}
@Override
public void onError(int error) {
Log.d("My speech test","error"+error);
infoShow.setText("My speech test error"+error);
}
@Override
public void onResults(Bundle results) {
String strResult = new String();
Log.d("My speech test", "onResults " + results);
ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
for (int i = 0; i < data.size(); i++)
{
Log.d("My speech test", "result " + data.get(i));
strResult += data.get(i);
}
// 显示被识别的数据
infoShow.setText(strResult);
}
@Override
public void onPartialResults(Bundle partialResults) {
}
@Override
public void onEvent(int eventType, Bundle params) {
switch (eventType) {
case 11: // eventType == 11 表是返回详细错误信息
String reason = params.get("reason") + "";
errorInfoShow.setText("EVENT_ERROR, " + reason + "\nEVENT_TYPE," + eventType);
break;
}
}
};
mSpeechRecognizer.setRecognitionListener(listener);
}
现象就是 开始调用就反馈error 7
新手,求解答,万分感谢。
请登录后评论
TOP
切换版块
您好,只通过代码可以参考的信息不足,谢谢支持