宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

转换成MP3:

using Microsoft.Win32;
using NAudio.MediaFoundation;
using NAudio.Wave;
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 = "WAV Files (*.wav)|*.wav|All Files (*.*)|*.*";
            openFileDialog.FilterIndex = 1;
            if (openFileDialog.ShowDialog() == true)
            {
                var inputFileName = openFileDialog.FileName;
                var outputFileName = inputFileName.Substring(0, inputFileName.Length - 3) + "mp3";

                var mediaType = MediaFoundationEncoder.SelectMediaType(
                                    AudioSubtypes.MFAudioFormat_MP3,
                                    new WaveFormat(44100, 1),
                                    0);

                using (var reader = new MediaFoundationReader(inputFileName))
                {
                    using (var encoder = new MediaFoundationEncoder(mediaType))
                    {
                        encoder.Encode(outputFileName, reader);
                    }
                }
            }
            MessageBox.Show("操作成功");
        }
    }
}

转换成WMA:

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "WAV Files (*.wav)|*.wav|All Files (*.*)|*.*";
            openFileDialog.FilterIndex = 1;
            if (openFileDialog.ShowDialog() == true)
            {
                var inputFileName = openFileDialog.FileName;
                var outputFileName = inputFileName.Substring(0, inputFileName.Length - 3) + "wma";

                var mediaType = MediaFoundationEncoder.SelectMediaType(
                                    AudioSubtypes.MFAudioFormat_WMAudioV8,
                                    new WaveFormat(16000, 1),
                                    16000);

                using (var reader = new MediaFoundationReader(inputFileName))
                {
                    using (var encoder = new MediaFoundationEncoder(mediaType))
                    {
                        encoder.Encode(outputFileName, reader);
                    }
                }
            }
            MessageBox.Show("操作成功");
        }