/**
* @param audio files list
*/
public void getInputCollection(List list) {
long dateTaken = System.currentTimeMillis();
String strTempFile = Long.toString(dateTaken);
mRecordAudioFile = new File(mPath, strTempFile + ".amr");

FileOutputStream fileOutputStream = null;

if (!mRecordAudioFile.exists()) {
try {
mRecordAudioFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
fileOutputStream = new FileOutputStream(mRecordAudioFile);

} catch (IOException e) {
e.printStackTrace();
}

for (int i = 0; i < list.size(); i++) {
File tempfile = new File((String) list.get(i));
try {
FileInputStream fileInputStream = new FileInputStream(tempfile);
byte[] myByte = new byte[fileInputStream.available()];
// file length
int length = myByte.length;

// first audio file
if (i == 0) {
while (fileInputStream.read(myByte) != -1) {
fileOutputStream.write(myByte, 0, length);
}
}

// delete file head information
else {
while (fileInputStream.read(myByte) != -1) {

fileOutputStream.write(myByte, 6, length - 6);
}
}

fileOutputStream.flush();
fileInputStream.close();
} catch (Exception e) {
e.printStackTrace();
}

}
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}

}

合并之前设置MediaRecorder的输出格式和encoder一定要指定对,否则合并后的录音文件有问题

mMediaRecorder = new MediaRecorder();
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

更多相关文章

  1. 将获取的html源代码格式化输出
  2. Android(安卓)Audio Record
  3. android 原生GET和POST提交数据
  4. Android(安卓)Media Recorder录音播放源代码
  5. [RK3399][Android7.1] 调试笔记 --- JNI层输出带TAG的Log
  6. 电话录音录制双方的声音
  7. Android-NDK开发之基础--Android(安卓)JNI实例代码(一)-- 在JNI
  8. Android(安卓)中Odex文件生成与合并
  9. Android(安卓)Log介绍

随机推荐

  1. Mysql二进制日志binlog命令
  2. ansible条件判断和循环
  3. 2021-03-12:go中,如何确定有没有内存泄露,系
  4. 自学软件测试 - 功能测试篇
  5. 优秀的软件测试人员有哪些特征?
  6. 二进制安装Kubernetes高可用集群(上)
  7. httpd-2.4.46 (apache) 基于网络源码包安
  8. 苹果笔记本macBookAir2020 -M1密码--重置
  9. IDEA 2021最新永久激活码(免费激活至 209
  10. 抽象类与接口论述