2

I've converted a double array output[] to a wav file using NAudio. The file plays ok in VLC player and Windows Media Player, but when I try to open it in Winamp, or access it in Matlab using wavread() I fail.. (in Matlab I get the error: " Invalid Wave File. Reason: Incorrect chunk size information in WAV file." , which pretty obviously means something's wrong with the header). Any ideas on how to solve this? Here's the code for converting the array to a WAV:

float[] floatOutput = output.Select(s => (float)s).ToArray();
WaveFormat waveFormat = new WaveFormat(16000, 16, 1);
WaveFileWriter writer = new WaveFileWriter("C:\\track1.wav", waveFormat);
writer.WriteSamples(floatOutput, 0, floatOutput.Length);
4

1 回答 1

2

您必须处理您的WaveFileWriter,以便它可以正确修复 WAV 文件头。using 语句是执行此操作的最佳方法:

float[] floatOutput = output.Select(s => (float)s).ToArray();
WaveFormat waveFormat = new WaveFormat(16000, 16, 1);
using (WaveFileWriter writer = new WaveFileWriter("C:\\track1.wav", waveFormat))
{
    writer.WriteSamples(floatOutput, 0, floatOutput.Length);
}
于 2013-11-06T11:12:10.147 回答