java语⾳识别源码_简单语⾳识别源码derqi.publicutil.voice;
import android.app.Activity;
t.Context;
t.SharedPreferences;
import android.os.Bundle;
TextUtils;
import android.widget.Button;
import android.widget.Toast;
import com.iflytek.cloud.speech.DataDownloader;
import com.iflytek.cloud.speech.DataUploader;
import com.iflytek.cloud.speech.RecognizerResult;
import com.iflytek.cloud.speech.SpeechConstant;
import com.iflytek.cloud.speech.SpeechError;
import com.iflytek.cloud.speech.SpeechListener;
import com.iflytek.cloud.speech.SpeechRecognizer;
import com.iflytek.cloud.speech.SpeechUser;
import com.iflytek.cloud.ui.RecognizerDialog;
import com.iflytek.cloud.ui.RecognizerDialogListener;
public class VoiceToWord extends Activity{
private Context context;
private Toast mToast;
//识别窗⼝
private RecognizerDialog iatDialog;
//识别对象
private SpeechRecognizer iatRecognizer;
//缓存,保存当前的引擎参数到下⼀次启动应⽤程序使⽤.
private SharedPreferences mSharedPreferences;
private RecognizerDialogListener recognizerDialogListener = null;
public VoiceToWord(Context context,String APP_ID) {
// TODO Auto-generated constructor stub
//⽤户登录
,
"appid=" + APP_ID, listener);
//初始化听写Dialog,如果只使⽤有UI听写功能,⽆需创建SpeechRecognizer
iatDialog =new RecognizerDialog(context);
mToast = Toast.makeText(context, "", Toast.LENGTH_LONG);
//初始化听写Dialog,如果只使⽤有UI听写功能,⽆需创建SpeechRecognizer
iatDialog =new RecognizerDialog(context);
//初始化缓存对象.
mSharedPreferences = PackageName(),MODE_PRIVATE);
}
public VoiceToWord(Context context,String APP_ID,RecognizerDialogListener recognizerDialogListener) {
, "appid=" + APP_ID, listener);
//初始化听写Dialog,如果只使⽤有UI听写功能,⽆需创建SpeechRecognizer
iatDialog =new RecognizerDialog(context);
mToast = Toast.makeText(context, "", Toast.LENGTH_LONG);
//初始化听写Dialog,如果只使⽤有UI听写功能,⽆需创建SpeechRecognizer
iatDialog =new RecognizerDialog(context);
//初始化缓存对象.
mSharedPreferences = PackageName(),MODE_PRIVATE); izerDialogListener = recognizerDialogListener;
}
public void GetWordFromVoice()
{
boolean isShowDialog = Boolean("iat_show",true);
if (isShowDialog) {
//显⽰语⾳听写Dialog.
showIatDialog();
} else {
if(null == iatRecognizer) {
ateRecognizer(this);
}
if(iatRecognizer.isListening()) {
iatRecognizer.stopListening();
//((Button) findViewById(android.R.id.button1)).setEnabled(false); } else {
}
}
}
private void showTip(String str)
{
if(!TextUtils.isEmpty(str))
{
mToast.setText(str);
mToast.show();
}
}
/**
* 显⽰听写对话框.
* @param
*/
public void showIatDialog()
{
if(null == iatDialog) {
//初始化听写Dialog
iatDialog =new RecognizerDialog(this);
}
//获取引擎参数
String engine = String(
"iat_engine",
"iat");
//清空Grammar_ID,防⽌识别后进⾏听写时Grammar_ID的⼲扰iatDialog.setParameter(SpeechConstant.CLOUD_GRAMMAR, null); //设置听写Dialog的引擎
iatDialog.setParameter(SpeechConstant.DOMAIN, engine);
//设置采样率参数,⽀持8K和16K
String rate = String(
"sf",
"sf");
if(rate.equals("rate8k"))
{
iatDialog.setParameter(SpeechConstant.SAMPLE_RATE, "8000"); }
else
{
iatDialog.setParameter(SpeechConstant.SAMPLE_RATE, "16000"); }
if(recognizerDialogListener == null)
{
getRecognizerDialogListener();
}
/
/显⽰听写对话框
iatDialog.setListener(recognizerDialogListener);
iatDialog.show();
}
private void getRecognizerDialogListener()
{
/**
* 识别回调
*/
recognizerDialogListener=new MyRecognizerDialogLister(context); }
/**
* ⽤户登录回调.
*/
private SpeechListener listener = new SpeechListener()
{
@Override
public void onData(byte[] arg0) {
}
@Override
public void onCompleted(SpeechError error) {
if(error != null) {
System.out.println("user login success");
}
}
@Override
public void onEvent(int arg0, Bundle arg1) {
java影视app源码}
};
}
更多源码 | 好库简介 | ⽹站地图 | 帮助中⼼ | 版权说明
Copyright© 2009-2012 OKBASE.NET All Rights Reserved 好库⽹ 版权所有
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论