我已经使用AudioRecorder录制的音频。我需要记录的文件合并成一个文件。任何建议。
getAudioPath() - 的语音文件的路径。 getCombineFile()---将合并的文件的路径。我的问题是第一个文件一个人玩,而不是在该目录中的整个文件
公共无效readAudioAsStream()
{
getAudioPath();
文件F = NULL;
的FileInputStream插件= NULL;
ReadSDDatas RDS =新ReadSDDatas();
尝试
{
串COMFILE = rds.getCombineFile();
// FileOutputStream中FOS =新的FileOutputStream(COMFILE);
Log.d(合并文件,COMFILE);
档案文件=新的文件(COMFILE);
RandomAccessFile的英国皇家空军=新RandomAccessFile的(文件,RW);
Log.d(路径大小,Integer.toString(audFullPath.size()));
的for(int i = 0; I< audFullPath.size();我++)
{
串文件路径= audFullPath.get(ⅰ);
Log.d(文件路径,文件路径);
F =新的文件(audFullPath.get(一));
fileContent =新的字节[阅读]
插件=新的FileInputStream(audFullPath.get(一));
INT numofbytes = ins.read(fileContent);
的System.out.println(字节数范围===========>>>+ numofbytes);
raf.seek(file.length());
raf.write(fileContent);
}
}
赶上(FileNotFoundException异常E1)
{
// TODO自动生成的catch块
e1.printStackTrace();
}
赶上(IOException异常E){
// TODO自动生成的catch块
e.printStackTrace();
}
/ *字符串路径= audFullPath.get(VAL);
playAudio(路径); * /
playAudio();
/ *
的for(int i = 0; I< audFullPath.size();我++)
{
Log.d(fullpathsize,Integer.toString(audFullPath.size()));
playAudio(audFullPath.get(ⅰ));
} * /
}
解决方案
如果您使用的是 AudioRecord.read()
,我假设你有PCM数据在短期或字节数组。如果是这样的话,所有你需要做的是创建一个新的数组一样大,无论是原件,并在复制数据,一个接一个。事情是这样的:
短[] newData =新的短[dataOne.length + dataTwo.length]。
的for(int i = 0; I< dataOne.length;我++)
newData [I] = dataOne [I];
的for(int i = 0; I< dataTwo.length;我++)
newData [1 + dataOne.length] = dataTwo [I];
然后你有一个阵列的所有PCM数据,并且可以与该做些什么,你会的。
I have recorded audio using AudioRecorder. I need to merge the recorded files into a single file. Any suggestion.
getAudioPath() -- the path of the audiofiles. getCombineFile()--- the path of the combined file. My problem is the first file alone play, not the entire file in that directory
public void readAudioAsStream()
{
getAudioPath();
File f=null;
FileInputStream ins = null;
ReadSDDatas rds=new ReadSDDatas();
try
{
String comfile=rds.getCombineFile();
//FileOutputStream fos=new FileOutputStream(comfile);
Log.d("combined file",comfile);
File file=new File(comfile);
RandomAccessFile raf = new RandomAccessFile(file, "rw");
Log.d("path size",Integer.toString(audFullPath.size()));
for(int i=0;i<audFullPath.size();i++)
{
String filepath=audFullPath.get(i);
Log.d("Filepath",filepath);
f=new File(audFullPath.get(i));
fileContent = new byte[read];
ins=new FileInputStream(audFullPath.get(i));
int numofbytes=ins.read(fileContent);
System.out.println("Number Of Bytes Read===========>>>"+numofbytes);
raf.seek(file.length());
raf.write(fileContent);
}
}
catch (FileNotFoundException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*String path=audFullPath.get(val);
playAudio(path);*/
playAudio();
/*
for(int i=0;i<audFullPath.size();i++)
{
Log.d("fullpathsize",Integer.toString(audFullPath.size()));
playAudio(audFullPath.get(i));
}*/
}
解决方案
If you're using AudioRecord.read()
, I'm assuming you have the PCM data in a short or byte array. If that's the case, all you need to do is create a new array as large as both of the originals, and copy the data over, one after the other. Something like this:
short[] newData = new short[dataOne.length + dataTwo.length];
for(int i=0;i<dataOne.length;i++)
newData[i] = dataOne[i];
for(int i=0;i<dataTwo.length;i++)
newData[i+dataOne.length] = dataTwo[i];
Then you have one array with all the PCM data, and you can do with that what you will.