android 合并录音文件
16lz
2021-01-26
/**
* @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();
}
* @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);
更多相关文章
- 将获取的html源代码格式化输出
- Android(安卓)Audio Record
- android 原生GET和POST提交数据
- Android(安卓)Media Recorder录音播放源代码
- [RK3399][Android7.1] 调试笔记 --- JNI层输出带TAG的Log
- 电话录音录制双方的声音
- Android-NDK开发之基础--Android(安卓)JNI实例代码(一)-- 在JNI
- Android(安卓)中Odex文件生成与合并
- Android(安卓)Log介绍