c# - 在C#中将.wav文件转换为.aiff

标签 c# audio file-conversion

我正在尝试编写一个类,将.wav文件转换为.aiff文件作为项目的一部分。

我遇到了几个库Alvas.Audio(http://alvas.net/alvas.audio,overview.aspx)和NAudio(http://naudio.codeplex.com)

我想知道是否有人对它们中的任何一个都有经验,因为我真的在努力研究如何使用两个库以aiff格式编写文件。

到目前为止,我有以下代码,但是我不知道如何将outfile定义为aiff:

阿尔瓦斯

string inFile = textBox1.Text; 
WaveReader mr = new WaveReader(File.OpenRead(inFile));
IntPtr mrFormat = mr.ReadFormat();
IntPtr wwFormat = AudioCompressionManager.GetCompatibleFormat(mrFormat, AudioCompressionManager.PcmFormatTag);
string outFile = inFile + ".aif";
WaveWriter ww = new WaveWriter(File.Create(outFile), AudioCompressionManager.FormatBytes(wwFormat));
AudioCompressionManager.Convert(mr, ww, false);
mr.Close();
ww.Close();

非音频
string inFile = textBox1.Text;
string outFile = inFile + ".aif";

using (WaveFileReader reader = new WaveFileReader(inFile))
{
   using (WaveFileWriter writer = new WaveFileWriter(outFile, reader.WaveFormat))
   {
       byte[] buffer = new byte[4096];
       int bytesRead = 0;
       do
       {
           bytesRead = reader.Read(buffer, 0, buffer.Length);
           writer.Write(buffer, 0, bytesRead);
       } while (bytesRead > 0);
   }
}

任何帮助将不胜感激:)

最佳答案

有关Alvas.Audio的最新版本,请参见以下代码:How to convert .wav to .aiff?

static void Wav2Aiff(string inFile)
{
    WaveReader wr = new WaveReader(File.OpenRead(inFile));
    IntPtr inFormat = wr.ReadFormat();
    IntPtr outFormat = AudioCompressionManager.GetCompatibleFormat(inFormat, 
        AudioCompressionManager.PcmFormatTag);
    string outFile = inFile + ".aif";
    AiffWriter aw = new AiffWriter(File.Create(outFile), outFormat);
    byte[] outData = AudioCompressionManager.Convert(inFormat, outFormat, wr.ReadData(), false);
    aw.WriteData(outData);
    wr.Close();
    aw.Close();
}

关于c# - 在C#中将.wav文件转换为.aiff,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13335647/

相关文章:

c# - 如何调用无参方法?

c# - 多线程代理检查器

c++ - PortAudio 回调中的求和波

java - 在 Play 框架中转换文件(特别是 .doc/.docx 到 .html)

pdf - 将 PDF 恢复为 LaTeX

c# - asp.net 和 javascript 中的正则表达式语法是否相同?

c# - 非泛型 IEnumerable 和泛型 IEnumerable<T> 之间有什么区别?

shell - 将所有第二层 mp3 递归转换为第三层并更新 ID3

ios - iPhone : Error uploading audio wav bytes data to server

html - 在 R 中将 HTML/CSS 转换为图像(png 或任何无损格式)