void start(){
//在小米5的手机上直接向getExternalStorageDirectory写文件会出现文件管理器找不文件的情况,
这时候就要提前生成这个文件夹,防止存储wav文件失败。
mkdir(); String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/0/" + wavFileCount + ".wav"; mIat.setParameter(SpeechConstant.ASR_AUDIO_PATH, path); //开始识别,并设置监听器 mIat.startListening(mRecognizerListener); } private void mkdir() { try { String rootPath = Environment.getExternalStorageDirectory().getAbsolutePath(); File dirFile = new File(rootPath); if (!dirFile.exists()) { dirFile.mkdir(); } String dir0Path = rootPath + "/0/"; File dir = new File(dir0Path); if (!dir.exists()) { dir.mkdir(); } // String wavPath = rootPath + "/0/test.wav"; // File file = new File(wavPath); // if (!file.exists()) { // FileOutputStream fos = new FileOutputStream(wavPath); // fos.write("123".getBytes()); // fos.flush(); // fos.close(); // } } catch (Exception e) { e.printStackTrace(); } }