程序返回“无法从输入文件获取音频输入流”对于特定的 .WAV 文件
我有一个程序涉及.wav 文件的分析和输出。它与 CD 或互联网上的曲目完美配合,但我使用 matlab 生成了一系列纯正弦波音调进行分析,它给了我标题中所示的错误。 matlab 文件在 iTunes 中运行良好,所以我不确定为什么我的程序出现问题。
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 代码:
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”数组中的每个条目代表一个音符
I have a program that involves the analysis and output of .wav files. It works perfectly fine with tracks from cds or the internet but I have generated a sequence of pure sine wave tones using matlab to analyse and it is giving me the error shown in the title. The matlab files run fine in iTunes so I'm not sure why my program is having trouble with it.
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();
}
The first line of this method is what is causing the error. This method involves the signal information for the file to a txt file. Any help would be greatly appreciated.
Below is the small section of matlab code I used to create the wav file:
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');
Each of the entries in the "totalSound" array represent a note
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WAV 文件 有一个标头。您似乎没有创建该标头。您创建的似乎是原始 PCM 文件。
WAV files have a header. You don't seem to create that header. What you seem to create is a raw PCM file.
我遇到这个问题“JBoss 4.2 和 JBoss 7 中的输出不同
JBoss 4.2:
支持 WAVE = true
JBoss 7:
支持 WAVE = false”
另请检查此https://community.jboss.org/message/729654
I exepriences this problem "The output is different in JBoss 4.2 and JBoss 7
JBoss 4.2:
Support WAVE = true
JBoss 7:
Support WAVE = false"
check also this https://community.jboss.org/message/729654