概述
packagecom.wangfubin.xunfenyuyin;importjava.util.ArrayList;importcom.iflytek.speech.RecognizerResult;importcom.iflytek.speech.SpeechError;importcom.iflytek.ui.RecognizerDialog;importcom.iflytek.ui.RecognizerDialogListener;importandroid.os.Bundle;importandroid.app.Activity;importandroid.app.AlertDialog;importandroid.app.Dialog;importandroid.content.DialogInterface;importandroid.view.Menu;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.Button;importandroid.widget.EditText;importandroid.widget.ImageButton;importandroid.widget.LinearLayout;importandroid.widget.Toast;public class MainActivity extendsActivity {privateEditText setedit;privateImageButton yuyinButton;privateButton button1;private String textString = "";
@Overrideprotected voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button1=(Button)findViewById(R.id.button1);
button1.setOnClickListener(newView.OnClickListener() {
@Overridepublic voidonClick(View v) {
LinearLayout LinearLayout1=(LinearLayout) getLayoutInflater()
.inflate(R.layout.activity_main,null);
setedit=(EditText) LinearLayout1.findViewById(R.searchdialog.editText1);
yuyinButton=(ImageButton) LinearLayout1.findViewById(R.searchdialog.imageButton1);new AlertDialog.Builder(MainActivity.this)
.setTitle("请输入查询关键字")
.setIcon(android.R.drawable.ic_dialog_info)
.setView(LinearLayout1)
.setPositiveButton("取消", null)
.setNegativeButton("确定",newDialogInterface.OnClickListener() {
@Overridepublic voidonClick(DialogInterface arg0,intarg1) {/*// 数据获取
searchtext(setedit.getText().toString());*/Toast.makeText(MainActivity.this, setedit.getText().toString(), Toast.LENGTH_LONG).show();
}
}).show();
yuyinButton.setOnClickListener(newOnClickListener() {
@Overridepublic voidonClick(View v) {//TODO Auto-generated method stub
showDialog(1);
}
});
}
});
}/*** 语音查询*/@Overrideprotected Dialog onCreateDialog(intid) {
RecognizerDialog recognizerDialog= newRecognizerDialog(
MainActivity.this, "appid=5132fe14");//这里应该写从科大讯飞申请到的appid
recognizerDialog.setEngine("sms", null, null);
recognizerDialog.setListener(newRecognizerDialogListener() {
@Overridepublic void onResults(ArrayListresults,booleanarg1) {for (int i = 0; i < results.size(); i++) {
textString+=results.get(i).text;
}
}
@Overridepublic voidonEnd(SpeechError arg0) {//Toast.makeText(MainActivity.this, textString, 1).show();
setedit.setText(textString.substring(0, textString.length() - 1));
textString ="";
}
});returnrecognizerDialog;
}
}
最后
以上就是甜美鲜花为你收集整理的乱码 讯飞 语音识别_教你实现语音识别(基于科大讯飞)的全部内容,希望文章能够帮你解决乱码 讯飞 语音识别_教你实现语音识别(基于科大讯飞)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复