我正在将NAudio与C#一起使用,将wave文件转换为48,000、8bit,Mono。我将转换后的数据存储在字节数组中。我的代码如下。它工作正常,但新的wave文件数据未签名,我需要对其进行签名。
WaveFormat target = new WaveFormat(48000, 8, 1);
WaveStream stream = new WaveFileReader(this.FilePath);
WaveFormatConversionStream conv = new WaveFormatConversionStream(target, stream);
this.ConvertedData = new byte[conv.Length];
conv.Position = 0;
conv.Read(this.ConvertedData, 0, Convert.ToInt32(conv.Length));
stream.Dispose();
conv.Dispose();
我已尝试在转换数据后遍历字节数组,并从每个字节中减去128,这是我在此站点上找到的解决方案。
for (int i = 0; i < end; i++)
{
signed = (int)this.ConvertedData[i] - 128;
this.Data[i] = (byte)signed;
}
这种工作方式,但并不是万无一失的,我相信必须有更好的方法。任何建议将不胜感激。谢谢。
最佳答案
WaveFormat target = new WaveFormat(48000, 8, 1);
WaveStream stream =new WaveFileReader(this.FilePath);
WaveFormatConversionStream str = new WaveFormatConversionStream(target, stream);
WaveFileWriter.CreateWaveFile("c:\\converted.wav", str); //or the path of .wav file
尝试改用WaveFileWriter.CreateFile方法。
结帐NAudio
您也可以 checkout 此链接,他们也有C#音频库
Alvis.Audio
关于c# - 如何将8位未签名的WAV文件转换为8位签名的WAV文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12019465/