gpt4 book ai didi

java - 合并音频文件

转载 作者:行者123 更新时间:2023-12-01 06:20:57 24 4
gpt4 key购买 nike

我录制了一些音频文件,并将它们存储在SD卡中。我需要将所有录制的文件合并到一个音频文件中。我使用了以下代码。我的问题是组合文件仅包含第一个录制的文件。任何建议...在 readAudioAsStream() 方法中我尝试合并文件。

public void readAudioAsStream() {
getFullAudioPath()

File f;
FileInputStream ins = null;

try
{
String comfile=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[(int)f.length()];
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) {
e1.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
public ArrayList<String> getFullAudioPath() {
ArrayList<String> fullPath=new ArrayList<String>();
fullPath.clear();

String path=filePath();
File f=new File(path);
if(f.isDirectory())
{
File[] files=f.listFiles();
for(int i=0;i<files.length;i++)
{
String fpath=path+File.separator+files[i].getName().toString().trim();
System.out.println("File Full Path======>>>"+fpath);
fullPath.add(fpath);
}
}
return fullPath;
}
public String filePath() {
String newFolderName="/MyAudio";
String extstoredir=Environment.getExternalStorageDirectory().toString();
String newPath=extstoredir+newFolderName;
return newPath;
}

public String getCombineFile() {
String newFolderName="/MyComAudio";
String extstoredir=Environment.getExternalStorageDirectory().toString();
String path=extstoredir+newFolderName;
File myNewPath=new File(path);
if(!myNewPath.exists()) {
myNewPath.mkdir();
}
String audname="ComAudio";
String ext=".3gp";
File audio=new File(myNewPath,audname+ext);

if(audio.exists()) {
audio.delete();
}
String audpath=path+"/"+audname+ext;
Log.d("Combined audio file",audpath);
return audpath;
}

最佳答案

仅通过将一个 .3gp 文件的内容写入另一个 .3gp 文件的末尾,无法合并两个 .3gp 文件。

关于java - 合并音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6137507/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com