本文整理汇总了Java中com.iflytek.cloud.SpeechRecognizer类的典型用法代码示例。如果您正苦于以下问题:Java SpeechRecognizer类的具体用法?Java SpeechRecognizer怎么用?Java SpeechRecognizer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SpeechRecognizer类属于com.iflytek.cloud包,在下文中一共展示了SpeechRecognizer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: IflyRecognizer
import com.iflytek.cloud.SpeechRecognizer; //导入依赖的package包/类
private IflyRecognizer(Context context, SystemVoiceMediator mediator) {
super.mContext = context;
super.mediator = mediator;
mPlayer = SpeechPlayer.createInstance(mContext, mediator);
mRecorder = new PcmRecorder(context);
mRecorder.setOnRecordListener(recordListener);
Log.i(TAG, "before SpeechRecognizer.createRecognizer");
recognizer = SpeechRecognizer.createRecognizer(context, rInitListener);
Log.i(TAG, "after SpeechRecognizer.createRecognizer");
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
if (!initParam)
setDefaultRecognizerParam(false);
}
}, 3000);
}
示例2: onCreate
import com.iflytek.cloud.SpeechRecognizer; //导入依赖的package包/类
@SuppressLint("ShowToast")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.iatdemo);
initLayout();
// 初始化识别无UI识别对象
// 使用SpeechRecognizer对象,可根据回调消息自定义界面;
mIat = SpeechRecognizer.createRecognizer(IatDemo.this, mInitListener);
// 初始化听写Dialog,如果只使用有UI听写功能,无需创建SpeechRecognizer
// 使用UI听写功能,请根据sdk文件目录下的notice.txt,放置布局文件和图片资源
mIatDialog = new RecognizerDialog(IatDemo.this, mInitListener);
mSharedPreferences = getSharedPreferences(IatSettings.PREFER_NAME,
Activity.MODE_PRIVATE);
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
mResultText = ((EditText) findViewById(R.id.iat_text));
}
示例3: startListening
import com.iflytek.cloud.SpeechRecognizer; //导入依赖的package包/类
private void startListening(JSONObject options, CallbackContext callbackContext) {
Log.v(TAG,"startListening " + String.valueOf(options));
SpeechRecognizer rec = getRecognizer();
rec.setParameter(SpeechConstant.DOMAIN, "iat");
rec.setParameter(SpeechConstant.LANGUAGE, "zh_cn");
rec.setParameter(SpeechConstant.ACCENT, "mandarin");
rec.setParameter(SpeechConstant.ASR_AUDIO_PATH, ASR_FILE);
if (options != null) {
Iterator it = options.keys();
while (it.hasNext()) {
String key = (String) it.next();
String value = options.optString(key);
rec.setParameter(key, value);
}
}
rec.startListening(this);
}
示例4: doVoiceInput
import com.iflytek.cloud.SpeechRecognizer; //导入依赖的package包/类
@Permission(PermissionUtils.CODE_AUDIO)
private void doVoiceInput() {
boolean has = PermissionUtils.hasPermission4Audio(mContext);
if (has) {
mIsVoiceOpen = true;
if (mIat == null) {
// 使用SpeechRecognizer对象,可根据回调消息自定义界面;
mIat = SpeechRecognizer.createRecognizer(mContext, mInitListener);
}
//todo 如果是title怎么办
mContentString = mEditTextView.getNoteContent();
setVoiceParam();
ret = mIat.startListening(mRecognizerListener);
if (ret != ErrorCode.SUCCESS) {
YLog.e(TAG, "听写失败,错误码:" + ret);
}
} else {
PermissionUtils.requestPermissions(mActivity, mContext.getString(R.string.permission_audio),
PermissionUtils.PERMISSION_AUDIO, PermissionUtils.CODE_AUDIO, null);
}
}
示例5: initData
import com.iflytek.cloud.SpeechRecognizer; //导入依赖的package包/类
private void initData(){
//注册广播
IntentFilter intentFilter=new IntentFilter();
intentFilter.addAction("com.zhengsonglan.cold.broadcastreceiver.MyReceiver");
registerReceiver(myReceiver, intentFilter);
//初始化语音听写
recognizer=SpeechRecognizer.createRecognizer(this,initListener);
//初始化UI
dialog=new RecognizerDialog(this,initListener);
//初始化聊天数据
data=new ArrayList<ChatMsgEntity>();
ChatMsgEntity chatMsgEntity=new ChatMsgEntity(you_name,"{\"code\":100000,\"text\":\"你好,啾啾为你服务\"}", ChatMsgEntity.Type.you,new Date());
data.add(chatMsgEntity);
chatAdapter=new ChatAdapter(this,data);
lv_chat.setAdapter(chatAdapter);
}
示例6: startListening
import com.iflytek.cloud.SpeechRecognizer; //导入依赖的package包/类
private void startListening(JSONObject options, CallbackContext callbackContext) {
SpeechRecognizer rec = getRecognizer();
rec.setParameter(SpeechConstant.DOMAIN, "iat");
rec.setParameter(SpeechConstant.LANGUAGE, "zh_cn");
rec.setParameter(SpeechConstant.ACCENT, "mandarin");
rec.setParameter(SpeechConstant.ASR_AUDIO_PATH, ASR_FILE);
if (options != null) {
Iterator it = options.keys();
while (it.hasNext()) {
String key = (String) it.next();
String value = options.optString(key);
rec.setParameter(key, value);
}
}
rec.startListening(this);
}
示例7: initComponent
import com.iflytek.cloud.SpeechRecognizer; //导入依赖的package包/类
private void initComponent(Context context) {
if (mRecorder == null) {
mRecorder = new PcmRecorder(context);
mRecorder.setOnRecordListener(recordListener);
}
if (recognizer == null) {
mPlayer = new SpeechPlayer();
recognizer = SpeechRecognizer.createRecognizer(context, rInitListener);
if (!"-1".equals(recognizer.getParameter(SpeechConstant.AUDIO_SOURCE))) {
setRecognizeParams();
}
}
}
示例8: reset
import com.iflytek.cloud.SpeechRecognizer; //导入依赖的package包/类
public void reset() {
try {
Log.e(TAG, "stopRecognize>>destroy>>reset");
recognizer.destroy();
recognizer.stopListening();
recognizer = SpeechRecognizer.createRecognizer(mContext, rInitListener);
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例9: startRecognize
import com.iflytek.cloud.SpeechRecognizer; //导入依赖的package包/类
public void startRecognize() {
if (null == mIat) {
mIat = SpeechRecognizer.createRecognizer(getContext(), mInitListener);
}
if (mIat.isListening()) {
return;
}
setParam();
int ret = mIat.startListening(this);
if (ret != ErrorCode.SUCCESS) {
RLog.d(TAG, "startRecognize ret error " + ret);
}
}
示例10: initXFVoice
import com.iflytek.cloud.SpeechRecognizer; //导入依赖的package包/类
private void initXFVoice() {
SpeechUtility.createUtility(getActivity(), SpeechConstant.APPID + BuildConfig.XF_APP_ID);
mIat = SpeechRecognizer.createRecognizer(getActivity(), this);
mIat.setParameter(SpeechConstant.DOMAIN, "iat");
mIat.setParameter(SpeechConstant.LANGUAGE, "zh_cn");
mIat.setParameter(SpeechConstant.ACCENT, "mandarin ");
mIat.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);
mIat.setParameter(SpeechConstant.ASR_PTT, "0");
}
示例11: startRecognize
import com.iflytek.cloud.SpeechRecognizer; //导入依赖的package包/类
private void startRecognize() {
if (null == mIat) {
mIat = SpeechRecognizer.createRecognizer(getContext(), mInitListener);
}
if (mIat.isListening()) {
return;
}
setParam();
int ret = mIat.startListening(this);
if (ret != ErrorCode.SUCCESS) {
Log.d(TAG, "startRecognize ret error " + ret);
}
}
示例12: onCreate
import com.iflytek.cloud.SpeechRecognizer; //导入依赖的package包/类
@SuppressLint("ShowToast")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.isrdemo);
initLayout();
// 初始化识别对象
mAsr = SpeechRecognizer.createRecognizer(AsrDemo.this, mInitListener);
mCloudGrammar = FucUtil.readFile(this,"grammar_sample.abnf","utf-8");
mSharedPreferences = getSharedPreferences(getPackageName(), MODE_PRIVATE);
mToast = Toast.makeText(this,"",Toast.LENGTH_SHORT);
}
示例13: initUI
import com.iflytek.cloud.SpeechRecognizer; //导入依赖的package包/类
private void initUI() {
mDanmakuView = (DanmakuView) findViewById(R.id.danmakuView);//弹幕
sendDanmu = (ImageView) findViewById(R.id.imageView5);//发送弹幕
mIat = SpeechRecognizer.createRecognizer(MainActivity.this, mInitListener);
// 初始化听写Dialog,如果只使用有UI听写功能,无需创建SpeechRecognizer
// 使用UI听写功能,请根据sdk文件目录下的notice.txt,放置布局文件和图片资源
mIatDialog = new RecognizerDialog(MainActivity.this, mInitListener);
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
sendDanmu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mIatResults.clear();
danmucontent = "";
// 设置参数
setParam();
boolean isShowDialog = true;
if (isShowDialog) {
// 显示听写对话框
mIatDialog.setListener(mRecognizerDialogListener);
mIatDialog.show();
showTip(getString(R.string.text_begin));
} else {
// 不显示听写对话框
ret = mIat.startListening(mRecognizerListener);
if (ret != ErrorCode.SUCCESS) {
showTip("听写失败,错误码:" + ret);
} else {
showTip(getString(R.string.text_begin));
}
}
}
});
}
示例14: onCreateView
import com.iflytek.cloud.SpeechRecognizer; //导入依赖的package包/类
/**
* Create this Fragments View.
*/
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_voice_view, container, false);
SpeechUtility.createUtility(getActivity(), SpeechConstant.APPID+"=581c7563");
listener = new Listener("android_remote_control", std_msgs.String._TYPE, new MessageListener<std_msgs.String>() {
@Override
public void onNewMessage(std_msgs.String message) {
String str = message.getData();
mTts.startSpeaking(str, mTtsListener);
}
});
talker = new Talker("pc_remote_control", std_msgs.String._TYPE);
virtualVoiceView = (ImageButton) view.findViewById(R.id.voice_button);
mToast = Toast.makeText(getActivity(),null,Toast.LENGTH_SHORT);
// 初始化对象
mIat = SpeechRecognizer.createRecognizer(getActivity(), mInitListener);
mTts = SpeechSynthesizer.createSynthesizer(getActivity(), mInitListener);
virtualVoiceView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(mTts.isSpeaking())
mTts.stopSpeaking();
iat();
}
});
iat_setParam();
tts_setParam();
return view;
}
示例15: onCreate
import com.iflytek.cloud.SpeechRecognizer; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
findViews();
// 初始化识别无UI识别对象
// 使用SpeechRecognizer对象,可根据回调消息自定义界面;
mIat = SpeechRecognizer.createRecognizer(this, mInitListener);
mIatDialog = new RecognizerDialog(TestActivity.this, mInitListener);
mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
}