问题
i want to split my audio file(.wav format) in frames of 32 milliseconds each sampling frequn-16khz,number of channels-1(mono),pcm signal, sample size=93638. I am using the following code for reading my wave file which give an array which is stored in data2 array.Can some one tell me how to proceed from this -:
import java.io.ByteArrayOutputStream;
import java.io.File;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
public class AudioFiles
{
public static void main(String[] args)
{
String file = "D:/p.wav";
int i;
AudioFiles afiles = new AudioFiles();
byte[] data2 = afiles.readWAVAudioFileData(file);
for(i=0;i<data2.length;i++)
{
System.out.format("\t"+data2[i]);
}
System.out.printf("\n%d",data2.length);
}
public byte[] readWAVAudioFileData(final String filePath)
{
byte[] data = null;
try {
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
final AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File(filePath));
AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, baout);
audioInputStream.close();
baout.close();
data = baout.toByteArray();
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
}
回答1:
At 16kHz sample rate you'll have 16 samples per millisecond. Therefore, each 32ms frame would be 32*16=512 mono samples. Multiply by the number of bytes-per-sample (typically 2 or 4) and that will be the number of bytes per frame.
来源:https://stackoverflow.com/questions/22389143/how-to-do-framing-for-a-given-wave-file-in-java