关于java:针对特定.WAV文件的程序返回”无法从输入文件获取音频输入流”

Program returning “could not get audio input stream from input file” for specific .WAV file

我有一个涉及.wav文件分析和输出的程序。它可以很好地处理CD或互联网上的曲目,但是我使用Matlab进行了分析,生成了一系列纯正弦波音调,这给了我标题中所示的错误。 Matlab文件在iTunes中可以正常运行,因此我不确定为什么我的程序遇到问题。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public static void signalToFile(File f) throws IOException, UnsupportedAudioFileException
{
    AudioInputStream inputStream = AudioSystem.getAudioInputStream(f);
    int numBytes = inputStream.available();
    byte[] buffer = new byte[numBytes];
    inputStream.read(buffer, 0, numBytes);

    String newFile = f.getName().replace(".wav",".txt");
    System.out.println("Beginning file write:" + newFile +" (soundUtilities)");
    BufferedWriter fileOut = new BufferedWriter(new FileWriter(new File("src/examples/Media/" + newFile)));
    System.out.println("Ending file write:" + newFile +" (soundUtilities)");
    System.out.println(buffer.length);
    ByteBuffer myBB = ByteBuffer.wrap(buffer);
    myBB.order(ByteOrder.LITTLE_ENDIAN);
    while(myBB.remaining() > 1)
    {
        short current = myBB.getShort();
        fileOut.write(String.valueOf(current));
        fileOut.newLine();
    }

    fileOut.flush();
    fileOut.close();
    inputStream.close();
}

此方法的第一行是导致错误的原因。此方法将文件的信号信息包含到txt文件中。任何帮助将不胜感激。

下面是我用来创建wav文件的matlab代码的一小部分:

1
2
3
4
5
6
7
x13 = sin(2*pi*220*t1); % A3 long sample
x13envelope = [1:-1/length(x13):1/length(x13)];
x13full = x13.*x13envelope;

totalSound = [x1full x2full x3full x4full x5full x6full x7full x8full x9full x10full x11full x12full x13full]; % combines the notes

 wavwrite(totalSound, fs, 32, 'TestTune');

" totalSound"数组中的每个条目都代表一个音符


WAV文件具有标题。您似乎没有创建该标头。您似乎要创建的是原始PCM文件。


我很喜欢这个问题" JBoss 4.2和JBoss 7的输出是不同的
JBoss 4.2:
支持WAVE = true

JBoss 7:
支持WAVE = false"
也请检查此https://community.jboss.org/message/729654