我需要将音频数据作为“ 16位整数数组”传递给第三方系统(来自有限的文档).
到目前为止,这是我尝试过的(系统从生成的bytes.dat文件中读取它).
AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File("c:\all.wav"));
int numBytes = inputStream.available();
byte[] buffer = new byte[numBytes];
inputStream.read(buffer, 0, numBytes);
BufferedWriter fileOut = new BufferedWriter(new FileWriter(new File("c:\temp\bytes.dat")));
ByteBuffer bb = ByteBuffer.wrap(buffer);
while (bb.remaining() > 1) {
short current = bb.getShort();
fileOut.write(String.valueOf(current));
fileOut.newLine();
}
这似乎不起作用-第三方系统无法识别它,我也无法将文件作为原始音频导入到Audacity中.
有什么明显的地方我做错了吗,还是有更好的方法呢?
额外信息:波形文件为16bit,44100Hz,单声道.