我需要将音频数据作为“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中。
我是否做错了什么?还是有更好的方法?
附加信息:波形文件是16位,44100Hz,单声道。