我已经成功地使用 NAudio 进行任何音频处理和抽象。它以 NuGet 的形式提供。它具有 Media Foundation(和其他)的包装编码器。
这是使用 NAudio 编码为 AAC 并返回 WAV 的示例:
using System;
using NAudio.Wave;
namespace ConsoleApplication11
{
class Program
{
static void Main(string[] args)
{
// convert source audio to AAC
// create media foundation reader to read the source (can be any supported format, mp3, wav, ...)
using (MediaFoundationReader reader = new MediaFoundationReader(@"d:\source.mp3"))
{
MediaFoundationEncoder.EncodeToAac(reader, @"D:\test.mp4");
}
// convert "back" to WAV
// create media foundation reader to read the AAC encoded file
using (MediaFoundationReader reader = new MediaFoundationReader(@"D:\test.mp4"))
// resample the file to PCM with same sample rate, channels and bits per sample
using (ResamplerDmoStream resampledReader = new ResamplerDmoStream(reader,
new WaveFormat(reader.WaveFormat.SampleRate, reader.WaveFormat.BitsPerSample, reader.WaveFormat.Channels)))
// create WAVe file
using (WaveFileWriter waveWriter = new WaveFileWriter(@"d:\test.wav", resampledReader.WaveFormat))
{
// copy samples
resampledReader.CopyTo(waveWriter);
}
}
}
}