gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:18:31 35 4
gpt4 key购买 nike

我正在尝试编写一个类,将.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/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com