/** 初始化百度的配置 */ private void initBaiduConfiguration(Context con) { if (recognitionClient == null) { recognitionClient = VoiceRecognitionClient.getInstance(con); recognitionClient.setTokenApis( BaiDuVoiceConfiguration.API_KEY, BaiDuVoiceConfiguration.SECRET_KEY); } }
public void startRecog(Context con) { /** stop first, because last action maybe not finished */ if (null == recognitionClient) { initBaiduConfiguration(con); } recognitionClient.stopVoiceRecognition(); /** 语音的配置 */ VoiceRecognitionConfig config = BaiDuVoiceConfiguration.getVoiceRecognitionConfig(); /** 下面发起识别 */ if (null == recogListener) { recogListener = new BaiDuVoiceChannelDialogRecogListener(con); } int code = recognitionClient.startVoiceRecognition(recogListener, config); if (code != VoiceRecognitionClient.START_WORK_RESULT_WORKING) { Toast.makeText(con, "网络连接出错,请重新尝试", Toast.LENGTH_LONG).show(); } }
public void speakFinish() { recognitionClient.speakFinish(); }