通过NLayer和NAudio转换MP3成WAV
NuGet安装:
Install-Package NLayer.NAudioSupport
示例代码:
using Microsoft.Win32; using NAudio.Wave; using NLayer.NAudioSupport; using System.Windows; namespace NAudioDemo { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "MP3 Files (*.mp3)|*.mp3|All Files (*.*)|*.*"; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == true) { var inputFileName = openFileDialog.FileName; var outputFileName = inputFileName.Substring(0, inputFileName.Length - 3) + "WAV"; var builder = new Mp3FileReader.FrameDecompressorBuilder(wf => new Mp3FrameDecompressor(wf)); using (var reader = new Mp3FileReader(inputFileName, builder)) { WaveFileWriter.CreateWaveFile(outputFileName, reader); } } MessageBox.Show("操作成功"); } } }