给定一个调用的InputStream,其中包含压缩格式的音频数据(如MP3或OGG),我希望创建一个包含输入数据的WAV转换的字节数组.不幸的是,如果您尝试这样做,JavaSound会向您发出以下错误:
java.io.IOException: stream length not specified@H_403_3@ @H_404_4@我设法通过将wav写入临时文件然后将其读回来使其工作,如下所示:AudioInputStream source = AudioSystem.getAudioInputStream(new BufferedInputStream(in,1024)); AudioInputStream pcm = AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED,source); AudioInputStream ulaw = AudioSystem.getAudioInputStream(AudioFormat.Encoding.ULAW,pcm); File tempFile = File.createTempFile("wav","tmp"); AudioSystem.write(ulaw,AudioFileFormat.Type.WAVE,tempFile); // The fileToByteArray() method reads the file // into a byte array; omitted for brevity byte[] bytes = fileToByteArray(tempFile); tempFile.delete(); return bytes;@H_403_3@ @H_404_4@这显然不太理想.有没有更好的办法?