赞
踩
讯飞语音开发集成地址http://www.xfyun.cn/ 解压后的doc文件夹下的msc develop 文件中有详细集成步骤
AppId:
1.先要注册开发者账户, 添加我的应用 , 下载sdk
2.下载后将sdk解压, 把案例导入工程中运行看看效果
3.将libs下的两个jar包添加到libs目录下, 将同路径下的其它 .so文件(与c进行交互)复制到main路径下新建的 jniLibs(L要大写)目录下(别忘了jar包要add) , 将assert目录拷贝到main目录下
注意 : 这些都是自己创建的应用生成的, 在申请appid时就与自己的应用绑定了, 拷贝别人的是没有用的
4.添加权限
5.创建类 , 以下是代码: initSpeech()方法下的APPID需要改成上面介绍中自己应用生成的appId
package atguigu.com.speechdemo2;
import android.app.Activity ;
import android.os.Bundle ;
import android.util.Log ;
import android.view.View ;
import android.widget.Button ;
import android.widget.EditText ;
import android.widget.Toast ;
import com.iflytek.cloud.ErrorCode ;
import com.iflytek.cloud.InitListener ;
import com.iflytek.cloud.RecognizerListener ;
import com.iflytek.cloud.RecognizerResult ;
import com.iflytek.cloud.SpeechConstant ;
import com.iflytek.cloud.SpeechError ;
import com.iflytek.cloud.SpeechRecognizer ;
import com.iflytek.cloud.SpeechSynthesizer ;
import com.iflytek.cloud.SpeechUtility ;
import com.iflytek.cloud.SynthesizerListener ;
import com.iflytek.cloud.ui.RecognizerDialog ;
import com.iflytek.cloud.ui.RecognizerDialogListener ;
import org.json.JSONException ;
import org.json.JSONObject ;
import java.util.HashMap ;
import java.util.LinkedHashMap ;
public class MainActivity extends Activity implements View.OnClickListener {
private static final String TAG = MainActivity.class .getSimpleName();
private EditText et_input;
private Button btn_startspeech, btn_startspeektext ;
// 用HashMap存储听写结果
private HashMap<String, String> mIatResults = new LinkedHashMap<String , String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState) ;
initView() ;
initSpeech() ;
}
private void initView() {
setContentView(R.layout.activity_main) ;
et_input = (EditText) findViewById(R.id.et_input );
btn_startspeech = (Button) findViewById(R.id.btn_startspeech );
btn_startspeektext = (Button) findViewById(R.id.btn_startspeektext );
btn_startspeech .setOnClickListener(this) ;
btn_startspeektext .setOnClickListener(this) ;
}
private void initSpeech() {
// 将“12345678”替换成您申请的 APPID,申请地址: http://www.xfyun.cn
// 请勿在 “ =”与 appid 之间添加任务空字符或者转义符
SpeechUtility. createUtility( this, SpeechConstant. APPID + "=56ffe0ae" );
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_startspeech: //语音识别(把声音转文字)
startSpeechDialog();
break;
case R.id. btn_startspeektext:// 语音合成(把文字转声音)
speekText();
break;
}
}
private void speekText() {
//1. 创建 SpeechSynthesizer 对象 , 第二个参数: 本地合成时传 InitListener
SpeechSynthesizer mTts = SpeechSynthesizer.createSynthesizer( this,
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。