版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
目录一、 设计背景 2二、 需求分析 2三、 设计名称 3四、 设计目的 3五、 设计原理及工具 3六、 设计步骤及结果 4七、 设计总结 27
设计背景随着移动通信与Internet向移动终端的普及,网络和用户对移动终端的要求越来越高Windowsmobi1e,Palm0s等手机平台过于封闭,不能很好的满足用户的需求,因此市场迫切需要一个开发性很强的平台。经过多年的发展,第四代数字通信(4G)技术活动了广泛的接受,它为移动终端用户带来了更快的数据传输速率。随着4G网络的使用,移动终端不再仅是通讯网络的终端,还将成为互联网的终端。因此,移动终端的应用软件和需要的服务将会有很大的发展空间。Goog1e为此于2007年11月推出了一个专为移动设备设计的软件平台Android是一套真正意义上的开发性的移动设备综合平台,它包括操作系统、中间件和些关键的平台应用。Android是由Linux+Java构成的开源软件,允许所有厂商和个人在其基础上进行开发。Android平台的开放性等特点既能促进技术(包括斗平台本身)的创新又有助于降低开发成本,还可以是运营商能非常方便地制定自己的特色化的产品。因此,它具有很大的市场发展潜力。需求分析如今,伴随着Goog1eAndroid操作系统的盛行,基于AndroidsDK的系统开发和基于Android应用的开发等已倍受大家关注。Android应用面向的是普通个体用户,这些用户往往会更加关注用户体验,因此Android应用增加多媒体功能十分必要。就目前的手机发展趋势来看,手机已经不再是单一的通讯工具,更多的手机用户希望在工作、学习之余通过方便灵巧可随身携带的仪器休闲娱乐。而且近年来,由于人们生活水平的提高,越来越多的人开始关注聊天交互,尤其是不会打字的人。因此为了迎合众多用户的需求并适应现在的手机的规模,我设计了一个语音识别应用程序。设计名称虎宝语音设计目的本设计是在学习Android平台软件开发的课程的基础上进行的一次综合实践。通过本课程设计,让学生们巩固下有关Android平台软件开发的知识,也考查学生们的学习情况。同时为方便与家人的语音交互聊天,让聊天更便捷。设计原理及工具设计原理在安卓工程中,引入第三方SDK,集成到项目中,实现功能。使用工具AndroidStudio开发工具AndroidStudio是一个Android集成开发工具,基于IntelliJIDEA.类似EclipseADT,AndroidStudio提供了集成的Android开发工具用于开发和调试。在IDEA的基础上,AndroidStudio提供:基于Gradle的构建支持Android专属的重构和快速修复提示工具以捕获性能、可用性、版本兼容性等问题支持ProGuard和应用签名基于模板的向导来生成常用的Android应用设计和组件功能强大的布局编辑器,可以让你拖拉UI控件并进行效果预览Mob短信验证SDK短信验证码SDK,为开发者提供全球通用的短信验证码工具,开发者可以用其在App植入短信验证码SDK、简单设置即可短信验证,集成快速便捷,且后期易于管理。讯飞语音听写SDK语音听写,主要是将连续的语音快速识别为文字的过程。这是一个非常有用的接口,它让机器人实现了听懂人的话。而,更加人性化的是,开发者可以针对某一个应用,根据特定场景下的用词,按照格式上传一些高频的词语,让科大的分析引擎通过机器学习,从而对这些词语有着更高的识别率。而且,科大官方也提出了几个听写的模型,通俗理解就是一些场景,针对这些场景,某些词语的识别率更高。设计步骤及结果在工程中集成第三方SDK,短信验证SDK和讯飞听写SDK。在工程build.gradle,加入代码://添加MobSDK的maven地址
maven{
url"/android"
}//注册MobSDK
classpath'com.mob.sdk:MobSDK:+'在个人build.gradle,加入代码:applyplugin:'com.mob.sdk'
//在MobSDK的扩展中注册SMSSDK的相关信息
MobSDK{
appKey"265d096d83eb9"
appSecret"32b1e7b67e2a3a9c894ff66ce38d87fa"
SMSSDK{}
}布局文件编写创建项目dhy203grapp01。修改主Activity的布局文件denglu_jm.xml,编写代码如下:<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayout
xmlns:android="/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.example.dhy203grapp01.CustomToolBar
xmlns:android="/apk/res/android"
xmlns:tools="/tools"
xmlns:app="/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:left_tv_visible="false"
app:left_tv_text="返回"
app:right_btn_visible="false"
app:right_btn_src="@mipmap/ic_launcher"
app:title_visible="true"
app:title_text="用户登录"
tools:context="com.example.dhy203grapp01.MainActivity">
</com.example.dhy203grapp01.CustomToolBar>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/huhu"
android:layout_marginTop="86dp"
android:layout_gravity="center"
/>
<LinearLayout
android:layout_width="280dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:layout_marginTop="40dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="手机号:"
android:textSize="18sp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/et_phonenum"
android:hint="请输入手机号"
android:inputType="phone"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_check"
android:text="获取验证码"
android:layout_gravity="center"
android:background="#1296db"
android:textColor="#ffffff"
android:textSize="18sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="280dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:layout_marginTop="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="验证码:"
android:textSize="18sp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/et_checkecode"
android:hint="请输入验证码"
android:inputType="phone"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_sure"
android:text="验证"
android:layout_gravity="center"
android:background="#1296db"
android:textColor="#ffffff"
android:textSize="18sp"/>
</LinearLayout>
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/btn_dl"
android:text="登录"
android:layout_marginTop="26dp"
android:layout_gravity="center"
android:background="#1296db"
android:textColor="#ffffff"
android:textSize="18sp"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/bj01"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="注册账号"
android:layout_alignParentLeft="true"
android:textSize="18sp"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:textColor="#1296db"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="忘记密码"
android:layout_alignParentRight="true"
android:textSize="18sp"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:textColor="#1296db"/>
</RelativeLayout>
</LinearLayout>在loyout文件夹下,创建activity_main.xml,编写代码如下:<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayout
xmlns:android="/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.example.dhy203grapp01.CustomToolBar
xmlns:android="/apk/res/android"
xmlns:tools="/tools"
xmlns:app="/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:left_tv_visible="false"
app:left_tv_text="返回"
app:right_btn_visible="false"
app:right_btn_src="@mipmap/ic_launcher"
app:title_visible="true"
app:title_text="语音输入"
tools:context="com.example.dhy203grapp01.MainActivity">
</com.example.dhy203grapp01.CustomToolBar>
<LinearLayout
android:layout_width="280dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:layout_marginTop="40dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="您想要说的:"
android:textSize="28sp"/>
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#55cccccc"
android:textSize="28sp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="start"
android:text="开始听写"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="stop"
android:text="停止听写"/>
</LinearLayout>
</LinearLayout>标题栏布局文件,创建layout_common_toolbar.xml文件,代码如下:<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/toolbar_content_rlyt"
android:layout_width="match_parent"
android:layout_height="58dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:background="@color/bg_toolbar">
<Button
android:id="@+id/toolbar_left_btn"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentLeft="true"
android:padding="50dp"
android:gravity="center"
android:layout_centerVertical="true"
android:background="@mipmap/ic_launcher"
android:visibility="invisible"/>
<TextView
android:id="@+id/toolbar_left_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="center"
android:layout_centerVertical="true"
android:textColor="#fff"
android:textSize="15sp"
android:text="返回"
android:visibility="gone"
/>
<TextView
android:id="@+id/toolbar_title_tv"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:layout_centerInParent="true"
android:singleLine="true"
android:text="标题"
android:textSize="20sp"
android:textColor="#fff"
android:maxEms="10"
android:visibility="invisible"/>
<Button
android:id="@+id/toolbar_right_btn"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:gravity="center"
android:layout_centerVertical="true"
android:visibility="invisible"
android:background="#00000000"
android:textSize="15sp"
android:textColor="#fff"/>
<TextView
android:id="@+id/toolbar_right_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="center"
android:layout_centerVertical="true"
android:textColor="#fff"
android:textSize="15sp"
android:text="更多"
android:visibility="gone"/>
</RelativeLayout>
</LinearLayout>配置文件,加载第三方SDK,mob短信验证SDK和讯飞语音SDK。在values文件夹下,创建attrs.xml,编写代码如下:<?xmlversion="1.0"encoding="utf-8"?>
<resources>
<!--标题栏样式-->
<declare-styleablename="CustomToolBar">
<!--左按钮是否可见|背景-->
<attrname="left_btn_visible"format="boolean"/>
<attrname="left_btn_src"format="reference|color"/>
<!--左文本是否可见|文本内容-->
<attrname="left_tv_visible"format="boolean"/>
<attrname="left_tv_text"format="string"/>
<!--右边按钮是否可见|背景-->
<attrname="right_btn_visible"format="boolean"/>
<attrname="right_btn_src"format="reference|color"/>
<!--右文本是否可见|文本内容-->
<attrname="right_tv_visible"format="boolean"/>
<attrname="right_tv_text"format="string"/>
<!--标题是否可见|文本内容-->
<attrname="title_visible"format="boolean"/>
<attrname="title_text"format="string"/>
<!--背景-->
<attrname="barBackground"format="reference|color"/>
</declare-styleable>
</resources>增加颜色设置,在colors中加入代码:<!--标题栏颜色-->
<colorname="bg_toolbar">#32A082</color>修改主Activity的类文件dengluActivity.java,编写代码如下:packagecom.example.dhy203grapp01;
importandroid.content.DialogInterface;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.os.Handler;
importandroid.os.Message;
importandroid.support.v7.app.AlertDialog;
importandroid.support.v7.app.AppCompatActivity;
importandroid.text.TextUtils;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.Toast;
importcom.mob.MobSDK;
importjava.util.Timer;
importjava.util.TimerTask;
importjava.util.regex.Matcher;
importjava.util.regex.Pattern;
importcn.smssdk.EventHandler;
importcn.smssdk.SMSSDK;
publicclassdengluActivityextendsAppCompatActivityimplementsView.OnClickListener{
privateTimerTasktt;
privateTimertm;
privateEditTextet_phonenum;
privateButtonbtn_check;
privateEditTextet_checkecode;
privateButtonbtn_sure;
privateintTIME=60;//倒计时60s这里应该多设置些因为mob后台需要60s,我们前端会有差异的建议设置90,100或者120
publicStringcountry="86";//这是中国区号,如果需要其他国家列表,可以使用getSupportedCountries();获得国家区号
privateStringphone;
privateButtonbt_3;
privatestaticfinalintCODE_REPEAT=1;//重新发送
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.denglu_jm);
MobSDK.init(this,"263082c1bd6b4","3c219b47cfcfc063177979d9c48640bb");
SMSSDK.registerEventHandler(eh);//注册短信回调(记得销毁,避免泄露内存)
initView();
}
Handlerhd=newHandler(){
@Override
publicvoidhandleMessage(Messagemsg){
if(msg.what==CODE_REPEAT){
btn_check.setEnabled(true);
btn_sure.setEnabled(true);
tm.cancel();//取消任务
tt.cancel();//取消任务
TIME=60;//时间重置
btn_check.setText("重新发送验证码");
}else{
btn_check.setText(TIME+"重新发送验证码");
}
}
};
//回调
EventHandlereh=newEventHandler(){
@Override
publicvoidafterEvent(intevent,intresult,Objectdata){
if(result==SMSSDK.RESULT_COMPLETE){
if(event==SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE){
toast("验证成功");
}elseif(event==SMSSDK.EVENT_GET_VERIFICATION_CODE){//获取验证码成功
toast("获取验证码成功");
}elseif(event==SMSSDK.EVENT_GET_SUPPORTED_COUNTRIES){//如果你调用了获取国家区号类表会在这里回调
//返回支持发送验证码的国家列表
}
}
else{
//错误码请参照/android-api-错误码参考/
((Throwable)data).printStackTrace();
Stringstr=data.toString();
toast(str);
}
}
};
//吐司的一个小方法
privatevoidtoast(finalStringstr){
runOnUiThread(newRunnable(){
@Override
publicvoidrun(){
Toast.makeText(dengluActivity.this,str,Toast.LENGTH_SHORT).show();
}
});
}
privatevoidinitView(){
et_phonenum=(EditText)findViewById(R.id.et_phonenum);
btn_check=(Button)findViewById(R.id.btn_check);
et_checkecode=(EditText)findViewById(R.id.et_checkecode);
btn_sure=(Button)findViewById(R.id.btn_sure);
btn_check.setOnClickListener(this);
btn_sure.setOnClickListener(this);
bt_3=(Button)findViewById(R.id.btn_dl);
bt_3.setOnClickListener(this);
}
@Override
publicvoidonClick(Viewv){
switch(v.getId()){
caseR.id.btn_check:
phone=et_phonenum.getText().toString().trim().replaceAll("/s","");
if(!TextUtils.isEmpty(phone)){
//定义需要匹配的正则表达式的规则
StringREGEX_MOBILE_SIMPLE="[1][358]\\d{9}";
//把正则表达式的规则编译成模板
Patternpattern=Ppile(REGEX_MOBILE_SIMPLE);
//把需要匹配的字符给模板匹配,获得匹配器
Matchermatcher=pattern.matcher(phone);
//通过匹配器查找是否有该字符,不可重复调用重复调用matcher.find()
if(matcher.find()){//匹配手机号是否存在
alterWarning();
}else{
toast("手机号格式错误");
}
}else{
toast("请先输入手机号");
}
break;
caseR.id.btn_sure:
//获得用户输入的验证码
Stringcode=et_checkecode.getText().toString().replaceAll("/s","");
if(!TextUtils.isEmpty(code)){//判断验证码是否为空
//验证
SMSSDK.submitVerificationCode(country,phone,code);
}else{//如果用户输入的内容为空,提醒用户
toast("请输入验证码后再提交");
}
break;
}
bt_3.setOnClickListener(newView.OnClickListener(){
@Override
publicvoidonClick(Viewv){
//在按钮响应函数中添加如下两句话就ok了
Intentintent=newIntent(dengluActivity.this,MainActivity.class);
startActivity(intent);
}
});
}
//弹窗确认下发
privatevoidalterWarning(){
//构造器
AlertDialog.Builderbuilder=newAlertDialog.Builder(this);
builder.setTitle("提示");//设置标题
builder.setMessage("我们将要发送到"+phone+"验证");//设置内容
builder.setIcon(R.drawable.ic_ts);//设置图标,图片id即可
builder.setPositiveButton("确定",newDialogInterface.OnClickListener(){
//设置确定按钮
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){
dialog.dismiss();//关闭dialog
//通过sdk发送短信验证(请求获取短信验证码,在监听(eh)中返回)
SMSSDK.getVerificationCode(country,phone);
//做倒计时操作
Toast.makeText(dengluActivity.this,"已发送"+which,Toast.LENGTH_SHORT).show();
btn_check.setEnabled(false);
btn_sure.setEnabled(true);
tm=newTimer();
tt=newTimerTask(){
@Override
publicvoidrun(){
hd.sendEmptyMessage(TIME--);
}
};
tm.schedule(tt,0,1000);
}
});
builder.setNegativeButton("取消",newDialogInterface.OnClickListener(){//设置取消按钮
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){
dialog.dismiss();
Toast.makeText(dengluActivity.this,"已取消"+which,Toast.LENGTH_SHORT).show();
}
});
//参数都设置完成了,创建并显示出来
builder.create().show();
}
//销毁短信注册
@Override
protectedvoidonDestroy(){
super.onDestroy();
//注销回调接口registerEventHandler必须和unregisterEventHandler配套使用,否则可能造成内存泄漏。
SMSSDK.unregisterEventHandler(eh);
}
}修改MainActivity.java文件,代码如下:<packagecom.example.dhy203grapp01;
importandroid.content.Context;
importandroid.content.SharedPreferences;
importandroid.os.Environment;
importandroid.support.v7.app.AppCompatActivity;
importandroid.os.Bundle;
importandroid.util.Log;
importandroid.view.View;
importandroid.widget.TextView;
importandroid.widget.Toast;
importcom.iflytek.cloud.ErrorCode;
importcom.iflytek.cloud.InitListener;
importcom.iflytek.cloud.RecognizerListener;
importcom.iflytek.cloud.RecognizerResult;
importcom.iflytek.cloud.SpeechConstant;
importcom.iflytek.cloud.SpeechError;
importcom.iflytek.cloud.SpeechRecognizer;
importcom.iflytek.cloud.SpeechUtility;
importcom.iflytek.cloud.ui.RecognizerDialog;
importcom.iflytek.cloud.ui.RecognizerDialogListener;
importorg.json.JSONException;
importorg.json.JSONObject;
importjava.util.HashMap;
importjava.util.LinkedHashMap;
publicclassMainActivityextendsAppCompatActivity{
//显示听写结果
privateTextViewtextView;
//语音听写对象
privateSpeechRecognizerspeechRecognizer;
//语音听写UI
privateRecognizerDialogrecognizerDialog;
//是否显示听写UI
privatebooleanisShowDialog=true;
//缓存
privateSharedPreferencessharedPreferences;
//用hashmap存储听写结果
privateHashMap<String,String>hashMap=newLinkedHashMap<String,String>();
//引擎类型(云端或本地)
privateStringmEngineType=null;
//函数返回值
privateintret=0;
privateToasttoast;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
initDate();
}
privatevoidinitDate(){
//初始化sdk将自己申请的appid放到下面
//此句代码应该放在application中的,这里为了方便就直接放代码中了
SpeechUtility.createUtility(this,"appid=5b1fd9ac");
speechRecognizer=SpeechRecognizer.createRecognizer(this,initListener);
recognizerDialog=newRecognizerDialog(this,initListener);
sharedPreferences=getSharedPreferences(this.getPackageName(),Context.MODE_PRIVATE);
toast=Toast.makeText(this,"",Toast.LENGTH_SHORT);
//这里我直接将引擎类型设置为云端,因为本地需要下载讯飞语记,这里为了方便直接使用云端
//有需要的朋友可以加个单选框让用户选择云端或本地
mEngineType=SpeechConstant.TYPE_CLOUD;
}
privatevoidinitView(){
textView=(TextView)findViewById(R.id.tv);
}
//开始听写
publicvoidstart(Viewview){
textView.setText("");
hashMap.clear();
setParams();
if(isShowDialog){
recognizerDialog.setListener(dialogListener);
recognizerDialog.show();
}else{
ret=speechRecognizer.startListening(recognizerListener);
if(ret!=ErrorCode.SUCCESS){
Log.e("tag","听写失败,错误码"+ret);
}
}
}
//结束听写
publicvoidstop(Viewview){
Toast.makeText(this,"停止听写",Toast.LENGTH_SHORT).show();
if(isShowDialog){
recognizerDialog.dismiss();
}else{
speechRecognizer.stopListening();
}
}
//初始化监听器
privateInitListenerinitListener=newInitListener(){
@Override
publicvoidonInit(inti){
if(i!=ErrorCode.SUCCESS){
Log.e("tag","初始化失败,错误码"+i);
}
}
};
//无UI监听器
privateRecognizerListenerrecognizerListener=newRecognizerListener(){
@Override
publicvoidonVolumeChanged(finalinti,byte[]bytes){
Log.e("tag","返回数据大小"+bytes.length);
runOnUiThread(newRunnable(){
@Override
publicvoidrun(){
toast.setText("当前音量"+i);
}
});
}
@Override
publicvoidonBeginOfSpeech(){
Log.e("tag","开始说话");
}
@Override
publicvoidonEndOfSpeech(){
Log.e("tag","结束说话");
}
@Override
publicvoidonResult(RecognizerResultrecognizerResult,booleanb){
if(recognizerResult!=null){
Log.e("tag","听写结果:"+recognizerResult.getResultString());
printResult(recognizerResult);
}
}
@Override
publicvoidonError(SpeechErrorspeechError){
Log.e("tag","错误信息"+speechError.getPlainDescription(true));
}
@Override
publicvoidonEvent(inti,inti1,inti2,Bundlebundle){
//以下代码用于获取与云端的会话id,当业务出错时将会话id提供给技术支持人员,可用于查询会话日志,定位出错原因
//若使用本地能力,会话id为null
//if(SpeechEvent.EVENT_SESSION_ID==eventType){
//Stringsid=obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);
//Log.d(TAG,"sessionid="+sid);
//}
}
};
//有UI监听器
privateRecognizerDialogListenerdialogListener=newRecognizerDialogListener(){
@Override
publicvoidonResult(RecognizerResultrecognizerResult,booleanb){
if(recognizerResult!=null){
Log.e("tag","听写结果:"+recognizerResult.getResultString());
printResult(recognizerResult);
}
}
@Override
publicvoidonError(SpeechErrorspeechError){
Log.e("tag",speechError.getPlainDescription(true));
}
};
//输出结果,将返回的json字段解析并在textVie中显示
privatevoidprintResult(RecognizerResultresults){
Stringtext=com.iflytek.speech.util.JsonParser.parseIatResult(results.getResultString());
Stringsn=null;
//读取json结果中的sn字段
try{
JSONObjectresultJson=newJSONObject(results.getResultString());
sn=resultJson.optString("sn");
}catch(JSONExceptione){
e.printStackTrace();
}
hashMap.put(sn,text);
StringBufferresultBuffer=newStringBuffer();
for(Stringkey:hashMap.keySet()){
resultBuffer.append(hashMap.get(key));
}
textView.setText(resultBuffer.toString());
}
privatevoidsetParams(){
//清空参数
speechRecognizer.setParameter(SpeechConstant.PARAMS,null);
//设置引擎
speechRecognizer.setParameter(SpeechConstant.ENGINE_TYPE,mEngineType);
//设置返回数据类型
speechRecognizer.setParameter(SpeechConstant.RESULT_TYPE,"json");
//设置中文普通话
speechRecognizer.setParameter(SpeechConstant.LANGUAGE,"zh_cn");
speechRecognizer.setParameter(SpeechConstant.ACCENT,"mandarin");
//设置语音前端点:静音超时时间,即用户多长时间不说话则当做超时处理
speechRecognizer.setParameter(SpeechConstant.VAD_BOS,
sharedPreferences.getString("iat_vadbos_preference","4000"));
//设置语音后端点:后端点静音检测时间,即用户停止说话多长时间内即认为不再输入,自动停止录音
speechRecognizer.setParameter(SpeechConstant.VAD_EOS,
sharedPreferences.getString("iat_vadeos_preference","1000"));
//设置标点符号,设置为"0"返回结果无标点,设置为"1"返回结果有标点
speechRecognizer.setParameter(SpeechConstant.ASR_PTT,
sharedPreferences.getString("iat_punc_preference","0"));
//设置音频保存路径,保存音频格式支持pcm、wav,设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
//注:AUDIO_FORMAT参数语记需要更新版本才能生效
speechRecognizer.setParameter(SpeechConstant.AUDIO_FORMAT,"wav");
speechRecognizer.setParameter(SpeechConstant.ASR_AUDIO_PATH,
Environment.getExternalStor
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 上海立达学院《病理学与病理生理学》2025-2026学年期末试卷
- 忻州职业技术学院《口腔颌面影像诊断学》2025-2026学年期末试卷
- 沈阳理工大学《理论新闻传播学导论》2025-2026学年期末试卷
- 苏州科技大学天平学院《画法几何》2025-2026学年期末试卷
- 山西医科大学《汉语文学》2025-2026学年期末试卷
- 上海东海职业技术学院《初级经济学》2025-2026学年期末试卷
- 山西工学院《临床分子生物学检验技术》2025-2026学年期末试卷
- 苏州科技大学《劳动经济学》2025-2026学年期末试卷
- 沈阳音乐学院《口腔组织病理学》2025-2026学年期末试卷
- 上海东海职业技术学院《中国税制》2025-2026学年期末试卷
- 波形梁护栏监理实施细则
- 2026年张家港市事业单位公开招聘工作人员90人笔试参考题库及答案解析
- 2026年及未来5年市场数据中国工业水处理药剂行业发展运行现状及发展趋势预测报告
- 《CPA长期股权投资》课件
- 经典常谈-《说文解字》
- 电动单梁起重机(双速)设计计算书
- GA/T 686-2018信息安全技术虚拟专用网产品安全技术要求
- FZ/T 93047-2011针刺机
- 石墨制品生产新工艺新技术概述课件
- 河南科技版八年级下册劳动与技术教案
- 1-4月国药控股运营分析0514下发【课件】
评论
0/150
提交评论