我需要将我的1个音频样本切换到另一个没有2秒和1秒钟的数据的数据。目前我正在尝试使用代码,但不能正确切割。
标题是44个字节,2秒是176400和1秒88200
private void copyWaveFileForAlgo(String inFilename, String outFilename) {
Log.v("copyWaveFile ", "---------copyWaveFile---------");
FileInputStream in = null;
FileOutputStream out = null;
long totalAudioLen = 0;
long totalDataLen = totalAudioLen + 36;
long longSampleRate = RECORDER_SAMPLERATE;
int channels = 1;
long byteRate = RECORDER_BPP * RECORDER_SAMPLERATE * channels / 8;
byte[] tmpdata = new byte[88200];
try {
in = new FileInputStream(inFilename);
out = new FileOutputStream(outFilename);
totalAudioLen = in.getChannel().size();
totalDataLen = totalAudioLen + 36;
int lenth = 0;
Log.v("data ", "----totalDataLen-----"+totalDataLen+"---------"+tmpdata.length);
long dataToCopy = totalDataLen - 88200;
long dataLenthTransfered = 0;
WriteWaveFileHeader(out, totalAudioLen, totalDataLen, longSampleRate, channels, byteRate);
long skippedB = 0;
lenth = in.read(tmpdata);
while (lenth != -1)
{
if (skippedB <176400)
{
skippedB+= in.skip(88200);
Log.v("skippedB ", "----skippedB-----"+skippedB+"---------");
}else
{
if(dataLenthTransfered < dataToCopy)
{Log.v("dataLenth ", "----elseee-----"+dataLenthTransfered+"-----dataToCopy----"+dataToCopy);
out.write(tmpdata);
}
else
{
Log.v("dataLenthTransfered ", "----dataLenthTransfered-----"+dataLenthTransfered+"----dataToCopy-----"+dataToCopy);
}
}
dataLenthTransfered+=lenth;
lenth = in.read(tmpdata);
}
in.close();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}`
感谢任何帮助。 谢谢, Vyoma